From f178100d14450c2f1f08a91aab9b070af163988b Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 9 Nov 2000 16:47:59 -0500 Subject: [svn-r2844] Purpose: New Feature Description: Added array datatype tests to the regression tests. These datatype combinations are tested currently: 1-D array of atomic datatypes 3-D array of atomic datatypes array of array of atomic datatypes array of compound of atomic datatypes array of compound of array datatypes array of VL of atomic datatypes array of VL of array datatypes Also added a test to verify that the older style compound datatype with array fields works correctly. Platforms tested: FreeBSD 4.1.1 (hawkwind) --- test/Makefile.in | 17 +- test/cmpd_dset.c | 71 +- test/dtypes.c | 148 ++-- test/gen_new_array.c | 146 ++++ test/gen_old_array.c | 144 ++++ test/tarray.c | 1849 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/tarrold.h5 | Bin 0 -> 6032 bytes test/testhdf5.c | 1 + test/testhdf5.h | 2 + 9 files changed, 2271 insertions(+), 107 deletions(-) create mode 100644 test/gen_new_array.c create mode 100644 test/gen_old_array.c create mode 100644 test/tarray.c create mode 100644 test/tarrold.h5 diff --git a/test/Makefile.in b/test/Makefile.in index fd97c82..a6108bf 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -47,7 +47,8 @@ MOSTLYCLEAN=cmpd_dset.h5 dataset.h5 extend.h5 istore.h5 tfile1.h5 tfile2.h5 \ big.data big[0-9][0-9][0-9][0-9][0-9].h5 dtypes1.h5 dtypes2.h5 \ tattr.h5 tselect.h5 mtime.h5 ragged.h5 unlink.h5 overhead.h5 \ fillval_[0-9].h5 fillval.raw mount_[0-9].h5 ttime.h5 trefer[12].h5 \ - tvltypes.h5 tvlstr.h5 flush.h5 enum1.h5 titerate.h5 ttsafe.h5 + tvltypes.h5 tvlstr.h5 flush.h5 enum1.h5 titerate.h5 ttsafe.h5 \ + tarray1.h5 CLEAN=$(TIMINGS) ## Source and object files for programs... The TEST_SRC list contains all the @@ -58,12 +59,11 @@ CLEAN=$(TIMINGS) TEST_SRC=big.c bittests.c chunk.c cmpd_dset.c dsets.c dtypes.c extend.c \ external.c fillval.c flush1.c flush2.c gheap.c h5test.c hyperslab.c \ iopipe.c istore.c lheap.c links.c mount.c mtime.c ohdr.c overhead.c \ - ragged.c stab.c tattr.c testhdf5.c tfile.c th5s.c titerate.c tmeta.c \ - ttime.c trefer.c tselect.c ttbbt.c tvltypes.c tvlstr.c unlink.c enum.c \ - ttsafe.c ttsafe_dcreate.c ttsafe_error.c ttsafe_cancel.c \ - ttsafe_acreate.c \ - gass_write.c gass_read.c gass_append.c dpss_read.c dpss_write.c \ - srb_read.c srb_write.c srb_append.c stream_test.c + ragged.c stab.c tarray.c tattr.c testhdf5.c tfile.c th5s.c titerate.c \ + tmeta.c trefer.c tselect.c ttime.c ttbbt.c tvltypes.c tvlstr.c unlink.c \ + enum.c ttsafe.c ttsafe_dcreate.c ttsafe_error.c ttsafe_cancel.c \ + ttsafe_acreate.c gass_write.c gass_read.c gass_append.c dpss_read.c \ + dpss_write.c srb_read.c srb_write.c srb_append.c stream_test.c TEST_OBJ=$(TEST_SRC:.c=.lo) @@ -83,7 +83,8 @@ timings _timings: $(TIMINGS) ## How to build the tests... They all depend on the test and hdf5 libraries. $(TEST_PROGS): $(LIB) $(LIBHDF5) -TESTHDF5_OBJ=testhdf5.lo tattr.lo tfile.lo titerate.lo tmeta.lo ttime.lo trefer.lo tselect.lo ttbbt.lo tvltypes.lo tvlstr.lo th5s.lo +TESTHDF5_OBJ=testhdf5.lo tarray.lo tattr.lo tfile.lo titerate.lo tmeta.lo \ + ttime.lo trefer.lo tselect.lo ttbbt.lo tvltypes.lo tvlstr.lo th5s.lo TTS_OBJ=ttsafe.lo ttsafe_dcreate.lo ttsafe_error.lo ttsafe_cancel.lo \ ttsafe_acreate.lo diff --git a/test/cmpd_dset.c b/test/cmpd_dset.c index 062707e..00ef239 100644 --- a/test/cmpd_dset.c +++ b/test/cmpd_dset.c @@ -128,10 +128,11 @@ main (int argc, char *argv[]) /* Other variables */ unsigned int i, j; hid_t file, dataset, space, PRESERVE, fapl; + hid_t array_dt; static hsize_t dim[] = {NX, NY}; hssize_t f_offset[2]; /*offset of hyperslab in file */ hsize_t h_size[2]; /*size of hyperslab */ - size_t memb_size[1] = {4}; + hsize_t memb_size[1] = {4}; char filename[256]; h5_reset(); @@ -178,15 +179,16 @@ main (int argc, char *argv[]) } /* Create the memory data type */ - if ((s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t)))<0) goto error; + if ((s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t)))<0) + goto error; + array_dt=H5Tarray_create(H5T_NATIVE_INT, 1, memb_size, NULL); if (H5Tinsert (s1_tid, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT)<0 || - H5Tinsert (s1_tid, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT)<0 || - H5Tinsert_array (s1_tid, "c", HOFFSET(s1_t,c), 1, memb_size, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert (s1_tid, "d", HOFFSET(s1_t,d), H5T_NATIVE_INT)<0 || - H5Tinsert (s1_tid, "e", HOFFSET(s1_t,e), H5T_NATIVE_INT)<0) { - goto error; - } + H5Tinsert (s1_tid, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT)<0 || + H5Tinsert (s1_tid, "c", HOFFSET(s1_t,c), array_dt)<0 || + H5Tinsert (s1_tid, "d", HOFFSET(s1_t,d), H5T_NATIVE_INT)<0 || + H5Tinsert (s1_tid, "e", HOFFSET(s1_t,e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); /* Create the dataset */ if ((dataset = H5Dcreate (file, "s1", s1_tid, space, H5P_DEFAULT))<0) { @@ -208,15 +210,16 @@ main (int argc, char *argv[]) TESTING("basic compound read"); /* Create a data type for s2 */ - if ((s2_tid = H5Tcreate (H5T_COMPOUND, sizeof(s2_t)))<0) goto error; + if ((s2_tid = H5Tcreate (H5T_COMPOUND, sizeof(s2_t)))<0) + goto error; + array_dt=H5Tarray_create(H5T_NATIVE_INT, 1, memb_size, NULL); if (H5Tinsert (s2_tid, "a", HOFFSET(s2_t,a), H5T_NATIVE_INT)<0 || - H5Tinsert (s2_tid, "b", HOFFSET(s2_t,b), H5T_NATIVE_INT)<0 || - H5Tinsert_array (s2_tid, "c", HOFFSET(s2_t,c), 1, memb_size, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert (s2_tid, "d", HOFFSET(s2_t,d), H5T_NATIVE_INT)<0 || - H5Tinsert (s2_tid, "e", HOFFSET(s2_t,e), H5T_NATIVE_INT)<0) { - goto error; - } + H5Tinsert (s2_tid, "b", HOFFSET(s2_t,b), H5T_NATIVE_INT)<0 || + H5Tinsert (s2_tid, "c", HOFFSET(s2_t,c), array_dt)<0 || + H5Tinsert (s2_tid, "d", HOFFSET(s2_t,d), H5T_NATIVE_INT)<0 || + H5Tinsert (s2_tid, "e", HOFFSET(s2_t,e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); /* Read the data */ if (H5Dread (dataset, s2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s2)<0) { @@ -249,15 +252,16 @@ main (int argc, char *argv[]) TESTING("reversal of struct members"); /* Create a data type for s3 */ - if ((s3_tid = H5Tcreate (H5T_COMPOUND, sizeof(s3_t)))<0) goto error; + if ((s3_tid = H5Tcreate (H5T_COMPOUND, sizeof(s3_t)))<0) + goto error; + array_dt=H5Tarray_create(H5T_NATIVE_INT, 1, memb_size, NULL); if (H5Tinsert (s3_tid, "a", HOFFSET(s3_t,a), H5T_NATIVE_INT)<0 || - H5Tinsert (s3_tid, "b", HOFFSET(s3_t,b), H5T_NATIVE_INT)<0 || - H5Tinsert_array (s3_tid, "c", HOFFSET(s3_t,c), 1, memb_size, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert (s3_tid, "d", HOFFSET(s3_t,d), H5T_NATIVE_INT)<0 || - H5Tinsert (s3_tid, "e", HOFFSET(s3_t,e), H5T_NATIVE_INT)<0) { - goto error; - } + H5Tinsert (s3_tid, "b", HOFFSET(s3_t,b), H5T_NATIVE_INT)<0 || + H5Tinsert (s3_tid, "c", HOFFSET(s3_t,c), array_dt)<0 || + H5Tinsert (s3_tid, "d", HOFFSET(s3_t,d), H5T_NATIVE_INT)<0 || + H5Tinsert (s3_tid, "e", HOFFSET(s3_t,e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); /* Read the data */ if (H5Dread (dataset, s3_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s3)<0) { @@ -325,15 +329,16 @@ main (int argc, char *argv[]) } /* Create a data type for s5 */ - if ((s5_tid = H5Tcreate (H5T_COMPOUND, sizeof(s5_t)))<0) goto error; + if ((s5_tid = H5Tcreate (H5T_COMPOUND, sizeof(s5_t)))<0) + goto error; + array_dt=H5Tarray_create(H5T_NATIVE_INT, 1, memb_size, NULL); if (H5Tinsert (s5_tid, "a", HOFFSET(s5_t,a), H5T_NATIVE_INT)<0 || - H5Tinsert (s5_tid, "b", HOFFSET(s5_t,b), H5T_NATIVE_INT)<0 || - H5Tinsert_array (s5_tid, "c", HOFFSET(s5_t,c), 1, memb_size, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert (s5_tid, "d", HOFFSET(s5_t,d), H5T_NATIVE_INT)<0 || - H5Tinsert (s5_tid, "e", HOFFSET(s5_t,e), H5T_NATIVE_INT)) { - goto error; - } + H5Tinsert (s5_tid, "b", HOFFSET(s5_t,b), H5T_NATIVE_INT)<0 || + H5Tinsert (s5_tid, "c", HOFFSET(s5_t,c), array_dt)<0 || + H5Tinsert (s5_tid, "d", HOFFSET(s5_t,d), H5T_NATIVE_INT)<0 || + H5Tinsert (s5_tid, "e", HOFFSET(s5_t,e), H5T_NATIVE_INT)) + goto error; + H5Tclose(array_dt); /* Read the data */ if (H5Dread (dataset, s5_tid, H5S_ALL, H5S_ALL, PRESERVE, s5)<0) { diff --git a/test/dtypes.c b/test/dtypes.c index 1bf7a7c..dc91425 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -440,9 +440,10 @@ test_compound_2(void) } *d_ptr; const int nelmts = NTESTELEM; - const size_t four = 4; + const hsize_t four = 4; unsigned char *buf=NULL, *orig=NULL, *bkg=NULL; hid_t st=-1, dt=-1; + hid_t array_dt; int i; TESTING("compound element reordering"); @@ -465,23 +466,25 @@ test_compound_2(void) memcpy(buf, orig, nelmts*sizeof(struct st)); /* Build hdf5 datatypes */ + array_dt=H5Tarray_create(H5T_NATIVE_INT,1, &four, NULL); if ((st=H5Tcreate(H5T_COMPOUND, sizeof(struct st)))<0 || - H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT)<0 || - H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT)<0 || - H5Tinsert_array(st, "c", HOFFSET(struct st, c), 1, &four, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT)<0 || - H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT)<0) - goto error; + H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "c", HOFFSET(struct st, c), array_dt)<0 || + H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); + array_dt=H5Tarray_create(H5T_NATIVE_INT,1, &four, NULL); if ((dt=H5Tcreate(H5T_COMPOUND, sizeof(struct dt)))<0 || - H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT)<0 || - H5Tinsert(dt, "b", HOFFSET(struct dt, b), H5T_NATIVE_INT)<0 || - H5Tinsert_array(dt, "c", HOFFSET(struct dt, c), 1, &four, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert(dt, "d", HOFFSET(struct dt, d), H5T_NATIVE_INT)<0 || - H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT)<0) - goto error; + H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT)<0 || + H5Tinsert(dt, "b", HOFFSET(struct dt, b), H5T_NATIVE_INT)<0 || + H5Tinsert(dt, "c", HOFFSET(struct dt, c), array_dt)<0 || + H5Tinsert(dt, "d", HOFFSET(struct dt, d), H5T_NATIVE_INT)<0 || + H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); /* Perform the conversion */ if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT)<0) goto error; @@ -554,9 +557,10 @@ test_compound_3(void) } *d_ptr; const int nelmts = NTESTELEM; - const size_t four = 4; + const hsize_t four = 4; unsigned char *buf=NULL, *orig=NULL, *bkg=NULL; hid_t st=-1, dt=-1; + hid_t array_dt; int i; TESTING("compound subset conversions"); @@ -566,37 +570,40 @@ test_compound_3(void) bkg = malloc(nelmts * sizeof(struct dt)); orig = malloc(nelmts * sizeof(struct st)); for (i=0; ia = i*8+0; - s_ptr->b = i*8+1; - s_ptr->c[0] = i*8+2; - s_ptr->c[1] = i*8+3; - s_ptr->c[2] = i*8+4; - s_ptr->c[3] = i*8+5; - s_ptr->d = i*8+6; - s_ptr->e = i*8+7; + s_ptr = ((struct st*)orig) + i; + s_ptr->a = i*8+0; + s_ptr->b = i*8+1; + s_ptr->c[0] = i*8+2; + s_ptr->c[1] = i*8+3; + s_ptr->c[2] = i*8+4; + s_ptr->c[3] = i*8+5; + s_ptr->d = i*8+6; + s_ptr->e = i*8+7; } memcpy(buf, orig, nelmts*sizeof(struct st)); /* Build hdf5 datatypes */ + array_dt=H5Tarray_create(H5T_NATIVE_INT, 1, &four, NULL); if ((st=H5Tcreate(H5T_COMPOUND, sizeof(struct st)))<0 || - H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT)<0 || - H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT)<0 || - H5Tinsert_array(st, "c", HOFFSET(struct st, c), 1, &four, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT)<0 || - H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT)<0) - goto error; + H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "c", HOFFSET(struct st, c), array_dt)<0 || + H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); + array_dt=H5Tarray_create(H5T_NATIVE_INT, 1, &four, NULL); if ((dt=H5Tcreate(H5T_COMPOUND, sizeof(struct dt)))<0 || - H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT)<0 || - H5Tinsert_array(dt, "c", HOFFSET(struct dt, c), 1, &four, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT)<0) - goto error; + H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT)<0 || + H5Tinsert(dt, "c", HOFFSET(struct dt, c), array_dt)<0 || + H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); /* Perform the conversion */ - if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT)<0) goto error; + if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT)<0) + goto error; /* Compare results */ for (i=0; ia = i*8+0; - s_ptr->b = (i*8+1) & 0x7fff; - s_ptr->c[0] = i*8+2; - s_ptr->c[1] = i*8+3; - s_ptr->c[2] = i*8+4; - s_ptr->c[3] = i*8+5; - s_ptr->d = (i*8+6) & 0x7fff; - s_ptr->e = i*8+7; + s_ptr = ((struct st*)orig) + i; + s_ptr->a = i*8+0; + s_ptr->b = (i*8+1) & 0x7fff; + s_ptr->c[0] = i*8+2; + s_ptr->c[1] = i*8+3; + s_ptr->c[2] = i*8+4; + s_ptr->c[3] = i*8+5; + s_ptr->d = (i*8+6) & 0x7fff; + s_ptr->e = i*8+7; } memcpy(buf, orig, nelmts*sizeof(struct st)); /* Build hdf5 datatypes */ + array_dt=H5Tarray_create(H5T_NATIVE_INT, 1, &four, NULL); if ((st=H5Tcreate(H5T_COMPOUND, sizeof(struct st)))<0 || - H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT)<0 || - H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT)<0 || - H5Tinsert_array(st, "c", HOFFSET(struct st, c), 1, &four, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT)<0 || - H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT)<0) - goto error; + H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "c", HOFFSET(struct st, c), array_dt)<0 || + H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT)<0 || + H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); + array_dt=H5Tarray_create(H5T_NATIVE_INT, 1, &four, NULL); if ((dt=H5Tcreate(H5T_COMPOUND, sizeof(struct dt)))<0 || - H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT)<0 || - H5Tinsert(dt, "b", HOFFSET(struct dt, b), H5T_NATIVE_SHORT)<0 || - H5Tinsert_array(dt, "c", HOFFSET(struct dt, c), 1, &four, NULL, - H5T_NATIVE_INT)<0 || - H5Tinsert(dt, "d", HOFFSET(struct dt, d), H5T_NATIVE_SHORT)<0 || - H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT)<0) - goto error; + H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT)<0 || + H5Tinsert(dt, "b", HOFFSET(struct dt, b), H5T_NATIVE_SHORT)<0 || + H5Tinsert(dt, "c", HOFFSET(struct dt, c), array_dt)<0 || + H5Tinsert(dt, "d", HOFFSET(struct dt, d), H5T_NATIVE_SHORT)<0 || + H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT)<0) + goto error; + H5Tclose(array_dt); /* Perform the conversion */ - if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT)<0) goto error; + if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT)<0) + goto error; /* Compare results */ for (i=0; i + * Thursday, November 09, 2000 + * + * Purpose: Create a two datasets, one with a compound datatypes with array + * fields (which should be stored in the newer version (version 2)) and + * one with an array datatype. + * This program is used to create the test file `tarrnew.h5' which has a + * datatypes stored in the newer (version 2) style in the object headers. + * To build the test file, this program MUST be compiled and linked with + * the hdf5-1.3+ series of libraries and the generated test file must be + * put into the 'test' directory in the 1.2.x branch of the library. + * The test file should be generated on a little-endian machine with + * 16-bit shorts, 32-bit floats, 32-bit ints and 64-bit doubles. + */ +#include + +#define TESTFILE "tarrnew.h5" + +/* 1-D array datatype */ +#define ARRAY1_RANK 1 +#define ARRAY1_DIM1 4 + +/* 2-D dataset with fixed dimensions */ +#define SPACE1_RANK 2 +#define SPACE1_DIM1 8 +#define SPACE1_DIM2 9 + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: + * + * Return: Success: + * + * Failure: + * + * Programmer: Robb Matzke + * Monday, October 26, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +main(void) +{ + typedef struct { /* Typedef for compound datatype */ + short i; + float f[ARRAY1_DIM1]; + long l[ARRAY1_DIM1]; + double d; + } s3_t; + hid_t file, space, type, arr_type, dset; + hsize_t tdims1[] = {ARRAY1_DIM1}; + hsize_t cur_dim[SPACE1_RANK]={SPACE1_DIM1,SPACE1_DIM2}; + herr_t ret; /* Generic return value */ + + /* Create the file */ + file = H5Fcreate(TESTFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if(file<0) + printf("file<0!\n"); + + /* Create the dataspace (for both datasets) */ + space = H5Screate_simple(SPACE1_RANK, cur_dim, NULL); + if(space<0) + printf("space<0!\n"); + + /* Create the compound datatype with array fields */ + type = H5Tcreate(H5T_COMPOUND, sizeof(s3_t)); + if(type<0) + printf("type<0!\n"); + + /* Insert integer field */ + ret = H5Tinsert (type, "i", HOFFSET(s3_t,i), H5T_NATIVE_SHORT); + if(ret<0) + printf("field 1 insert<0!\n"); + + /* Creat the array datatype */ + arr_type=H5Tarray_create(H5T_NATIVE_FLOAT,ARRAY1_RANK,tdims1,NULL); + if(arr_type<0) + printf("arr_type<0!\n"); + + /* Insert float array field */ + ret = H5Tinsert (type, "f", HOFFSET(s3_t,f), arr_type); + if(ret<0) + printf("field 3 insert<0!\n"); + + /* Close array datatype */ + ret = H5Tclose (arr_type); + if(ret<0) + printf("field 3 array close<0!\n"); + + /* Creat the array datatype */ + arr_type=H5Tarray_create(H5T_NATIVE_LONG,ARRAY1_RANK,tdims1,NULL); + if(arr_type<0) + printf("arr_type<0!\n"); + + /* Insert long array field */ + ret = H5Tinsert (type, "l", HOFFSET(s3_t,l), arr_type); + if(ret<0) + printf("field 3 insert<0!\n"); + + /* Close array datatype */ + ret = H5Tclose (arr_type); + if(ret<0) + printf("field 3 array close<0!\n"); + + /* Insert double field */ + ret = H5Tinsert (type, "d", HOFFSET(s3_t,d), H5T_NATIVE_DOUBLE); + if(ret<0) + printf("field 4 insert<0!\n"); + + /* Create the dataset with compound array fields */ + dset = H5Dcreate(file, "Dataset1", type, space, H5P_DEFAULT); + if(dset<0) + printf("dset<0!\n"); + H5Dclose(dset); + + /* Close compound datatype */ + H5Tclose(type); + + /* Create the compound datatype with array fields */ + type = H5Tarray_create(H5T_NATIVE_INT, ARRAY1_RANK, tdims1, NULL); + if(type<0) + printf("type<0!\n"); + + /* Create the dataset with array datatype */ + dset = H5Dcreate(file, "Dataset2", type, space, H5P_DEFAULT); + if(dset<0) + printf("dset<0!\n"); + H5Dclose(dset); + + /* Close array datatype */ + H5Tclose(type); + + H5Sclose(space); + H5Fclose(file); + + return 0; +} + diff --git a/test/gen_old_array.c b/test/gen_old_array.c new file mode 100644 index 0000000..c307b4f --- /dev/null +++ b/test/gen_old_array.c @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2000 NCSA + * All rights reserved. + * + * Programmer: Quincey Koziol + * Thursday, November 09, 2000 + * + * Purpose: Create a two datasets with compound datatypes, one with no array + * fields and one with array fields. + * This program is used to create the test file `tarrold.h5' which has a + * datatypes stored in the older (version 1) style in the object headers. + * To build the test file, this program MUST be compiled and linked with + * the hdf5-1.2.x series of libraries and the generated test file must be + * put into the 'test' directory in the 1.3+ branch of the library. + * The test file should be generated on a little-endian machine with + * 16-bit shorts, 32-bit floats, 32-bit ints and 64-bit doubles. + */ +#include + +#define TESTFILE "tarrold.h5" + +/* 1-D array datatype */ +#define ARRAY1_RANK 1 +#define ARRAY1_DIM1 4 + +/* 2-D dataset with fixed dimensions */ +#define SPACE1_RANK 2 +#define SPACE1_DIM1 8 +#define SPACE1_DIM2 9 + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: + * + * Return: Success: + * + * Failure: + * + * Programmer: Robb Matzke + * Monday, October 26, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +main(void) +{ + typedef struct { /* Typedef for compound datatype */ + short i; + float f; + long l; + } s2_t; + typedef struct { /* Typedef for compound datatype */ + short i; + float f[ARRAY1_DIM1]; + long l[ARRAY1_DIM1]; + double d; + } s3_t; + hid_t file, space, type, dset; + size_t tdims1[] = {ARRAY1_DIM1}; + hsize_t cur_dim[SPACE1_RANK]={SPACE1_DIM1,SPACE1_DIM2}; + herr_t ret; /* Generic return value */ + + /* Create the file */ + file = H5Fcreate(TESTFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if(file<0) + printf("file<0!\n"); + + /* Create the dataspace (for both datasets) */ + space = H5Screate_simple(SPACE1_RANK, cur_dim, NULL); + if(space<0) + printf("space<0!\n"); + + /* Create the compound datatype with non-array fields */ + type = H5Tcreate(H5T_COMPOUND, sizeof(s2_t)); + if(type<0) + printf("type<0!\n"); + + /* Insert integer field */ + ret = H5Tinsert (type, "i", HOFFSET(s2_t,i), H5T_NATIVE_SHORT); + if(ret<0) + printf("field 1 insert<0!\n"); + + /* Insert float field */ + ret = H5Tinsert (type, "f", HOFFSET(s2_t,f), H5T_NATIVE_FLOAT); + if(ret<0) + printf("field 3 insert<0!\n"); + + /* Insert long field */ + ret = H5Tinsert (type, "l", HOFFSET(s2_t,l), H5T_NATIVE_LONG); + if(ret<0) + printf("field 3 insert<0!\n"); + + /* Create the dataset with compound non-array fields */ + dset = H5Dcreate(file, "Dataset1", type, space, H5P_DEFAULT); + if(dset<0) + printf("dset<0!\n"); + H5Dclose(dset); + + /* Close first compound datatype */ + H5Tclose(type); + + /* Create the compound datatype with array fields */ + type = H5Tcreate(H5T_COMPOUND, sizeof(s3_t)); + if(type<0) + printf("type<0!\n"); + + /* Insert integer field */ + ret = H5Tinsert (type, "i", HOFFSET(s3_t,i), H5T_NATIVE_SHORT); + if(ret<0) + printf("field 1 insert<0!\n"); + + /* Insert float array field */ + ret = H5Tinsert_array (type, "f", HOFFSET(s3_t,f), ARRAY1_RANK, tdims1, NULL, H5T_NATIVE_FLOAT); + if(ret<0) + printf("field 3 insert<0!\n"); + + /* Insert long array field */ + ret = H5Tinsert_array (type, "l", HOFFSET(s3_t,l), ARRAY1_RANK, tdims1, NULL, H5T_NATIVE_LONG); + if(ret<0) + printf("field 3 insert<0!\n"); + + /* Insert double field */ + ret = H5Tinsert (type, "d", HOFFSET(s3_t,d), H5T_NATIVE_DOUBLE); + if(ret<0) + printf("field 4 insert<0!\n"); + + /* Create the dataset with compound array fields */ + dset = H5Dcreate(file, "Dataset2", type, space, H5P_DEFAULT); + if(dset<0) + printf("dset<0!\n"); + H5Dclose(dset); + + /* Close second compound datatype */ + H5Tclose(type); + + H5Sclose(space); + H5Fclose(file); + + return 0; +} diff --git a/test/tarray.c b/test/tarray.c new file mode 100644 index 0000000..6877981 --- /dev/null +++ b/test/tarray.c @@ -0,0 +1,1849 @@ +/**************************************************************************** + * NCSA HDF * + * Software Development Group * + * National Center for Supercomputing Applications * + * University of Illinois at Urbana-Champaign * + * 605 E. Springfield, Champaign IL 61820 * + * * + * For conditions of distribution and use, see the accompanying * + * hdf/COPYING file. * + * * + ****************************************************************************/ + +#ifdef RCSID +static char RcsId[] = "$Revision$"; +#endif + +/* $Id$ */ + +/*********************************************************** +* +* Test program: tarray +* +* Test the Array Datatype functionality +* +*************************************************************/ + +#include + +#include + +#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 */ + intn 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) { + num_errs++; + printf("Compound field name doesn't match!, mname=%s\n",mname); + } /* end if */ + 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) { + num_errs++; + printf("Compound data type is incorrect!, ret=%d\n",(int)ret); + } /* end if */ + 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) { + num_errs++; + printf("Compound field name doesn't match!, mname=%s\n",mname); + } /* end if */ + 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) { + num_errs++; + printf("Compound data type is incorrect!, ret=%d\n",(int)ret); + } /* end if */ + 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) { + num_errs++; + printf("Compound field name doesn't match!, mname=%s\n",mname); + } /* end if */ + 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) { + num_errs++; + printf("Compound data type is incorrect!, ret=%d\n",(int)ret); + } /* end if */ + 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) { + num_errs++; + printf("Compound field name doesn't match!, mname=%s\n",mname); + } /* end if */ + 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) { + num_errs++; + printf("Compound data type is incorrect!, ret=%d\n",(int)ret); + } /* end if */ + 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) { + num_errs++; + printf("Compound field name doesn't match!, mname=%s\n",mname); + } /* end if */ + 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