diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2009-09-04 14:50:13 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2009-09-04 14:50:13 (GMT) |
commit | c7590ca38eb81dccfffa8e7132e0d1df0734cf44 (patch) | |
tree | e99ca501ec34b6303b5f85a5ecc77e9a476fb3c2 /tools/h5dump | |
parent | 4978a681f9a98016a829b8353fafb0acb5cdf1d4 (diff) | |
download | hdf5-c7590ca38eb81dccfffa8e7132e0d1df0734cf44.zip hdf5-c7590ca38eb81dccfffa8e7132e0d1df0734cf44.tar.gz hdf5-c7590ca38eb81dccfffa8e7132e0d1df0734cf44.tar.bz2 |
[svn-r17450] Bring h5dump single subsetting selection and region reference changes from NPOESS
Tested: local linux smirom
Diffstat (limited to 'tools/h5dump')
-rw-r--r-- | tools/h5dump/h5dump.c | 203 | ||||
-rw-r--r-- | tools/h5dump/h5dumpgentest.c | 122 |
2 files changed, 231 insertions, 94 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index beacdbb..c74c9f1 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -81,7 +81,6 @@ static const char *fp_format = NULL; const char *outfname=NULL; - /* things to display or which are set via command line parameters */ static int display_all = TRUE; static int display_oid = FALSE; @@ -94,6 +93,7 @@ static int display_dcpl = FALSE; /*dcpl */ static int display_fi = FALSE; /*file index */ static int display_ai = TRUE; /*array index */ static int display_escape = FALSE; /*escape non printable characters */ +static int display_region = FALSE; /*print region reference data */ /* sort parameters */ static H5_index_t sort_by = H5_INDEX_NAME; /*sort_by [creation_order | name] */ @@ -388,7 +388,7 @@ struct handler_t { * parameters. The long-named ones can be partially spelled. When * adding more, make sure that they don't clash with each other. */ -static const char *s_opts = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:b*F:s:S:Aq:z:m:"; +static const char *s_opts = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:b*F:s:S:Aq:z:m:R"; static struct long_options l_opts[] = { { "help", no_arg, 'h' }, { "hel", no_arg, 'h' }, @@ -500,6 +500,7 @@ static struct long_options l_opts[] = { { "sort_by", require_arg, 'q' }, { "sort_order", require_arg, 'z' }, { "format", require_arg, 'm' }, + { "region", no_arg, 'R' }, { NULL, 0, '\0' } }; @@ -655,6 +656,7 @@ usage(const char *prog) fprintf(stdout, " -m T, --format=T Set the floating point output format\n"); fprintf(stdout, " -q Q, --sort_by=Q Sort groups and attributes by index Q\n"); fprintf(stdout, " -z Z, --sort_order=Z Sort groups and attributes by order Z\n"); + fprintf(stdout, " -R, --region Print dataset pointed by region references\n"); fprintf(stdout, " -x, --xml Output in XML using Schema\n"); fprintf(stdout, " -u, --use-dtd Output in XML using DTD\n"); fprintf(stdout, " -D U, --xml-dtd=U Use the DTD or schema at U\n"); @@ -665,14 +667,16 @@ usage(const char *prog) fprintf(stdout, " Subsetting is available by using the following options with a dataset\n"); fprintf(stdout, " attribute. Subsetting is done by selecting a hyperslab from the data.\n"); fprintf(stdout, " Thus, the options mirror those for performing a hyperslab selection.\n"); - fprintf(stdout, " The START and COUNT parameters are mandatory if you do subsetting.\n"); - fprintf(stdout, " The STRIDE and BLOCK parameters are optional and will default to 1 in\n"); - fprintf(stdout, " each dimension.\n"); + fprintf(stdout, " One of the START, COUNT, STRIDE, or BLOCK parameters are mandatory if you do subsetting.\n"); + fprintf(stdout, " The STRIDE, COUNT, and BLOCK parameters are optional and will default to 1 in\n"); + fprintf(stdout, " each dimension. START is optional and will default to 0 in each dimension.\n"); fprintf(stdout, "\n"); - fprintf(stdout, " -s L, --start=L Offset of start of subsetting selection\n"); - fprintf(stdout, " -S L, --stride=L Hyperslab stride\n"); - fprintf(stdout, " -c L, --count=L Number of blocks to include in selection\n"); - fprintf(stdout, " -k L, --block=L Size of block in hyperslab\n"); + fprintf(stdout, " -s START, --start=START Offset of start of subsetting selection\n"); + fprintf(stdout, " -S STRIDE, --stride=STRIDE Hyperslab stride\n"); + fprintf(stdout, " -c COUNT, --count=COUNT Number of blocks to include in selection\n"); + fprintf(stdout, " -k BLOCK, --block=BLOCK Size of block in hyperslab\n"); + fprintf(stdout, " START, COUNT, STRIDE, and BLOCK - is a list of integers the number of which are equal to the\n"); + fprintf(stdout, " number of dimensions in the dataspace being queried\n"); fprintf(stdout, "\n"); fprintf(stdout, " D - is the file driver to use in opening the file. Acceptable values\n"); fprintf(stdout, " are \"sec2\", \"family\", \"split\", \"multi\", \"direct\", and \"stream\". Without\n"); @@ -683,8 +687,6 @@ usage(const char *prog) fprintf(stdout, " P - is the full path from the root group to the object.\n"); fprintf(stdout, " N - is an integer greater than 1.\n"); fprintf(stdout, " T - is a string containing the floating point format, e.g '%%.3f'\n"); - fprintf(stdout, " L - is a list of integers the number of which are equal to the\n"); - fprintf(stdout, " number of dimensions in the dataspace being queried\n"); fprintf(stdout, " U - is a URI reference (as defined in [IETF RFC 2396],\n"); fprintf(stdout, " updated by [IETF RFC 2732])\n"); fprintf(stdout, " B - is the form of binary output: NATIVE for a memory type, FILE for the\n"); @@ -1189,6 +1191,18 @@ print_datatype(hid_t type,unsigned in_group) case H5T_REFERENCE: printf("H5T_REFERENCE"); + /* The BNF document states that the type of reference should be + * displayed after "H5T_REFERENCE". Therefore add the missing + * reference type if the region command line option is used. This + * reference type will not be displayed if the region option is not used. */ + if(display_region) { + if (H5Tequal(type, H5T_STD_REF_DSETREG)==TRUE) { + printf(" { H5T_STD_REF_DSETREG }"); + } + else { + printf(" { H5T_STD_REF_OBJECT }"); + } + } break; case H5T_ENUM: @@ -2391,13 +2405,29 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index) outputformat->pindex=display_index; /* do not print indices for regions */ - if(obj_data == DATASET_DATA) - { + if(obj_data == DATASET_DATA) { hid_t f_type = H5Dget_type(obj_id); - if (H5Tequal(f_type, H5T_STD_REF_DSETREG)) - { - outputformat->pindex = 0; + if (H5Tequal(f_type, H5T_STD_REF_DSETREG)) { + /* For the region option, correct the display of indices */ + if (display_region) { + if (display_index) { + outputformat->pindex = 1; + outputformat->idx_fmt = "(%s): "; + outputformat->idx_n_fmt = HSIZE_T_FORMAT; + outputformat->idx_sep = ","; + outputformat->line_pre = "%s"; + } + else { + outputformat->pindex = 0; + outputformat->idx_fmt = ""; + outputformat->idx_n_fmt = ""; + outputformat->idx_sep = ""; + outputformat->line_pre = ""; + } + } + else + outputformat->pindex = 0; } H5Tclose(f_type); } @@ -2470,13 +2500,15 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index) status = h5tools_dump_dset(stdout, outputformat, obj_id, -1, sset, depth); H5Tclose(f_type); - } else { + } + else { /* need to call h5tools_dump_mem for the attribute data */ space = H5Aget_space(obj_id); space_type = H5Sget_simple_extent_type(space); if(space_type == H5S_NULL || space_type == H5S_NO_CLASS) { status = SUCCEED; - } else { + } + else { char string_prefix[64]; h5tool_format_t string_dataformat; @@ -3516,21 +3548,13 @@ handle_datasets(hid_t fid, const char *dset, void *data, int pe, const char *dis } if (!sset->count) { - hsize_t dims[H5S_MAX_RANK]; - herr_t status = H5Sget_simple_extent_dims(sid, dims, NULL); unsigned int i; - if (status == FAIL) { - error_msg(progname, "unable to get dataset dimensions\n"); - d_status = EXIT_FAILURE; - H5Sclose(sid); - return; - } sset->count = calloc(ndims, sizeof(hsize_t)); for (i = 0; i < ndims; i++) - sset->count[i] = dims[i] - sset->start[i]; + sset->count[i] = 1; } if (!sset->block) { @@ -3872,6 +3896,10 @@ parse_command_line(int argc, const char *argv[]) while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { parse_start: switch ((char)opt) { + case 'R': + display_region = TRUE; + region_output = TRUE; + break; case 'B': display_bb = TRUE; last_was_dset = FALSE; @@ -3981,74 +4009,61 @@ parse_start: break; case 'o': + if ( bin_output ) { + if (set_output_file(opt_arg, 1) < 0) { + usage(progname); + leave(EXIT_FAILURE); + } + } + else { + if (set_output_file(opt_arg, 0) < 0) { + usage(progname); + leave(EXIT_FAILURE); + } + } + + usingdasho = TRUE; + last_was_dset = FALSE; + outfname = opt_arg; + break; + + case 'b': + if ( opt_arg != NULL) { + if ( ( bin_form = set_binary_form(opt_arg)) < 0) { + /* failed to set binary form */ + usage(progname); + leave(EXIT_FAILURE); + } + } + bin_output = TRUE; + if (outfname!=NULL) { + if (set_output_file(outfname, 1) < 0) { + /* failed to set output file */ + usage(progname); + leave(EXIT_FAILURE); + } + + last_was_dset = FALSE; + } + break; - if ( bin_output ) - { - if (set_output_file(opt_arg, 1) < 0){ - usage(progname); - leave(EXIT_FAILURE); - } - } - else - { - if (set_output_file(opt_arg, 0) < 0){ - usage(progname); - leave(EXIT_FAILURE); - } - } - - usingdasho = TRUE; - last_was_dset = FALSE; - outfname = opt_arg; - break; - - case 'b': - - if ( opt_arg != NULL) - { - if ( ( bin_form = set_binary_form(opt_arg)) < 0) - { - /* failed to set binary form */ - usage(progname); - leave(EXIT_FAILURE); - } - } - bin_output = TRUE; - if (outfname!=NULL) - { - if (set_output_file(outfname, 1) < 0) - { - /* failed to set output file */ - usage(progname); - leave(EXIT_FAILURE); - } - - last_was_dset = FALSE; - } - - break; - - case 'q': - - if ( ( sort_by = set_sort_by(opt_arg)) < 0) - { - /* failed to set "sort by" form */ - usage(progname); - leave(EXIT_FAILURE); - } - - break; - - case 'z': - - if ( ( sort_order = set_sort_order(opt_arg)) < 0) - { - /* failed to set "sort order" form */ - usage(progname); - leave(EXIT_FAILURE); - } - - break; + case 'q': + if ( ( sort_by = set_sort_by(opt_arg)) < 0) { + /* failed to set "sort by" form */ + usage(progname); + leave(EXIT_FAILURE); + } + break; + + case 'z': + if ( ( sort_order = set_sort_order(opt_arg)) < 0) { + /* failed to set "sort order" form */ + usage(progname); + leave(EXIT_FAILURE); + } + break; + + break; /** begin XML parameters **/ case 'x': diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index c0d5801..77988f0 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -92,6 +92,7 @@ #define FILE62 "textlinktar.h5" #define FILE63 "textlinkfar.h5" #define FILE64 "tarray8.h5" +#define FILE65 "tattrreg.h5" @@ -1852,6 +1853,126 @@ static void gent_datareg(void) free(drbuf); } +static void gent_attrreg(void) +{ + /*some code is taken from enum.c in the test dir */ + + hid_t fid1; /* HDF5 File IDs */ + hid_t dset1; /* Dataset ID */ + hid_t dset2; /* Dereferenced dataset ID */ + hid_t sid1; /* Dataspace ID #1 */ + hid_t sid2; /* Dataspace ID #2 */ + hid_t sid3; /* Dataspace ID #3 */ + hid_t attr1; /* Attribute ID */ + hsize_t dims1[] = {SPACE1_DIM1}; + hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + hsize_t coord1[POINT1_NPOINTS][SPACE2_RANK]; /* Coordinates for point selection */ + hdset_reg_ref_t *wbuf; /* buffer to write to disk */ + hdset_reg_ref_t *rbuf; /* buffer read from disk */ + uint8_t *dwbuf; /* Buffer for writing numeric data to disk */ + uint8_t *drbuf; /* Buffer for reading numeric data from disk */ + uint8_t *tu8; /* Temporary pointer to uint8 data */ + 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); + + /* Create file */ + fid1 = H5Fcreate(FILE65, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + /* Create dataspace for datasets */ + sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL); + + /* Create a dataset */ + dset2 = H5Dcreate2(fid1, "Dataset2", H5T_STD_U8BE, sid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + + for(tu8 = dwbuf, i = 0; i < SPACE2_DIM1 * SPACE2_DIM2; i++) + *tu8++=i*3; + + /* Write selection to disk */ + H5Dwrite(dset2, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, dwbuf); + + /* Close Dataset */ + H5Dclose(dset2); + + /* + * Create dataset with a null dataspace to serve as the parent for + * the attribute. + */ + sid1 = H5Screate (H5S_NULL); + dset1 = H5Dcreate (fid1, "Dataset1", H5T_STD_I32LE, sid1, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT); + H5Sclose (sid1); + + /* Create references */ + + /* Select 6x6 hyperslab for first reference */ + start[0] = 2; start[1] = 2; + stride[0] = 1; stride[1] = 1; + count[0] = 6; count[1] = 6; + block[0] = 1; block[1] = 1; + H5Sselect_hyperslab(sid2, H5S_SELECT_SET, start, stride, count, block); + + H5Sget_select_npoints(sid2); + + /* Store first dataset region */ + H5Rcreate(&wbuf[0], fid1, "/Dataset2", H5R_DATASET_REGION, sid2); + + /* Select sequence of ten points for second reference */ + coord1[0][0]=6; coord1[0][1]=9; + coord1[1][0]=2; coord1[1][1]=2; + coord1[2][0]=8; coord1[2][1]=4; + coord1[3][0]=1; coord1[3][1]=6; + coord1[4][0]=2; coord1[4][1]=8; + coord1[5][0]=3; coord1[5][1]=2; + coord1[6][0]=0; coord1[6][1]=4; + coord1[7][0]=9; coord1[7][1]=0; + coord1[8][0]=7; coord1[8][1]=1; + coord1[9][0]=3; coord1[9][1]=3; + H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(hsize_t *)coord1); + + H5Sget_select_npoints(sid2); + + /* Store second dataset region */ + H5Rcreate(&wbuf[1],fid1,"/Dataset2",H5R_DATASET_REGION,sid2); + + /* Create dataspace for the attribute */ + sid3 = H5Screate_simple(SPACE1_RANK, dims1, NULL); + + /* Create the attribute and write the region references to it. */ + attr1 = H5Acreate (dset1, "Attribute1", H5T_STD_REF_DSETREG, sid3, H5P_DEFAULT, + H5P_DEFAULT); + H5Awrite (attr1, H5T_STD_REF_DSETREG, wbuf); + + /* Close attribute dataspace */ + H5Sclose(sid3); + + /* Close attribute */ + H5Aclose (attr1); + + /* Close Dataset */ + H5Dclose(dset1); + + /* Close uint8 dataset dataspace */ + H5Sclose(sid2); + + /* Close file */ + H5Fclose(fid1); + + /* Free memory buffers */ + free(wbuf); + free(rbuf); + free(dwbuf); + free(drbuf); +} + /*taken from Elena's compound test file*/ static void gent_nestcomp(void) { @@ -6351,6 +6472,7 @@ int main(void) gent_enum(); gent_objref(); gent_datareg(); + gent_attrreg(); gent_nestcomp(); gent_opaque(); gent_bitfields(); |