summaryrefslogtreecommitdiffstats
path: root/tools/h5dump/h5dump.c
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 /tools/h5dump/h5dump.c
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
Diffstat (limited to 'tools/h5dump/h5dump.c')
-rw-r--r--tools/h5dump/h5dump.c18
1 files changed, 17 insertions, 1 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? */