/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the files COPYING and Copyright.html. COPYING can be found at the root * * of the source code distribution tree; Copyright.html can be found at the * * root level of an installed copy of the electronic HDF5 document set and * * is linked from the top-level documents page. It can also be found at * * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /*********************************************************** * * Test program: tarray * * Test the Array Datatype functionality * *************************************************************/ #include "testhdf5.h" #include "hdf5.h" #define FILENAME "tarray1.h5" #define TESTFILE "tarrold.h5" /* 1-D array datatype */ #define ARRAY1_RANK 1 #define ARRAY1_DIM1 4 /* 3-D array datatype */ #define ARRAY2_RANK 3 #define ARRAY2_DIM1 3 #define ARRAY2_DIM2 4 #define ARRAY2_DIM3 5 /* 2-D array datatype */ #define ARRAY3_RANK 2 #define ARRAY3_DIM1 6 #define ARRAY3_DIM2 3 /* 1-D dataset with fixed dimensions */ #define SPACE1_NAME "Space1" #define SPACE1_RANK 1 #define SPACE1_DIM1 4 /* 2-D dataset with fixed dimensions */ #define SPACE2_NAME "Space2" #define SPACE2_RANK 2 #define SPACE2_DIM1 10 #define SPACE2_DIM2 10 /**************************************************************** ** ** test_array_atomic_1d(): Test basic array datatype code. ** Tests 1-D array of atomic datatypes ** ****************************************************************/ static void test_array_atomic_1d(void) { int wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */ int rdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information read in */ hid_t fid1; /* HDF5 File IDs */ hid_t dataset; /* Dataset ID */ hid_t sid1; /* Dataspace ID */ hid_t tid1; /* Datatype ID */ hsize_t sdims1[] = {SPACE1_DIM1}; hsize_t tdims1[] = {ARRAY1_DIM1}; int ndims; /* Array rank for reading */ hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */ int i,j; /* counting variables */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing 1-D Array of Atomic Datatypes Functionality\n")); /* Allocate and initialize array data to write */ for(i=0; i= 0){ /* Open the first dataset (with no array fields) */ dataset = H5Dopen(fid1, "Dataset1"); CHECK_I(dataset, "H5Dopen"); /* Get the datatype */ tid1=H5Dget_type(dataset); CHECK_I(tid1, "H5Dget_type"); /* Verify datatype class */ mclass=H5Tget_class(tid1); VERIFY(mclass, H5T_COMPOUND, "H5Tget_class"); /* Get the number of compound datatype fields */ nmemb=H5Tget_nmembers(tid1); VERIFY(nmemb,3,"H5Tget_nmembers"); /* Check the 1st field's name */ mname=H5Tget_member_name(tid1,0); CHECK(mname, NULL, "H5Tget_member_name"); if(HDstrcmp(mname,"i")!=0) TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname); free(mname); /* Check the 1st field's offset */ off=H5Tget_member_offset(tid1,0); VERIFY(off, 0, "H5Tget_member_offset"); /* Check the 1st field's datatype */ mtid=H5Tget_member_type(tid1,0); CHECK(mtid, FAIL, "H5Tget_member_type"); if((ret=H5Tequal(mtid,H5T_STD_I16LE))<=0) TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret); ret=H5Tclose(mtid); CHECK(mtid, FAIL, "H5Tclose"); /* Check the 2nd field's name */ mname=H5Tget_member_name(tid1,1); CHECK(mname, NULL, "H5Tget_member_name"); if(HDstrcmp(mname,"f")!=0) TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname); free(mname); /* Check the 2nd field's offset */ off=H5Tget_member_offset(tid1,1); VERIFY(off, 4, "H5Tget_member_offset"); /* Check the 2nd field's datatype */ mtid=H5Tget_member_type(tid1,1); CHECK(mtid, FAIL, "H5Tget_member_type"); if((ret=H5Tequal(mtid,H5T_IEEE_F32LE))<=0) TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret); ret=H5Tclose(mtid); CHECK(mtid, FAIL, "H5Tclose"); /* Check the 3rd field's name */ mname=H5Tget_member_name(tid1,2); CHECK(mname, NULL, "H5Tget_member_name"); if(HDstrcmp(mname,"l")!=0) TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname); free(mname); /* Check the 3rd field's offset */ off=H5Tget_member_offset(tid1,2); VERIFY(off, 8, "H5Tget_member_offset"); /* Check the 3rd field's datatype */ mtid=H5Tget_member_type(tid1,2); CHECK(mtid, FAIL, "H5Tget_member_type"); if((ret=H5Tequal(mtid,H5T_STD_I32LE))<=0) TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret); ret=H5Tclose(mtid); CHECK(mtid, FAIL, "H5Tclose"); /* Close the datatype */ ret = H5Tclose(tid1); CHECK_I(ret, "H5Tclose"); /* Close the dataset */ ret = H5Dclose(dataset); CHECK_I(ret, "H5Dclose"); /* Open the second dataset (with array fields) */ dataset = H5Dopen(fid1, "Dataset2"); CHECK_I(dataset, "H5Dopen"); /* Get the datatype */ tid1=H5Dget_type(dataset); CHECK_I(tid1, "H5Dget_type"); /* Verify datatype class */ mclass=H5Tget_class(tid1); VERIFY(mclass, H5T_COMPOUND, "H5Tget_class"); /* Get the number of compound datatype fields */ nmemb=H5Tget_nmembers(tid1); VERIFY(nmemb,4,"H5Tget_nmembers"); /* Check the 1st field's name */ mname=H5Tget_member_name(tid1,0); CHECK(mname, NULL, "H5Tget_member_name"); if(HDstrcmp(mname,"i")!=0) TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname); free(mname); /* Check the 1st field's offset */ off=H5Tget_member_offset(tid1,0); VERIFY(off, 0, "H5Tget_member_offset"); /* Check the 1st field's datatype */ mtid=H5Tget_member_type(tid1,0); CHECK(mtid, FAIL, "H5Tget_member_type"); if((ret=H5Tequal(mtid,H5T_STD_I16LE))<=0) TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret); ret=H5Tclose(mtid); CHECK(mtid, FAIL, "H5Tclose"); /* Check the 2nd field's name */ mname=H5Tget_member_name(tid1,1); CHECK(mname, NULL, "H5Tget_member_name"); if(HDstrcmp(mname,"f")!=0) TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname); free(mname); /* Check the 2nd field's offset */ off=H5Tget_member_offset(tid1,1); VERIFY(off, 4, "H5Tget_member_offset"); /* Check the 2nd field's datatype */ mtid=H5Tget_member_type(tid1,1); CHECK(mtid, FAIL, "H5Tget_member_type"); /* Verify datatype class */ mclass=H5Tget_class(mtid); VERIFY(mclass, H5T_ARRAY, "H5Tget_class"); /* Check the array rank */ ndims=H5Tget_array_ndims(mtid); VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims"); /* Get the array dimensions */ ret=H5Tget_array_dims(mtid,rdims1,NULL); CHECK(ret, FAIL, "H5Tget_array_dims"); /* Check the array dimensions */ for(i=0; i