Reading a File
Contents:
Typical functions that you would use to read an SDS are as follows:
Take example sd_create.c, created earlier, and add a call to
read back the data (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 output from this program in the next
section, "Output from Sample Program".
Following is a detailed review of what this program does:
- Creates an HDF file (see tutorial "Writing to a File" for details).
- Re-opens the HDF file with DFACC_READ permissions.
- Selects the SDS from which to read data (SDselect/sfselect). If there is
only one SDS in the file, then you can use an index of 0 to select it, though
this is not recommended.
- Reads in the data from the file (SDreaddata/sfrdata/sfrcdata) and print it out.
It uses the same start, stride and edges as used when creating the file.
Following is what this program outputs to the screen:
... sd.hdf created
... data1 created
... data written out
... file closed
... sd.hdf opened with READ access
Data:
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
6 7 8 9 10
7 8 9 10 11
8 9 10 11 12
9 10 11 12 13
10 11 12 13 14
... file closed
Programs used in this tutorial:
[Compiling a program]