C: sd_id = SDstart(filename, access_mode); sds_id = SDselect(sd_id, sds_index); <Optional operations> status = SDendaccess(sds_id); status = SDend(sd_id); FORTRAN: sd_id = sfstart(filename_1, access_mode) sds_id = sfselect(sd_id, sds_index) <Optional operations> status = sfendaccess(sds_id) status = sfend(sd_id)
C: sd_id_1 = SDstart(filename_1, access_mode); sds_id_1 = SDselect(sd_id_1, sds_index_1); sd_id_2 = SDstart(filename_2, access_mode); sds_id_2 = SDselect(sd_id_2, sds_index_2); <Optional operations> status = SDendaccess(sds_id_1); status = SDend(sd_id_1); status = SDendaccess(sds_id_2); status = SDend(sd_id_2); FORTRAN: sd_id_1 = sfstart(filename_1, access_mode) sds_id_1 = sfselect(sd_id_1, sds_index_1) sd_id_2 = sfstart(filename_2, access_mode) sds_id_2 = sfselect(sd_id_2, sds_index_2) <Optional operations> status = sfendacc(sds_id_1) status = sfend(sd_id_1) status = sfendacc(sds_id_2) status = sfend(sd_id_2)
As with file identifiers, SD ids can be obtained and discarded in any order and all SD ids must be individually discarded before termination of the calling program.
3.4.1 Establishing Access to Files and Data Sets: SDstart and SDselect
In the SD interface, SDstart is used to open files rather than Hopen. SDstart takes two arguments; filename and access_mode, and returns the file id sd_id. The argument filename is the name of an HDF or netCDF file as it is stored on disk. All other functions in the SD interface accept only sd_id for file operations. The argument access_mode specifies the type of access required for operations on the file. The access mode tags passed in the access_mode parameter have names prefaced by "DFACC".
3.4.2 Terminating Access to Files and Data Sets: SDendaccess and SDend
SDendaccess disposes of the open data set id sds_id and terminates access to the data set. The calling program must make one SDendaccess call for every SDselect call made during its execution. Failing to call SDendaccess for each call to SDselect or SDcreate may result in a loss of data. TABLE 3B SDstart, SDselect, SDend and SDendaccess Parameter List
This example assumes that the "Dummy_HDF_File.hdf" file contains one SDS.
C:
#include "mfhdf.h" main( ) { int32 sd_id, sds_id, sds_index, status; int32 rank, num_type, attributes; /* Open the HDF file. DFACC_CREATE is defined in hdf.h. */ sd_id = SDstart("Dummy_HDF_File.hdf", DFACC_CREATE); /* Get the identifier of the first data set. */ sds_index = 0; sds_id = SDselect(sd_id, sds_index); /* Dispose of the data set identifier to terminate access. */ status = SDendaccess(sds_id); /* Dispose of the file identifier to close the file. */ status = SDend(sd_id); }
PROGRAM SDSDATA ACCESS integer*4 sds_id, sd_id, sds_index, status integer sfstart, sfselect, sfendacc, sfend C DFACC_CREATE is defined in hdf.h. parameter (DFACC_CREATE = 4) C Open the HDF file. sd_id = sfstart('Dummy_HDF_File.hdf', DFACC_CREATE) C Get the identifier of the first data set. sds_index = 0 sds_id = sfselect(sd_id, sds_index) C Dispose of the data set identifier to terminate access. status = sfendacc(sds_id) C Dispose of the file identifier to close the file. status = sfend(sd_id) end