From eb9ba954a5ed7200cc3d3c165c1ce630576c2a75 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Tue, 6 May 2008 15:08:11 -0500 Subject: [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 --- MANIFEST | 2 ++ release_docs/RELEASE.txt | 3 +++ tools/h5dump/h5dump.c | 22 ++++++++++++++++++- tools/h5dump/h5dumpgentest.c | 46 ++++++++++++++++++++++++++++++++++++++++ tools/h5dump/testh5dump.sh.in | 3 ++- tools/testfiles/tfpformat.ddl | 21 ++++++++++++++++++ tools/testfiles/tfpformat.h5 | Bin 0 -> 2120 bytes tools/testfiles/tnofilename.ddl | 2 ++ 8 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 tools/testfiles/tfpformat.ddl create mode 100644 tools/testfiles/tfpformat.h5 diff --git a/MANIFEST b/MANIFEST index fa2ce42..1116b73 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1239,6 +1239,8 @@ ./tools/testfiles/torderattr3.ddl ./tools/testfiles/torderattr4.ddl ./tools/testfiles/torderattr.h5 +./tools/testfiles/tfpformat.ddl +./tools/testfiles/tfpformat.h5 diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 95d47c9..2c72503 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -71,6 +71,9 @@ New Features ----- - h5dump: add a printing of the compression ratio of uncompressed and compressed sizes for cases where compression filters are present. (PVN - 2008/05/01) + - h5dump: added an option to allow a user defined formatting string for printf + regarding floating point numbers. (PVN - 2008/05/06) + F90 API 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." diff --git a/tools/testfiles/tfpformat.ddl b/tools/testfiles/tfpformat.ddl new file mode 100644 index 0000000..2336822 --- /dev/null +++ b/tools/testfiles/tfpformat.ddl @@ -0,0 +1,21 @@ +############################# +Expected output for 'h5dump -m %.7f tfpformat.h5' +############################# +HDF5 "tfpformat.h5" { +GROUP "/" { + DATASET "double" { + DATATYPE H5T_IEEE_F64LE + DATASPACE SIMPLE { ( 6 ) / ( 6 ) } + DATA { + (0): -0.1234567, 0.1234567, 0.0000000, 0.0000000, 0.0000000, 0.0000000 + } + } + DATASET "float" { + DATATYPE H5T_IEEE_F32LE + DATASPACE SIMPLE { ( 6 ) / ( 6 ) } + DATA { + (0): -0.1234567, 0.1234567, 0.0000000, 0.0000000, 0.0000000, 0.0000000 + } + } +} +} diff --git a/tools/testfiles/tfpformat.h5 b/tools/testfiles/tfpformat.h5 new file mode 100644 index 0000000..4b7cb00 Binary files /dev/null and b/tools/testfiles/tfpformat.h5 differ diff --git a/tools/testfiles/tnofilename.ddl b/tools/testfiles/tnofilename.ddl index b7b802b..756b88f 100644 --- a/tools/testfiles/tnofilename.ddl +++ b/tools/testfiles/tnofilename.ddl @@ -23,6 +23,7 @@ usage: h5dump [OPTIONS] file -b B, --binary=B Binary file output, of form B -t P, --datatype=P Print the specified named datatype -w N, --width=N Set the number of columns of output + -m T, --format=T Set the floating point output format -q Q, --sort_by=Q Sort groups and attributes by index Q -z Z, --sort_order=Z Sort groups and attributes by order Z -x, --xml Output in XML using Schema @@ -52,6 +53,7 @@ usage: h5dump [OPTIONS] file F - is a filename. P - is the full path from the root group to the object. N - is an integer greater than 1. + T - is a string containing the floating point format, e.g '%.3f' L - is a list of integers the number of which are equal to the number of dimensions in the dataspace being queried U - is a URI reference (as defined in [IETF RFC 2396], -- cgit v0.12