summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2008-05-05 20:06:22 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2008-05-05 20:06:22 (GMT)
commit26d880217ba085053abb0e26be737b6eb35e6c96 (patch)
treea08dcbd55bfcb18cb46152e1d99527e66f2fc312
parent5bd2405c11837865b6d7c54e30933dbc0b43c938 (diff)
downloadhdf5-26d880217ba085053abb0e26be737b6eb35e6c96.zip
hdf5-26d880217ba085053abb0e26be737b6eb35e6c96.tar.gz
hdf5-26d880217ba085053abb0e26be737b6eb35e6c96.tar.bz2
[svn-r14934] 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
-rw-r--r--tools/h5dump/h5dump.c18
-rw-r--r--tools/h5dump/h5dumpgentest.c51
-rw-r--r--tools/h5dump/testh5dump.sh.in4
-rw-r--r--tools/testfiles/tfpformat.ddl21
-rw-r--r--tools/testfiles/tfpformat.h5bin0 -> 2120 bytes
-rw-r--r--tools/testfiles/tnofilename.ddl2
6 files changed, 93 insertions, 3 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 694c634..365f88f 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -62,6 +62,7 @@ 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 +368,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 +479,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 +630,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 +660,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 +2193,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 */
@@ -3821,6 +3831,12 @@ 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..54b22df 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"
+
/*-------------------------------------------------------------------------
@@ -5542,14 +5544,14 @@ error:
* Contains:
* 1) an integer dataset
* 2) a float dataset
- * 4) a double dataset
+ * 3) a double dataset
*
*-------------------------------------------------------------------------
*/
static void
gent_binary(void)
{
- hid_t fid, sid, did, tid;
+ hid_t fid, sid, did;
hsize_t dims[1] = {6};
int ibuf[6] = {1,2,3,4,5,6};
float fbuf[6] = {1,2,3,4,5,6};
@@ -6128,6 +6130,50 @@ out:
}
+/*-------------------------------------------------------------------------
+ * Function: gent_fpformat
+ *
+ * Purpose: Generate a file to be used in the floating point format test
+ * Contains:
+ * 2) a float dataset
+ * 4) 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 +6242,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 1a8c18a..034c456 100644
--- a/tools/h5dump/testh5dump.sh.in
+++ b/tools/h5dump/testh5dump.sh.in
@@ -496,6 +496,10 @@ TOOLTEST torderattr3.ddl -H --sort_by=creation_order --sort_order=ascending tord
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..5f78930
--- /dev/null
+++ b/tools/testfiles/tfpformat.h5
Binary files differ
diff --git a/tools/testfiles/tnofilename.ddl b/tools/testfiles/tnofilename.ddl
index b7b802b..4b6e13a 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 '0.000'
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],