/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 < SPACE1_DIM1; i++) for(j = 0; j < ARRAY1_DIM1; j++) wdata[i][j] = i * 10 + j; /* Create file */ fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fcreate"); /* Create dataspace for datasets */ sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL); CHECK(sid1, FAIL, "H5Screate_simple"); /* Create a datatype to refer to */ tid1 = H5Tarray_create2(H5T_NATIVE_INT, ARRAY1_RANK, tdims1); CHECK(tid1, FAIL, "H5Tarray_create2"); /* Create a dataset */ dataset = H5Dcreate2(fid1, "Dataset1", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); /* Write dataset to disk */ ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); CHECK(ret, FAIL, "H5Dwrite"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close datatype */ ret = H5Tclose(tid1); CHECK(ret, FAIL, "H5Tclose"); /* Close disk dataspace */ ret = H5Sclose(sid1); CHECK(ret, FAIL, "H5Sclose"); /* Close file */ ret = H5Fclose(fid1); CHECK(ret, FAIL, "H5Fclose"); /* Re-open file */ fid1 = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fopen"); /* Open the dataset */ dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dopen2"); /* Get the datatype */ tid1 = H5Dget_type (dataset); CHECK(tid1, FAIL, "H5Dget_type"); /* Check the array rank */ ndims = H5Tget_array_ndims(tid1); VERIFY(ndims, ARRAY1_RANK, "H5Tget_array_ndims"); /* Get the array dimensions */ ret = H5Tget_array_dims2(tid1, rdims1); CHECK(ret, FAIL, "H5Tget_array_dims2"); /* Check the array dimensions */ for(i = 0; i < ndims; i++) if(rdims1[i] != tdims1[i]) { TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n", (int)i, (int)rdims1[i], (int)i, (int)tdims1[i]); continue; } /* end if */ /* Read dataset from disk */ ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata); CHECK(ret, FAIL, "H5Dread"); /* Compare data read in */ for(i = 0; i < SPACE1_DIM1; i++) for(j = 0; j < ARRAY1_DIM1; j++) if(wdata[i][j] != rdata[i][j]) { TestErrPrintf("Array data information doesn't match!, wdata[%d][%d]=%d, rdata[%d][%d]=%d\n", (int)i, (int)j, (int)wdata[i][j], (int)i, (int)j, (int)rdata[i][j]); continue; } /* end if */ /* Close Datatype */ ret = H5Tclose(tid1); CHECK(ret, FAIL, "H5Tclose"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close file */ ret = H5Fclose(fid1); CHECK(ret, FAIL, "H5Fclose"); } /* end test_array_atomic_1d() */ /**************************************************************** ** ** test_array_funcs(): Test some type functions that are and ** aren't supposed to work with array type. ** ****************************************************************/ static void test_array_funcs(void) { hid_t type; /* Datatype ID */ hsize_t tdims1[] = {ARRAY1_DIM1}; int size; H5T_pad_t inpad; H5T_norm_t norm; H5T_cset_t cset; H5T_str_t strpad; herr_t ret; /* Generic return value */ /* Create a datatype to refer to */ type = H5Tarray_create2(H5T_IEEE_F32BE, ARRAY1_RANK, tdims1); CHECK(type, FAIL, "H5Tarray_create2"); size=H5Tget_precision(type); CHECK(size, FAIL, "H5Tget_precision"); size=H5Tget_size(type); CHECK(size, FAIL, "H5Tget_size"); size=H5Tget_ebias(type); CHECK(size, FAIL, "H5Tget_ebias"); ret=H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE); CHECK(ret, FAIL, "H5Tset_pad"); inpad=H5Tget_inpad(type); CHECK(inpad, FAIL, "H5Tget_inpad"); norm=H5Tget_norm(type); CHECK(norm, FAIL, "H5Tget_norm"); ret=H5Tset_offset(type, (size_t)16); CHECK(ret, FAIL, "H5Tset_offset"); H5E_BEGIN_TRY { cset=H5Tget_cset(type); } H5E_END_TRY; VERIFY(cset, FAIL, "H5Tget_cset"); H5E_BEGIN_TRY { strpad=H5Tget_strpad(type); } H5E_END_TRY; VERIFY(strpad, FAIL, "H5Tget_strpad"); /* Close datatype */ ret = H5Tclose(type); CHECK(ret, FAIL, "H5Tclose"); } /* end test_array_funcs */ /**************************************************************** ** ** test_array_atomic_3d(): Test basic array datatype code. ** Tests 3-D array of atomic datatypes ** ****************************************************************/ static void test_array_atomic_3d(void) { int wdata[SPACE1_DIM1][ARRAY2_DIM1][ARRAY2_DIM2][ARRAY2_DIM3]; /* Information to write */ int rdata[SPACE1_DIM1][ARRAY2_DIM1][ARRAY2_DIM2][ARRAY2_DIM3]; /* Information read in */ hid_t fid; /* HDF5 File IDs */ hid_t dataset; /* Dataset ID */ hid_t sid; /* Dataspace ID */ hid_t tid; /* Datatype ID */ hsize_t sdims1[] = {SPACE1_DIM1}; hsize_t tdims2[] = {ARRAY2_DIM1,ARRAY2_DIM2,ARRAY2_DIM3}; int ndims; /* Array rank for reading */ hsize_t rdims2[H5S_MAX_RANK]; /* Array dimensions for reading */ int i,j,k,l; /* counting variables */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing 3-D Array of Atomic Datatypes Functionality\n")); /* Allocate and initialize array data to write */ for(i = 0; i < SPACE1_DIM1; i++) for(j = 0; j < ARRAY2_DIM1; j++) for(k = 0; k < ARRAY2_DIM2; k++) for(l = 0; l < ARRAY2_DIM3; l++) wdata[i][j][k][l] = i * 1000 + j * 100 + k * 10 + l; /* Create file */ fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid, FAIL, "H5Fcreate"); /* Create dataspace for datasets */ sid = H5Screate_simple(SPACE1_RANK, sdims1, NULL); CHECK(sid, FAIL, "H5Screate_simple"); /* Create a datatype to refer to */ tid = H5Tarray_create2(H5T_NATIVE_INT, ARRAY2_RANK, tdims2); CHECK(tid, FAIL, "H5Tarray_create2"); /* Create a dataset */ dataset = H5Dcreate2(fid, "Dataset1", tid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); /* Write dataset to disk */ ret = H5Dwrite(dataset, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); CHECK(ret, FAIL, "H5Dwrite"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close datatype */ ret = H5Tclose(tid); CHECK(ret, FAIL, "H5Tclose"); /* Close disk dataspace */ ret = H5Sclose(sid); CHECK(ret, FAIL, "H5Sclose"); /* Close file */ ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); /* Re-open file */ fid = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT); CHECK(fid, FAIL, "H5Fopen"); /* Open the dataset */ dataset = H5Dopen2(fid, "Dataset1", H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dopen2"); /* Get the datatype */ tid = H5Dget_type (dataset); CHECK(tid, FAIL, "H5Dget_type"); /* Check the array rank */ ndims = H5Tget_array_ndims(tid); VERIFY(ndims, ARRAY2_RANK, "H5Tget_array_ndims"); /* Get the array dimensions */ ret = H5Tget_array_dims2(tid, rdims2); CHECK(ret, FAIL, "H5Tget_array_dims2"); /* Check the array dimensions */ for(i = 0; i < ndims; i++) if(rdims2[i] != tdims2[i]) { TestErrPrintf("Array dimension information doesn't match!, rdims2[%d]=%d, tdims2[%d]=%d\n", (int)i, (int)rdims2[i], (int)i, (int)tdims2[i]); continue; } /* end if */ /* Read dataset from disk */ ret = H5Dread(dataset, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata); CHECK(ret, FAIL, "H5Dread"); /* Compare data read in */ for(i = 0; i < SPACE1_DIM1; i++) for(j = 0; j < ARRAY2_DIM1; j++) for(k = 0; k < ARRAY2_DIM2; k++) for(l = 0; l < ARRAY2_DIM3; l++) if(wdata[i][j][k][l] != rdata[i][j][k][l]) { TestErrPrintf("Array data information doesn't match!, wdata[%d][%d][%d][%d]=%d, rdata[%d][%d][%d][%d]=%d\n", (int)i, (int)j, (int)k, (int)l, (int)wdata[i][j][k][l], (int)i, (int)j, (int)k, (int)l, (int)rdata[i][j][k][l]); continue; } /* end if */ /* Close Datatype */ ret = H5Tclose(tid); CHECK(ret, FAIL, "H5Tclose"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close file */ ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); } /* end test_array_atomic_3d() */ /**************************************************************** ** ** test_array_array_atomic(): Test basic array datatype code. ** Tests 1-D array 2-D arrays of atomic datatypes ** ****************************************************************/ static void test_array_array_atomic(void) { int wdata[SPACE1_DIM1][ARRAY1_DIM1][ARRAY3_DIM1][ARRAY3_DIM2]; /* Information to write */ int rdata[SPACE1_DIM1][ARRAY1_DIM1][ARRAY3_DIM1][ARRAY3_DIM2]; /* Information read in */ hid_t fid; /* HDF5 File IDs */ hid_t dataset; /* Dataset ID */ hid_t sid; /* Dataspace ID */ hid_t tid1; /* 1-D array Datatype ID */ hid_t tid2; /* 2-D array Datatype ID */ hsize_t sdims1[] = {SPACE1_DIM1}; hsize_t tdims1[] = {ARRAY1_DIM1}; hsize_t tdims2[] = {ARRAY3_DIM1,ARRAY3_DIM2}; int ndims1; /* Array rank for reading */ int ndims2; /* Array rank for reading */ hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */ hsize_t rdims2[H5S_MAX_RANK]; /* Array dimensions for reading */ int i,j,k,l; /* counting variables */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing 1-D Array 2-D Arrays of Atomic Datatypes Functionality\n")); /* Allocate and initialize array data to write */ for(i = 0; i < SPACE1_DIM1; i++) for(j = 0; j < ARRAY1_DIM1; j++) for(k = 0; k < ARRAY3_DIM1; k++) for(l = 0; l < ARRAY3_DIM2; l++) wdata[i][j][k][l] = i * 1000 + j * 100 + k * 10 + l; /* Create file */ fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid, FAIL, "H5Fcreate"); /* Create dataspace for datasets */ sid = H5Screate_simple(SPACE1_RANK, sdims1, NULL); CHECK(sid, FAIL, "H5Screate_simple"); /* Create a 2-D datatype to refer to */ tid2 = H5Tarray_create2(H5T_NATIVE_INT, ARRAY3_RANK, tdims2); CHECK(tid2, FAIL, "H5Tarray_create2"); /* Create a 1-D datatype to refer to */ tid1 = H5Tarray_create2(tid2, ARRAY1_RANK, tdims1); CHECK(tid1, FAIL, "H5Tarray_create2"); /* Create a dataset */ dataset = H5Dcreate2(fid, "Dataset1", tid1, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); /* Write dataset to disk */ ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); CHECK(ret, FAIL, "H5Dwrite"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close datatypes */ ret = H5Tclose(tid1); CHECK(ret, FAIL, "H5Tclose"); ret = H5Tclose(tid2); CHECK(ret, FAIL, "H5Tclose"); /* Close disk dataspace */ ret = H5Sclose(sid); CHECK(ret, FAIL, "H5Sclose"); /* Close file */ ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); /* Re-open file */ fid = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT); CHECK(fid, FAIL, "H5Fopen"); /* Open the dataset */ dataset = H5Dopen2(fid, "Dataset1", H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dopen2"); /* Get the 1-D datatype */ tid1 = H5Dget_type(dataset); CHECK(tid1, FAIL, "H5Dget_type"); /* Check the 1-D array rank */ ndims1 = H5Tget_array_ndims(tid1); VERIFY(ndims1, ARRAY1_RANK, "H5Tget_array_ndims"); /* Get the 1-D array dimensions */ ret = H5Tget_array_dims2(tid1, rdims1); CHECK(ret, FAIL, "H5Tget_array_dims2"); /* Check the array dimensions */ for(i = 0; i < ndims1; i++) if(rdims1[i] != tdims1[i]) { TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n", (int)i, (int)rdims1[i], (int)i, (int)tdims1[i]); continue; } /* end if */ /* Get the 2-D datatype */ tid2 = H5Tget_super(tid1); CHECK(tid2, FAIL, "H5Tget_super"); /* Check the 2-D array rank */ ndims2 = H5Tget_array_ndims(tid2); VERIFY(ndims2, ARRAY3_RANK, "H5Tget_array_ndims"); /* Get the 2-D array dimensions */ ret = H5Tget_array_dims2(tid2, rdims2); CHECK(ret, FAIL, "H5Tget_array_dims2"); /* Check the array dimensions */ for(i = 0; i < ndims2; i++) if(rdims2[i] != tdims2[i]) { TestErrPrintf("Array dimension information doesn't match!, rdims2[%d]=%d, tdims2[%d]=%d\n", (int)i, (int)rdims2[i], (int)i, (int)tdims2[i]); continue; } /* end if */ /* Read dataset from disk */ ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata); CHECK(ret, FAIL, "H5Dread"); /* Compare data read in */ for(i = 0; i < SPACE1_DIM1; i++) for(j = 0; j < ARRAY1_DIM1; j++) for(k = 0; k < ARRAY3_DIM1; k++) for(l = 0; l < ARRAY3_DIM2; l++) if(wdata[i][j][k][l] != rdata[i][j][k][l]) { TestErrPrintf("Array data information doesn't match!, wdata[%d][%d][%d][%d]=%d, rdata[%d][%d][%d][%d]=%d\n", (int)i, (int)j, (int)k, (int)l, (int)wdata[i][j][k][l], (int)i, (int)j, (int)k, (int)l, (int)rdata[i][j][k][l]); continue; } /* end if */ /* Close Datatypes */ ret = H5Tclose(tid1); CHECK(ret, FAIL, "H5Tclose"); ret = H5Tclose(tid2); CHECK(ret, FAIL, "H5Tclose"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close file */ ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); } /* end test_array_array_atomic() */ /**************************************************************** ** ** test_array_compound_atomic(): Test basic array datatype code. ** Tests 1-D array of compound datatypes (with no array fields) ** ****************************************************************/ static void test_array_compound_atomic(void) { typedef struct { /* Typedef for compound datatype */ int i; float f; } s1_t; s1_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */ s1_t 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; /* Array Datatype ID */ hid_t tid2; /* Compound 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 nmemb; /* Number of compound members */ char *mname; /* Name of compound field */ size_t off; /* Offset of compound field */ hid_t mtid; /* Datatype ID for field */ int i,j; /* counting variables */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing 1-D Array of Compound Atomic Datatypes Functionality\n")); /* Initialize array data to write */ for(i = 0; i < SPACE1_DIM1; i++) for(j = 0; j < ARRAY1_DIM1; j++) { wdata[i][j].i = i * 10 + j; wdata[i][j].f = (float)(i * 2.5 + j); } /* end for */ /* Create file */ fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fcreate"); /* Create dataspace for datasets */ sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL); CHECK(sid1, FAIL, "H5Screate_simple"); /* Create a compound datatype to refer to */ tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1_t)); CHECK(tid2, FAIL, "H5Tcreate"); /* Insert integer field */ ret = H5Tinsert(tid2, "i", HOFFSET(s1_t, i), H5T_NATIVE_INT); CHECK(ret, FAIL, "H5Tinsert"); /* Insert float field */ ret = H5Tinsert(tid2, "f", HOFFSET(s1_t, f), H5T_NATIVE_FLOAT); CHECK(ret, FAIL, "H5Tinsert"); /* Create an array datatype to refer to */ tid1 = H5Tarray_create2(tid2, ARRAY1_RANK, tdims1); CHECK(tid1, FAIL, "H5Tarray_create2"); /* Close compound datatype */ ret = H5Tclose(tid2); CHECK(ret, FAIL, "H5Tclose"); /* Create a dataset */ dataset = H5Dcreate2(fid1, "Dataset1", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); /* Write dataset to disk */ ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); CHECK(ret, FAIL, "H5Dwrite"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close datatype */ ret = H5Tclose(tid1); CHECK(ret, FAIL, "H5Tclose"); /* Close disk dataspace */ ret = H5Sclose(sid1); CHECK(ret, FAIL, "H5Sclose"); /* Close file */ ret = H5Fclose(fid1); CHECK(ret, FAIL, "H5Fclose"); /* Re-open file */ fid1 = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fopen"); /* Open the dataset */ dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dopen2"); /* Get the datatype */ tid1 = H5Dget_type(dataset); CHECK(tid1, FAIL, "H5Dget_type"); /* Check the array rank */ ndims = H5Tget_array_ndims(tid1); VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims"); /* Get the array dimensions */ ret = H5Tget_array_dims2(tid1, rdims1); CHECK(ret, FAIL, "H5Tget_array_dims2"); /* Check the array dimensions */ for(i = 0; i < ndims; i++) if(rdims1[i] != tdims1[i]) { TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n", (int)i, (int)rdims1[i], (int)i, (int)tdims1[i]); continue; } /* end if */ /* Get the compound datatype */ tid2 = H5Tget_super (tid1); CHECK(tid2, FAIL, "H5Tget_super"); /* Check the number of members */ nmemb = H5Tget_nmembers(tid2); VERIFY(nmemb,2,"H5Tget_nmembers"); /* Check the 1st field's name */ mname = H5Tget_member_name(tid2, 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(tid2, 0); VERIFY(off, HOFFSET(s1_t, i), "H5Tget_member_offset"); /* Check the 1st field's datatype */ mtid = H5Tget_member_type(tid2, 0); CHECK(mtid, FAIL, "H5Tget_member_type"); if((ret = H5Tequal(mtid,H5T_NATIVE_INT)) <= 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(tid2, 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(tid2, 1); VERIFY(off, HOFFSET(s1_t, f), "H5Tget_member_offset"); /* Check the 2nd field's datatype */ mtid = H5Tget_member_type(tid2, 1); CHECK(mtid, FAIL, "H5Tget_member_type"); if((ret = H5Tequal(mtid, H5T_NATIVE_FLOAT)) <= 0) TestErrPrintf("Compound data type is incorrect!, ret=%d\n", (int)ret); ret = H5Tclose(mtid); CHECK(mtid, FAIL, "H5Tclose"); /* Close Compound Datatype */ ret = H5Tclose(tid2); CHECK(ret, FAIL, "H5Tclose"); /* Read dataset from disk */ ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata); CHECK(ret, FAIL, "H5Dread"); /* Compare data read in */ for(i = 0; i < SPACE1_DIM1; i++) for(j = 0; j < ARRAY1_DIM1; j++) { if(wdata[i][j].i != rdata[i][j].i) { TestErrPrintf("Array data information doesn't match!, wdata[%d][%d].i=%d, rdata[%d][%d].i=%d\n", (int)i, (int)j, (int)wdata[i][j].i, (int)i, (int)j, (int)rdata[i][j].i); continue; } /* end if */ if(!FLT_ABS_EQUAL(wdata[i][j].f, rdata[i][j].f)) { TestErrPrintf("Array data information doesn't match!, wdata[%d][%d].f=%f, rdata[%d][%d].f=%f\n", (int)i, (int)j, wdata[i][j].f, (int)i, (int)j, rdata[i][j].f); continue; } /* end if */ } /* end for */ /* Close Datatype */ ret = H5Tclose(tid1); CHECK(ret, FAIL, "H5Tclose"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close file */ ret = H5Fclose(fid1); CHECK(ret, FAIL, "H5Fclose"); } /* end test_array_compound_atomic() */ /**************************************************************** ** ** test_array_compound_array(): Test basic array datatype code. ** Tests 1-D array of compound datatypes (with array fields) ** ****************************************************************/ static void test_array_compound_array(void) { typedef struct { /* Typedef for compound datatype */ int i; float f[ARRAY1_DIM1]; } s1_t; s1_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */ s1_t 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; /* Array Datatype ID */ hid_t tid2; /* Compound Datatype ID */ hid_t tid3; /* Nested Array 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 nmemb; /* Number of compound members */ char *mname; /* Name of compound field */ size_t off; /* Offset of compound field */ hid_t mtid; /* Datatype ID for field */ H5T_class_t mclass; /* Datatype class for field */ int i,j,k; /* counting variables */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing 1-D Array of Compound Array Datatypes Functionality\n")); /* Initialize array data to write */ for(i=0; i= 0){ /* Open the first dataset (with no array fields) */ dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT); CHECK_I(dataset, "H5Dopen2"); /* 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 = H5Dopen2(fid1, "Dataset2", H5P_DEFAULT); CHECK_I(dataset, "H5Dopen2"); /* 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(mname && HDstrcmp(mname,"i")!=0) TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname); if(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(mname && HDstrcmp(mname,"f")!=0) TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname); if(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_dims2(mtid, rdims1); CHECK(ret, FAIL, "H5Tget_array_dims2"); /* Check the array dimensions */ for(i=0; i