/*********************************************************************** * Example for enumerated datatype. * * blw 3/24/03 * ***********************************************************************/ #include "hdf5.h" /* System libraries to include */ #include #include /* Name of file for database output */ #define DATAFILE "enum.h5" /* Name of dataset to create in datafile */ #define DATASETNAME "EnumTest" /* Dataset dimensions */ #define LENGTH 10 #define RANK 1 /* Defining the enumerated struct */ typedef enum { RED, GREEN, BLUE, WHITE, BLACK } EnumStuct; /* Creating the enum array */ EnumStuct EnumArray[LENGTH]; int main(void) { EnumStuct val; /* Variable for pointer */ hid_t file, dataset; hid_t dataspace, datatype; herr_t status; hsize_t dim[]= {LENGTH}; int i; /* Loop control variable */ /* Filler data for enumerated array */ for (i=0; i<5; i++) EnumArray[i]=i; for (i=5; i= 0); /* Create the file */ file = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); assert (file >= 0); /* Create the datatype */ datatype = H5Tcreate(H5T_ENUM, sizeof(EnumStuct)); assert (datatype >= 0); /* Insert the enumerated data */ val = RED; status = H5Tenum_insert(datatype, "RED", &val ); assert (status >= 0); /* Insert the enumerated data */ val = GREEN; status = H5Tenum_insert(datatype, "GREEN", &val); assert (status >= 0); /* Insert the enumerated data */ val = BLUE; status = H5Tenum_insert(datatype, "BLUE", &val); assert (status >= 0); /* Insert the enumerated data */ val = WHITE; status = H5Tenum_insert(datatype, "WHITE", &val); assert (status >= 0); /* Insert the enumerated data */ val = BLACK; status = H5Tenum_insert(datatype, "BLACK", &val); assert (status >= 0); /* Create the dataset */ dataset = H5Dcreate(file, DATASETNAME, datatype, dataspace, H5P_DEFAULT); assert (dataset >= 0); /* Write data to the dataset */ status = H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, EnumArray); assert (status >= 0); /* Close the Datatype */ status = H5Tclose(datatype); assert (status >= 0); /* Close the dataspace */ status = H5Sclose(dataspace); assert (status >= 0); /* Close the dataset */ status = H5Dclose(dataset); assert (status >= 0); /* Close the file */ status = H5Fclose(file); assert (status >= 0); }