diff options
Diffstat (limited to 'tools/h5repack/h5repacktst.c')
-rw-r--r-- | tools/h5repack/h5repacktst.c | 400 |
1 files changed, 330 insertions, 70 deletions
diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c index 3198b76..d302dd4 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -103,11 +103,11 @@ int d_status = EXIT_SUCCESS; #define USERBLOCK_SIZE 2048 /* obj and region references */ -#define NAME_OBJ_DS "Dset1" +#define NAME_OBJ_DS1 "Dset1" #define NAME_OBJ_GRP "Group" #define NAME_OBJ_NDTYPE "NamedDatatype" +#define NAME_OBJ_DS2 "Dset2" #define REG_REF_DS1 "Dset_REGREF" -#define REG_REF_DS2 "Dset2" /*------------------------------------------------------------------------- * prototypes @@ -1765,10 +1765,13 @@ int make_testfiles(void) return -1; /*------------------------------------------------------------------------- - * create a file with obj and region references + * create obj and region reference type datasets (bug1814) + * add attribute with int type (bug1726) + * add attribute with obj and region reference type (bug1726) *-------------------------------------------------------------------------*/ if((fid = H5Fcreate(FNAME_REF,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT)) < 0) return -1; + /* create reference type datasets */ if (make_references(fid) < 0) goto out; if(H5Fclose(fid) < 0) @@ -5595,29 +5598,173 @@ out: } /* end make_named_dtype() */ /*------------------------------------------------------------------------- - * Function: gen_obj_ref + * Function: add_attr_with_objref * * Purpose: - * Generate object references to objects (dataset,group and named datatype) + * Create attributes with object reference to objects (dset, + * group, datatype). * * Note: - * copied from h5copygentest.c and upate to create named datatype + * this function depends on locally created objects, however can be modified + * to be independent as necessary * - * Programmer: Jonathan Kim (March 18, 2010) + * Programmer: Jonathan Kim (March 23, 2010) *------------------------------------------------------------------------*/ -static herr_t gen_obj_ref(hid_t loc_id) +static herr_t add_attr_with_objref(hid_t file_id, hid_t obj_id) { - hid_t sid=0, oid=0, tid=0; - hsize_t dims1[1]={3}; - hsize_t dims2[1]={3}; - int data[3] = {10,20,30}; - hobj_ref_t objref_buf[3]; /* write buffer for obj reference */ + int ret = SUCCEED; + int status; + int data_attr_int[2] = {10,20}; + /* attr obj ref */ + hsize_t dim_attr_objref[1]={3}; + hobj_ref_t data_attr_objref[3]; + + /* -------------------------------- + * add attribute with obj ref type + */ + /* ref to dset */ + status = H5Rcreate(&data_attr_objref[0],file_id,NAME_OBJ_DS1,H5R_OBJECT,-1); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* ref to group */ + status = H5Rcreate(&data_attr_objref[1],file_id,NAME_OBJ_GRP,H5R_OBJECT,-1); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* ref to datatype */ + status = H5Rcreate(&data_attr_objref[2],file_id,NAME_OBJ_NDTYPE,H5R_OBJECT,-1); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* create attr with obj ref type */ + status = make_attr(obj_id,1,dim_attr_objref,"Attr_OBJREF",H5T_STD_REF_OBJ,data_attr_objref); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> make_attr failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + +out: + + return ret; + +} + +/*------------------------------------------------------------------------- + * Function: add_attr_with_regref + * + * Purpose: + * Create attributes with region reference to dset + * + * Note: + * this function depends on locally created objects, however can be modified + * to be independent as necessary + * + * Programmer: Jonathan Kim (March 23, 2010) + *------------------------------------------------------------------------*/ +static herr_t add_attr_with_regref(hid_t file_id, hid_t obj_id) +{ + int ret = SUCCEED; + int status; + + /* attr region ref */ + hid_t sid_regrefed_dset=0; + hsize_t dim_regrefed_dset[2]={3,6}; + hsize_t coords_regrefed_dset[3][2] = {{0,1},{1,2},{2,3}}; + hsize_t dim_attr_regref[1]= {1}; /* dim of */ + hdset_reg_ref_t data_attr_regref[1]; + + + /* ----------------------------------- + * add attribute with region ref type + */ + sid_regrefed_dset = H5Screate_simple (2, dim_regrefed_dset, NULL); + if (sid_regrefed_dset < 0) + { + fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* select elements space for reference */ + status = H5Sselect_elements (sid_regrefed_dset, H5S_SELECT_SET, 3, coords_regrefed_dset[0]); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Sselect_elements failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* create region reference from elements space */ + status = H5Rcreate (&data_attr_regref[0], file_id, NAME_OBJ_DS2, H5R_DATASET_REGION, sid_regrefed_dset); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* create attr with region ref type */ + status = make_attr(obj_id,1,dim_attr_regref,"Attr_REGREF",H5T_STD_REF_DSETREG,data_attr_regref); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> make_attr failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + +out: + if (sid_regrefed_dset > 0) + H5Sclose (sid_regrefed_dset); + return ret; + +} + +/*------------------------------------------------------------------------- + * Function: gen_refered_objs + * + * Purpose: + * Create objects (dataset, group, datatype) to be referenced + * + * Note: + * This function is to use along with gen_obj_ref() gen_region_ref() + * + * Programmer: Jonathan Kim (March 23, 2010) + *------------------------------------------------------------------------*/ +static herr_t gen_refered_objs(hid_t loc_id) +{ int status; herr_t ret = SUCCEED; - /*-------------- - * add dataset */ + /* objects (dset, group, datatype) */ + hid_t sid=0, did1=0, gid=0, tid=0; + hsize_t dims1[1]={3}; + int data[3] = {10,20,30}; + + /* Dset2 */ + hid_t sid2=0, did2=0; + hsize_t dims2[2] = {3,16}; + char data2[3][16] = {"The quick brown", "fox jumps over ", "the 5 lazy dogs"}; + + /*----------------------- + * add short dataset + * (define NAME_OBJ_DS1) + */ sid = H5Screate_simple(1, dims1, NULL); if (sid < 0) { @@ -5626,15 +5773,15 @@ static herr_t gen_obj_ref(hid_t loc_id) goto out; } - oid = H5Dcreate2 (loc_id, NAME_OBJ_DS, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (oid < 0) + did1 = H5Dcreate2 (loc_id, NAME_OBJ_DS1, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (did1 < 0) { fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", FUNC, __LINE__); ret = FAIL; goto out; } - status = H5Dwrite(oid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); + status = H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); if (status < 0) { fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", FUNC, __LINE__); @@ -5642,22 +5789,21 @@ static herr_t gen_obj_ref(hid_t loc_id) goto out; } - H5Dclose(oid); - H5Sclose(sid); - /*-------------- - * add group */ - oid = H5Gcreate2 (loc_id, NAME_OBJ_GRP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (oid < 0) + * add group + * (define NAME_OBJ_GRP) + */ + gid = H5Gcreate2 (loc_id, NAME_OBJ_GRP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (gid < 0) { fprintf(stderr, "Error: %s %d> H5Gcreate2 failed.\n", FUNC, __LINE__); ret = FAIL; goto out; } - H5Gclose(oid); /*---------------------- * add named datatype + * (define NAME_OBJ_NDTYPE) */ tid = H5Tcopy(H5T_NATIVE_INT); status = H5Tcommit2(loc_id, NAME_OBJ_NDTYPE, tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); @@ -5668,12 +5814,87 @@ static herr_t gen_obj_ref(hid_t loc_id) goto out; } + + /*-------------------------- + * create long dataset + * (define NAME_OBJ_DS2) + */ + sid2 = H5Screate_simple (2, dims2, NULL); + if (sid2 < 0) + { + fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* create normal dataset which is refered */ + did2 = H5Dcreate2 (loc_id, NAME_OBJ_DS2, H5T_STD_I8LE, sid2, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); + if (did2 < 0) + { + fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* write values to dataset */ + status = H5Dwrite (did2, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, data2); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + +out: + if(did1 > 0) + H5Dclose(did1); + if(gid > 0) + H5Gclose(gid); + if(tid > 0) + H5Tclose(tid); + if(sid > 0) + H5Sclose(sid); + + if(did2 > 0) + H5Dclose(did2); + if(sid2 > 0) + H5Sclose(sid2); + return ret; + +} + +/*------------------------------------------------------------------------- + * Function: gen_obj_ref + * + * Purpose: + * Generate object references to objects (dataset,group and named datatype) + * + * Note: + * copied from h5copygentest.c and upate to create named datatype + * + * Programmer: Jonathan Kim (March 18, 2010) + *------------------------------------------------------------------------*/ +static herr_t gen_obj_ref(hid_t loc_id) +{ + int status; + herr_t ret = SUCCEED; + + hid_t sid=0, oid=0; + hsize_t dims_dset_objref[1]={3}; + + /* attr with int type */ + hsize_t dim_attr_int[1]={2}; + int data_attr_int[2] = {10,20}; + + /* write buffer for obj reference */ + hobj_ref_t objref_buf[3]; + /*--------------------------------------------------------- * create obj references to the previously created objects. * Passing -1 as reference is an object.*/ /* obj ref to dataset */ - status = H5Rcreate (&objref_buf[0], loc_id, NAME_OBJ_DS, H5R_OBJECT, -1); + status = H5Rcreate (&objref_buf[0], loc_id, NAME_OBJ_DS1, H5R_OBJECT, -1); if (status < 0) { fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); @@ -5702,7 +5923,7 @@ static herr_t gen_obj_ref(hid_t loc_id) /*--------------------------------------------------------- * create dataset contain references */ - sid = H5Screate_simple (1, dims2, NULL); + sid = H5Screate_simple (1, dims_dset_objref, NULL); if (sid < 0) { fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", FUNC, __LINE__); @@ -5726,11 +5947,31 @@ static herr_t gen_obj_ref(hid_t loc_id) goto out; } + /* add attribute with int type */ + if (make_attr(oid,1,dim_attr_int,"integer",H5T_NATIVE_INT,data_attr_int) < 0) + goto out; + + /* add attribute with obj ref */ + status = add_attr_with_objref(loc_id, oid); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> add_attr_with_objref failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* add attribute with region ref */ + status = add_attr_with_regref(loc_id, oid); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> add_attr_with_regref failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + out: if(oid > 0) H5Dclose(oid); - if(tid > 0) - H5Tclose(tid); if(sid > 0) H5Sclose(sid); @@ -5750,13 +5991,18 @@ out: *------------------------------------------------------------------------*/ static herr_t gen_region_ref(hid_t loc_id) { - hid_t sid=0, oid1=0, oid2=0; int status; herr_t ret = SUCCEED; - char data[3][16] = {"The quick brown", "fox jumps over ", "the 5 lazy dogs"}; - hsize_t dims2[2] = {3,16}; - hsize_t coords[4][2] = { {0,1}, {2,11}, {1,0}, {2,4} }; + /* target dataset */ + hid_t sid_trg=0; + hsize_t dims_trg[2] = {3,16}; + + /* dset with region ref type */ + hid_t sid_ref=0, oid_ref=0; + + /* region ref to target dataset */ + hsize_t coords[4][2] = { {0,1}, {2,11}, {1,0}, {2,4} }; hdset_reg_ref_t rr_data[2]; hsize_t start[2] = {0,0}; hsize_t stride[2] = {2,11}; @@ -5764,34 +6010,20 @@ static herr_t gen_region_ref(hid_t loc_id) hsize_t block[2] = {1,3}; hsize_t dims1[1] = {2}; - sid = H5Screate_simple (2, dims2, NULL); - if (sid < 0) - { - fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", FUNC, __LINE__); - ret = FAIL; - goto out; - } - - /* create normal dataset which is refered */ - oid2 = H5Dcreate2 (loc_id, REG_REF_DS2, H5T_STD_I8LE, sid, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); - if (oid2 < 0) - { - fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", FUNC, __LINE__); - ret = FAIL; - goto out; - } + /* attr with int type */ + hsize_t dim_attr_int[1]={2}; + int data_attr_int[2] = {10,20}; - /* write values to dataset */ - status = H5Dwrite (oid2, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); - if (status < 0) + sid_trg = H5Screate_simple (2, dims_trg, NULL); + if (sid_trg < 0) { - fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", FUNC, __LINE__); + fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", FUNC, __LINE__); ret = FAIL; goto out; } /* select elements space for reference */ - status = H5Sselect_elements (sid, H5S_SELECT_SET, 4, coords[0]); + status = H5Sselect_elements (sid_trg, H5S_SELECT_SET, 4, coords[0]); if (status < 0) { fprintf(stderr, "Error: %s %d> H5Sselect_elements failed.\n", FUNC, __LINE__); @@ -5800,7 +6032,7 @@ static herr_t gen_region_ref(hid_t loc_id) } /* create region reference from elements space */ - status = H5Rcreate (&rr_data[0], loc_id, REG_REF_DS2, H5R_DATASET_REGION, sid); + status = H5Rcreate (&rr_data[0], loc_id, NAME_OBJ_DS2, H5R_DATASET_REGION, sid_trg); if (status < 0) { fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); @@ -5809,7 +6041,7 @@ static herr_t gen_region_ref(hid_t loc_id) } /* select hyperslab space for reference */ - status = H5Sselect_hyperslab (sid, H5S_SELECT_SET, start, stride, count, block); + status = H5Sselect_hyperslab (sid_trg, H5S_SELECT_SET, start, stride, count, block); if (status < 0) { fprintf(stderr, "Error: %s %d> H5Sselect_hyperslab failed.\n", FUNC, __LINE__); @@ -5818,7 +6050,7 @@ static herr_t gen_region_ref(hid_t loc_id) } /* create region reference from hyperslab space */ - status = H5Rcreate (&rr_data[1], loc_id, REG_REF_DS2, H5R_DATASET_REGION, sid); + status = H5Rcreate (&rr_data[1], loc_id, NAME_OBJ_DS2, H5R_DATASET_REGION, sid_trg); if (status < 0) { fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); @@ -5826,11 +6058,9 @@ static herr_t gen_region_ref(hid_t loc_id) goto out; } - H5Sclose (sid); - /* Create dataspace. */ - sid = H5Screate_simple (1, dims1, NULL); - if (sid < 0) + sid_ref = H5Screate_simple (1, dims1, NULL); + if (sid_ref < 0) { fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", FUNC, __LINE__); ret = FAIL; @@ -5838,8 +6068,8 @@ static herr_t gen_region_ref(hid_t loc_id) } /* create region reference dataset */ - oid1 = H5Dcreate2 (loc_id, REG_REF_DS1, H5T_STD_REF_DSETREG, sid, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); - if (oid1 < 0) + oid_ref = H5Dcreate2 (loc_id, REG_REF_DS1, H5T_STD_REF_DSETREG, sid_ref, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); + if (oid_ref < 0) { fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", FUNC, __LINE__); ret = FAIL; @@ -5847,7 +6077,7 @@ static herr_t gen_region_ref(hid_t loc_id) } /* write data as region references */ - status = H5Dwrite (oid1, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, rr_data); + status = H5Dwrite (oid_ref, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, rr_data); if (status < 0) { fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", FUNC, __LINE__); @@ -5855,13 +6085,35 @@ static herr_t gen_region_ref(hid_t loc_id) goto out; } + /* add attribute with int type */ + if (make_attr(oid_ref,1,dim_attr_int,"integer",H5T_NATIVE_INT,data_attr_int) < 0) + goto out; + + /* add attribute with obj ref */ + status = add_attr_with_objref(loc_id, oid_ref); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> add_attr_with_objref failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* add attribute with region ref */ + status = add_attr_with_regref(loc_id, oid_ref); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> add_attr_with_regref failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + out: - if (oid1 > 0) - H5Dclose (oid1); - if (oid2 > 0) - H5Dclose (oid2); - if (sid > 0) - H5Sclose (sid); + if (oid_ref > 0) + H5Dclose (oid_ref); + if (sid_ref > 0) + H5Sclose (sid_ref); + if (sid_trg > 0) + H5Sclose (sid_trg); return ret; } @@ -5879,6 +6131,14 @@ static herr_t make_references(hid_t loc_id) herr_t ret = SUCCEED; herr_t status; + /* add target objects */ + status = gen_refered_objs(loc_id); + if (status == FAIL) + { + fprintf(stderr, "Failed to generate referenced object.\n"); + ret = FAIL; + } + /* add object reference */ status = gen_obj_ref(loc_id); if (status == FAIL) |