Writing to a File
Contents:
Typical functions that you would use to write to an SDS are as follows:
The sd_create program is a sample program for writing out an SDS. You
can either download the C or FORTRAN program at the end, or just take a
look at the HTML version, with the HDF calls highlighted:
If you have downloaded this program, then you can
compile and run it. It creates an HDF file
called sd.hdf. You can view the contents of the HDF file
that gets created by this program, in the next section,
"Contents of HDF File Created".
Following is a detailed review of what this program does:
- Opens a new HDF file called sd.hdf and initializes the
SD Interface (SDstart/sfstart).
- Creates a dataset called "data1" of type
DFNT_INT16 (SDcreate/sfcreate).
This dataset is a 2-dimensional array with size 10 x 5.
- Fills a buffer full of data and writes it out to the dataset
(SDwritedata/sfwdata/sfwcdata).
- start
- Array specifying the location in the dataset array to begin the write
operation.
- stride
- Array specifying, for each dimension, the interval between values to be
written (with the same rank as the SDS array). It is set to NULL in
this case, indicating an interval of 1 for each dimension. This will
write data to every location along a dimension.
- edge
- Array specifying the number of values to be written along each
dimension of the slab being written.
When equal to the size of the dimensions of the array, then data will be written
to the entire dataset.
- Terminates access to the array (SDendaccess/sfendacc).
- Terminates access to the SD interface and closes the file
(SDend/sfend).
You can view the contents of sd.hdf, using the
hdp command. Following is the output
you would get by examining the file with hdp:
hdp dumpsds sd.hdf
The hdp command allows you to view general information
about a file. You can see that sd.hdf contains a two-dimensional array
(rank = 2) of 16-bit signed integers, and has no attributes.
Dimension 0, named fakeDim0, has a size of 10, and Dimension 1, named
fakeDim1, has a size of 5. The index is the
position of the data set relative to the beginning of the file, beginning with
zero. There is only one dataset in this file, so its index is zero. The data is
a series of increasing numbers.
Programs used in this tutorial:
[Compiling a program]