diff options
Diffstat (limited to 'tools/h5dump/h5dumpgentest.c')
-rw-r--r-- | tools/h5dump/h5dumpgentest.c | 270 |
1 files changed, 256 insertions, 14 deletions
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index 4d89d3e..7f6fc3b 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -35,6 +35,7 @@ #define FILE2 "tdset.h5" #define FILE3 "tattr.h5" #define FILE4 "tslink.h5" +#define FILE4_1 "tsoftlinks.h5" #define FILE5 "thlink.h5" #define FILE6 "tcompound.h5" #define FILE7 "tall.h5" @@ -471,6 +472,246 @@ static void gent_softlink(void) H5Fclose(fid); } +/*------------------------------------------------------------------------- + * Function: gent_softlink2 + * + * Purpose: Create soft links to various objects. + * Return: + * SUCCEED + * FAIL + * Programmer: Jonathan Kim + * Date: May 26, 2010 + *-------------------------------------------------------------------------*/ +#define NX 4 +#define NY 2 +static int gent_softlink2(void) +{ + hid_t fileid1; + hid_t grp1=0, grp2=0; + hid_t tid; + hid_t dset1, dset2; + hid_t datatype, dataspace; + hsize_t dimsf[2]; /* dataset dimensions */ + herr_t status=SUCCEED; + int data1[NX][NY] = {{0,0},{1,1},{2,2},{3,3}}; + int data2[NX][NY] = {{0,0},{0,1},{0,2},{3,3}}; + + /*----------------------------------------------------------------------- + * FILE + *------------------------------------------------------------------------*/ + /* Create a new file */ + fileid1 = H5Fcreate(FILE4_1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if (fileid1 < 0) + { + fprintf(stderr, "Error: %s> H5Fcreate failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /*----------------------------------------------------------------------- + * Groups + *------------------------------------------------------------------------*/ + grp1 = H5Gcreate2(fileid1, "group1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (grp1 < 0) + { + fprintf(stderr, "Error: %s> H5Gcreate2 failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + grp2 = H5Gcreate2(fileid1, "group_empty", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (grp2 < 0) + { + fprintf(stderr, "Error: %s> H5Gcreate2 failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /*----------------------------------------------------------------------- + * Named datatype + *------------------------------------------------------------------------*/ + tid = H5Tcopy(H5T_NATIVE_INT); + status = H5Tcommit2(fileid1, "dtype", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Tcommit2 failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /*----------------------------------------------------------------------- + * Datasets + *------------------------------------------------------------------------*/ + /* + * Describe the size of the array and create the data space for fixed + * size dataset. + */ + dimsf[0] = NX; + dimsf[1] = NY; + dataspace = H5Screate_simple(2, dimsf, NULL); + + /* + * Define datatype for the data in the file. + * We will store little endian INT numbers. + */ + datatype = H5Tcopy(H5T_NATIVE_INT); + + /*--------------- + * dset1 + */ + /* Create a new dataset as sample object */ + dset1 = H5Dcreate2(fileid1, "/dset1", datatype, dataspace, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (dset1 < 0) + { + fprintf(stderr, "Error: %s> H5Dcreate2 failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + status = H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data1); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /*--------------- + * dset2 + */ + /* Create a new dataset as sample object */ + dset2 = H5Dcreate2(fileid1, "/dset2", datatype, dataspace, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (dset2 < 0) + { + fprintf(stderr, "Error: %s> H5Dcreate2 failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + status = H5Dwrite(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data2); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /*----------------------------------------------------------------------- + * Soft links + *------------------------------------------------------------------------*/ + /* + * create various soft links under '/' root + */ + /* link to dset1 */ + status = H5Lcreate_soft("/dset1", fileid1, "soft_dset1", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /* link to data type */ + status = H5Lcreate_soft("/dtype", fileid1, "soft_dtype", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /* link to group1 */ + status = H5Lcreate_soft("/group1", fileid1, "soft_group1", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /* link to empty group */ + status = H5Lcreate_soft("/group_empty", fileid1, "soft_empty_grp", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /* dangling link */ + status = H5Lcreate_soft("not_yet", fileid1, "soft_dangle", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /*----------------------------------------- + * create various soft links under a group + */ + /* link to dset1 */ + status = H5Lcreate_soft("/dset1", grp1, "soft_dset1", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /* link to dset2 */ + status = H5Lcreate_soft("/dset2", grp1, "soft_dset2", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /* link to data type */ + status = H5Lcreate_soft("/dtype", grp1, "soft_dtype", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /* link to empty group */ + status = H5Lcreate_soft("/group_empty", grp1, "soft_empty_grp", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + + /* dangling link */ + status = H5Lcreate_soft("not_yet", grp1, "soft_dangle", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Lcreate_soft failed.\n", FILE4_1); + status = FAIL; + goto out; + } + +out: + /* + * Close/release resources. + */ + H5Sclose(dataspace); + H5Gclose(grp1); + H5Gclose(grp2); + H5Tclose(datatype); + H5Dclose(dset1); + H5Dclose(dset2); + H5Fclose(fileid1); + + return status; +} + /* / @@ -1666,7 +1907,7 @@ static void gent_objref(void) hid_t sid1; /* Dataspace ID */ hid_t tid1; /* Datatype ID */ hsize_t dims1[] = {SPACE1_DIM1}; - hobj_ref_t *wbuf, /* buffer to write to disk */ + hobj_ref_t *wbuf, /* buffer to write to disk */ *rbuf, /* buffer read from disk */ *tbuf; /* temp. buffer read from disk */ uint32_t *tu32; /* Temporary pointer to uint32 data */ @@ -1674,9 +1915,9 @@ static void gent_objref(void) const char *write_comment = "Foo!"; /* Comments for group */ /* Allocate write & read buffers */ - wbuf = malloc(sizeof(hobj_ref_t) * SPACE1_DIM1); - rbuf = malloc(sizeof(hobj_ref_t) * SPACE1_DIM1); - tbuf = malloc(sizeof(hobj_ref_t) * SPACE1_DIM1); + wbuf = (hobj_ref_t*) malloc(sizeof(hobj_ref_t) * SPACE1_DIM1); + rbuf = (hobj_ref_t*) malloc(sizeof(hobj_ref_t) * SPACE1_DIM1); + tbuf = (hobj_ref_t*) malloc(sizeof(hobj_ref_t) * SPACE1_DIM1); /* Create file */ fid1 = H5Fcreate(FILE16, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); @@ -1784,10 +2025,10 @@ static void gent_datareg(void) int i; /* counting variables */ /* Allocate write & read buffers */ - wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1); - rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); - dwbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); - drbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + wbuf = (hdset_reg_ref_t*) calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1); + rbuf = (hdset_reg_ref_t*) malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); + dwbuf = (uint8_t*) malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + drbuf = (uint8_t*) calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); /* Create file */ fid1 = H5Fcreate(FILE17, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); @@ -1893,10 +2134,10 @@ static void gent_attrreg(void) int i; /* counting variables */ /* Allocate write & read buffers */ - wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1); - rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); - dwbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); - drbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + wbuf = (hdset_reg_ref_t*) calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1); + rbuf = (hdset_reg_ref_t*) malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); + dwbuf = (uint8_t*) malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + drbuf = (uint8_t*) calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); /* Create file */ fid1 = H5Fcreate(FILE65, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); @@ -5660,7 +5901,7 @@ static void gent_longlinks(void) assert(gid >= 0); /* Construct very long file name */ - objname = HDmalloc((size_t)(F51_MAX_NAME_LEN + 1)); + objname = (char*) HDmalloc((size_t)(F51_MAX_NAME_LEN + 1)); assert(objname); for(u = 0; u < F51_MAX_NAME_LEN; u++) objname[u] = 'a'; @@ -5924,7 +6165,7 @@ gent_hyperslab(void) double *buf; int i, ret; - buf = malloc(32 * 4097 * sizeof(double) ); + buf = (double*) malloc(32 * 4097 * sizeof(double) ); for(i = 0; i < 32 * 4097; i++) buf[i] = 1; @@ -6657,6 +6898,7 @@ int main(void) gent_group(); gent_attribute(); gent_softlink(); + gent_softlink2(); gent_dataset(); gent_hardlink(); gent_extlink(); |