/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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: trefer * * Test the Reference functionality * *************************************************************/ #include "testhdf5.h" #include "hdf5.h" #define FILE1 "trefer1.h5" #define FILE2 "trefer2.h5" #define FILE3 "trefer3.h5" /* 1-D dataset with fixed dimensions */ #define SPACE1_RANK 1 #define SPACE1_DIM1 4 /* 2-D dataset with fixed dimensions */ #define SPACE2_RANK 2 #define SPACE2_DIM1 10 #define SPACE2_DIM2 10 /* Larger 1-D dataset with fixed dimensions */ #define SPACE3_RANK 1 #define SPACE3_DIM1 100 /* Element selection information */ #define POINT1_NPOINTS 10 /* Compound datatype */ typedef struct s1_t { unsigned int a; unsigned int b; float c; } s1_t; #define GROUPNAME "/group" #define GROUPNAME2 "group2" #define GROUPNAME3 "group3" #define DSETNAME "/dset" #define DSETNAME2 "dset2" #define NAME_SIZE 16 /**************************************************************** ** ** test_reference_params(): Test basic H5R (reference) parameters ** for correct processing ** ****************************************************************/ static void test_reference_params(void) { hid_t fid1; /* HDF5 File IDs */ hid_t dataset, /* Dataset ID */ dset2; /* Dereferenced dataset ID */ hid_t group; /* Group ID */ hid_t sid1; /* Dataspace ID */ hid_t tid1; /* Datatype ID */ hsize_t dims1[] = {SPACE1_DIM1}; hobj_ref_t *wbuf, /* buffer to write to disk */ *rbuf, /* buffer read from disk */ *tbuf; /* temp. buffer read from disk */ unsigned *tu32; /* Temporary pointer to uint32 data */ int i; /* counting variables */ const char *write_comment = "Foo!"; /* Comments for group */ herr_t ret; /* Generic return value */ size_t name_size; /* Size of reference name */ /* Output message about test being performed */ MESSAGE(5, ("Testing Reference Parameters\n")); /* Allocate write & read buffers */ wbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)) * SPACE1_DIM1); rbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)) * SPACE1_DIM1); tbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)) * SPACE1_DIM1); /* Create file */ fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fcreate"); /* Create dataspace for datasets */ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL); CHECK(sid1, FAIL, "H5Screate_simple"); /* Create a group */ group = H5Gcreate2(fid1, "Group1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(group, FAIL, "H5Gcreate2"); /* Set group's comment */ ret = H5Oset_comment(group, write_comment); CHECK(ret, FAIL, "H5Oset_comment"); /* Create a dataset (inside Group1) */ dataset = H5Dcreate2(group, "Dataset1", H5T_NATIVE_UINT, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); for(tu32 = (unsigned *)wbuf, i = 0; i < SPACE1_DIM1; i++) *tu32++=i*3; /* Write selection to disk */ ret = H5Dwrite(dataset, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf); CHECK(ret, FAIL, "H5Dwrite"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Create another dataset (inside Group1) */ dataset = H5Dcreate2(group, "Dataset2", H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Create a datatype to refer to */ tid1 = H5Tcreate(H5T_COMPOUND, sizeof(s1_t)); CHECK(tid1, FAIL, "H5Tcreate"); /* Insert fields */ ret = H5Tinsert(tid1, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT); CHECK(ret, FAIL, "H5Tinsert"); ret = H5Tinsert(tid1, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT); CHECK(ret, FAIL, "H5Tinsert"); ret = H5Tinsert(tid1, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT); CHECK(ret, FAIL, "H5Tinsert"); /* Save datatype for later */ ret = H5Tcommit2(group, "Datatype1", tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Tcommit2"); /* Close datatype */ ret = H5Tclose(tid1); CHECK(ret, FAIL, "H5Tclose"); /* Close group */ ret = H5Gclose(group); CHECK(ret, FAIL, "H5Gclose"); /* Create a dataset */ dataset = H5Dcreate2(fid1, "Dataset3", H5T_STD_REF_OBJ, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Dcreate2"); /* Test parameters to H5Rcreate */ ret = H5Rcreate(NULL, fid1, "/Group1/Dataset1", H5R_OBJECT, (hid_t)-1); VERIFY(ret, FAIL, "H5Rcreate ref"); ret = H5Rcreate(&wbuf[0], (hid_t)-1, "/Group1/Dataset1", H5R_OBJECT, (hid_t)-1); VERIFY(ret, FAIL, "H5Rcreate loc_id"); ret = H5Rcreate(&wbuf[0], fid1, NULL, H5R_OBJECT, (hid_t)-1); VERIFY(ret, FAIL, "H5Rcreate name"); ret = H5Rcreate(&wbuf[0], fid1, "", H5R_OBJECT, (hid_t)-1); VERIFY(ret, FAIL, "H5Rcreate null name"); ret = H5Rcreate(&wbuf[0], fid1, "/Group1/Dataset1", H5R_MAXTYPE, (hid_t)-1); VERIFY(ret, FAIL, "H5Rcreate type"); ret = H5Rcreate(&wbuf[0], fid1, "/Group1/Dataset1", H5R_DATASET_REGION, (hid_t)-1); VERIFY(ret, FAIL, "H5Rcreate region space"); ret = H5Rcreate(&wbuf[0], fid1, "/Group1/Dataset1", H5R_MAXTYPE, (hid_t)0); VERIFY(ret, FAIL, "H5Rcreate space"); /* Test parameters to H5Rdereference */ dset2 = H5Rdereference((hid_t)-1, H5R_OBJECT, &rbuf[0]); VERIFY(dset2, FAIL, "H5Rdereference loc_id"); dset2 = H5Rdereference(dataset, H5R_OBJECT, NULL); VERIFY(dset2, FAIL, "H5Rdereference ref"); dset2 = H5Rdereference(dataset, H5R_MAXTYPE, &rbuf[0]); VERIFY(dset2, FAIL, "H5Rdereference type"); /* Test parameters to H5Rget_obj_type2 */ ret = H5Rget_obj_type2((hid_t)-1, H5R_OBJECT, &rbuf[0], NULL); VERIFY(ret, FAIL, "H5Rget_obj_type2 loc_id"); ret = H5Rget_obj_type2(fid1, H5R_OBJECT, NULL, NULL); VERIFY(ret, FAIL, "H5Rget_obj_type2 ref"); ret = H5Rget_obj_type2(fid1, H5R_MAXTYPE, &rbuf[0], NULL); VERIFY(ret, FAIL, "H5Rget_obj_type2 type"); /* Test parameters to H5Rget_name */ name_size = H5Rget_name((hid_t)-1, H5R_DATASET_REGION, &rbuf[0], NULL, 0); VERIFY(name_size, FAIL, "H5Rget_name loc_id"); name_size = H5Rget_name(fid1, H5R_DATASET_REGION, NULL, NULL, 0); VERIFY(name_size, FAIL, "H5Rget_name ref"); name_size = H5Rget_name(fid1, H5R_MAXTYPE, &rbuf[0], NULL, 0); VERIFY(name_size, FAIL, "H5Rget_name type"); /* Test parameters to H5Rget_region */ ret = H5Rget_region((hid_t)-1, H5R_OBJECT, &rbuf[0]); VERIFY(ret, FAIL, "H5Rget_region loc_id"); ret = H5Rget_region(fid1, H5R_OBJECT, NULL); VERIFY(ret, FAIL, "H5Rget_region ref"); ret = H5Rget_region(fid1, H5R_OBJECT, &rbuf[0]); VERIFY(ret, FAIL, "H5Rget_region type"); /* Close disk dataspace */ ret = H5Sclose(sid1); CHECK(ret, FAIL, "H5Sclose"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close file */ ret = H5Fclose(fid1); CHECK(ret, FAIL, "H5Fclose"); /* Free memory buffers */ HDfree(wbuf); HDfree(rbuf); HDfree(tbuf); } /* test_reference_obj() */ /**************************************************************** ** ** test_reference_obj(): Test basic H5R (reference) object reference code. **