About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/fwrite.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 fwrite Context: slangrtl

Synopsis

Write binary data to a file

Syntax

UInt_Type fwrite (b, File_Type fp)

Description

The fwrite may be used to write the object represented by b to an open file. If b is a string or an array, the function will attempt to write all elements of the object to the file. It returns the number of objects successfully written, otherwise it returns -1 upon error and sets errno accordingly.

Example

The following example illustrates how to write an integer array to a file. In this example, fp is an open file descriptor:

     variable a = [1:50];     % 50 element integer array
     if (50 != fwrite (a, fp))
       error ("fwrite failed");

Here is how to write the array one element at a time:

     variable a = [1:50];
     foreach (a)
       {
          variable ai = ();
          if (1 != fwrite(ai, fp))
          error ("fwrite failed");
       }

Not all data types may support the fwrite operation. However, it is supported by all vector, scalar, and string objects.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.