diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2008-05-06 20:08:11 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2008-05-06 20:08:11 (GMT) |
commit | eb9ba954a5ed7200cc3d3c165c1ce630576c2a75 (patch) | |
tree | 541e05b8947a7415e06d32c29d643c8952f0fb06 /tools/h5dump | |
parent | 41bf2001b12eb45be944d44dd99b56a5a15bfb92 (diff) | |
download | hdf5-eb9ba954a5ed7200cc3d3c165c1ce630576c2a75.zip hdf5-eb9ba954a5ed7200cc3d3c165c1ce630576c2a75.tar.gz hdf5-eb9ba954a5ed7200cc3d3c165c1ce630576c2a75.tar.bz2 |
[svn-r14948] Add a test for the floating point user defined printf format
Usage is
-m T, --format=T
Where T - is a string containing the floating point format, e.g '%.3f'
The test consists of writing a number with 7 fractional digits (default precision display of %f is 6 digits) and have the 7 digits displayed with
-m %.7f fpformat.h5
Tested: windows, linux, solaris
Note: the output file was generated in linux, it may be possible that platforms other than the ones tested have a different representation of the number
Diffstat (limited to 'tools/h5dump')
-rw-r--r-- | tools/h5dump/h5dump.c | 22 | ||||
-rw-r--r-- | tools/h5dump/h5dumpgentest.c | 46 | ||||
-rw-r--r-- | tools/h5dump/testh5dump.sh.in | 3 |
3 files changed, 69 insertions, 2 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 70d845d..9802ad0 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -62,6 +62,8 @@ static size_t prefix_len = 1024; static char *prefix; static const char *driver = NULL; /* The driver to open the file with. */ static const h5dump_header_t *dump_header_format; +static const char *fp_format = NULL; + /* things to display or which are set via command line parameters */ static int display_all = TRUE; @@ -367,7 +369,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:"; +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 struct long_options l_opts[] = { { "help", no_arg, 'h' }, { "hel", no_arg, 'h' }, @@ -478,6 +480,7 @@ static struct long_options l_opts[] = { { "form", require_arg, 'F' }, { "sort_by", require_arg, 'q' }, { "sort_order", require_arg, 'z' }, + { "format", require_arg, 'm' }, { NULL, 0, '\0' } }; @@ -628,6 +631,7 @@ usage(const char *prog) fprintf(stdout, " -b B, --binary=B Binary file output, of form B\n"); fprintf(stdout, " -t P, --datatype=P Print the specified named datatype\n"); fprintf(stdout, " -w N, --width=N Set the number of columns of output\n"); + 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, " -x, --xml Output in XML using Schema\n"); @@ -657,6 +661,7 @@ usage(const char *prog) fprintf(stdout, " F - is a filename.\n"); 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"); @@ -2189,6 +2194,12 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index) int depth; int stdindent = COL; /* should be 3 */ + if (fp_format) + { + outputformat->fmt_double = fp_format; + outputformat->fmt_float = fp_format; + } + outputformat->line_ncols = nCols; outputformat->do_escape=display_escape; /* print the matrix indices */ @@ -3819,6 +3830,15 @@ parse_start: /* To Do: check format of this value? */ xml_dtd_uri = opt_arg; break; + + case 'm': + /* specify alternative floating point printing format */ + fp_format = opt_arg; + break; + + + + case 'X': /* specify XML namespace (default="hdf5:"), or none */ /* To Do: check format of this value? */ diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index 4070425..270f2ee 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -87,6 +87,8 @@ #define FILE57 "thyperslab.h5" #define FILE58 "tordergr.h5" #define FILE59 "torderattr.h5" +#define FILE60 "tfpformat.h5" + /*------------------------------------------------------------------------- @@ -6128,6 +6130,49 @@ out: } +/*------------------------------------------------------------------------- + * Function: gent_fpformat + * + * Purpose: Generate a file to be used in the floating point format test + * Contains: + * 1) a float dataset + * 2) a double dataset + * + *------------------------------------------------------------------------- + */ +static void +gent_fpformat(void) +{ + hid_t fid, sid, did; + hsize_t dims[1] = {6}; + double dbuf[6] = {-0.1234567, 0.1234567, 0, 0, 0, 0}; + float fbuf[6] = {-0.1234567f, 0.1234567f, 0, 0, 0, 0}; + + fid = H5Fcreate(FILE60, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + sid = H5Screate_simple(1, dims, NULL); + +/*------------------------------------------------------------------------- + * double + *------------------------------------------------------------------------- + */ + did = H5Dcreate2(fid, "double", H5T_NATIVE_DOUBLE, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5Dwrite(did, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dbuf); + H5Dclose(did); + + +/*------------------------------------------------------------------------- + * float + *------------------------------------------------------------------------- + */ + did = H5Dcreate2(fid, "float", H5T_NATIVE_FLOAT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5Dwrite(did, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, fbuf); + H5Dclose(did); + + + /* close */ + H5Sclose(sid); + H5Fclose(fid); +} /*------------------------------------------------------------------------- * Function: main @@ -6196,6 +6241,7 @@ int main(void) gent_hyperslab(); gent_group_creation_order(); gent_attr_creation_order(); + gent_fpformat(); return 0; diff --git a/tools/h5dump/testh5dump.sh.in b/tools/h5dump/testh5dump.sh.in index b7b8429..df5c40d 100644 --- a/tools/h5dump/testh5dump.sh.in +++ b/tools/h5dump/testh5dump.sh.in @@ -496,7 +496,8 @@ TOOLTEST torderattr2.ddl -H --sort_by=name --sort_order=descending torderattr.h5 TOOLTEST torderattr3.ddl -H --sort_by=creation_order --sort_order=ascending torderattr.h5 TOOLTEST torderattr4.ddl -H --sort_by=creation_order --sort_order=descending torderattr.h5 - +# tests for floating point user defined printf format +TOOLTEST tfpformat.ddl -m %.7f tfpformat.h5 if test $nerrors -eq 0 ; then echo "All $DUMPER tests passed." |