#include "mfhdf.h" #define FILE_NAME "SDS.hdf" #define FILE_ATTR_NAME "File_contents" #define SDS_ATTR_NAME "Valid_range" #define DIM_ATTR_NAME "Dim_metric" int main() { /************************* Variable declaration **************************/ int32 sd_id, sds_id, dim_id; intn status; int32 attr_index, data_type, n_values; char attr_name[H4_MAX_NC_NAME]; int i; /********************* End of variable declaration ***********************/ /* * Open the file and initialize SD interface. */ sd_id = SDstart (FILE_NAME, DFACC_READ); /* * Find the file attribute defined by FILE_ATTR_NAME. */ attr_index = SDfindattr (sd_id, FILE_ATTR_NAME); /* * Get information about the file attribute. Note that the first * parameter is an SD interface identifier. */ status = SDattrinfo (sd_id, attr_index, attr_name, &data_type, &n_values); /* The data type should be DFNT_CHAR, from SD_set_attr.c */ if (data_type = DFNT_CHAR) { char *fileattr_data; /* * Allocate a buffer to hold the attribute data. */ fileattr_data = (char *)HDmalloc (n_values * sizeof(char)); /* * Read the file attribute data. */ status = SDreadattr (sd_id, attr_index, fileattr_data); /* * Print out file attribute value and free buffer. */ printf ("File attribute value is : %s\n", fileattr_data); free (fileattr_data); } /* * Select the first data set. */ sds_id = SDselect (sd_id, 0); /* * Find the data set attribute defined by SDS_ATTR_NAME. Note that the * first parameter is a data set identifier. */ attr_index = SDfindattr (sds_id, SDS_ATTR_NAME); /* * Get information about the data set attribute. */ status = SDattrinfo (sds_id, attr_index, attr_name, &data_type, &n_values); /* * The data type should be DFNT_FLOAT32, from SD_set_attr.c. */ if (data_type == DFNT_FLOAT32) { float32 *sds_data; /* * Allocate a buffer to hold the data set attribute data. */ sds_data = (float32 *)HDmalloc (n_values * sizeof (float32)); /* * Read the SDS attribute data. */ status = SDreadattr (sds_id, attr_index, sds_data); /* * Print out SDS attribute data type and values and free buffer. */ printf ("SDS attribute data type is : float32\n"); printf ("SDS attribute values are : "); for (i=0; i