Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add long double format option to h5dump #5025

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hl/tools/h5watch/h5watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ doprint(hid_t did, const hsize_t *start, const hsize_t *block, int rank)
{
h5tools_context_t ctx; /* print context */
h5tool_format_t info; /* Format info for the tools library */
static char fmt_ldouble[16]; /* Format info */
static char fmt_double[16], fmt_float[16]; /* Format info */
struct subset_t subset; /* Subsetting info */
hsize_t ss_start[H5S_MAX_RANK]; /* Info for hyperslab */
Expand Down Expand Up @@ -175,6 +176,8 @@ doprint(hid_t did, const hsize_t *start, const hsize_t *block, int rank)
info.fmt_float = fmt_float;
snprintf(fmt_double, sizeof(fmt_double), "%%1.%dg", DBL_DIG);
info.fmt_double = fmt_double;
snprintf(fmt_ldouble, sizeof(fmt_ldouble), "%%1.%dLg", DBL_DIG);
info.fmt_ldouble = fmt_ldouble;

info.dset_format = "DSET-%s ";
info.dset_hidefileno = 0;
Expand Down
7 changes: 7 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ New Features

Tools:
------
- Added h5dump command option to set the floating point format for long double

The new option is --lformat, which allows the user to set the
floating point format for long double. The default format is %Lg.
There is already an option --format to set the floating point format
for double and float. The default format is %g.

- Remove the high-level GIF tools

The high-level GIF tools, h52gif and gif2h5, have unfixed CVE issues
Expand Down
4 changes: 4 additions & 0 deletions tools/lib/h5tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ typedef struct h5tool_format_t {
* typed `unsigned long long'. The default depends on what
* printf() format is available to print this datatype.
*
* fmt_ldouble: The printf() format to use when rendering data which is
* typed `long double'. The default is `%Lg'.
*
* fmt_double: The printf() format to use when rendering data which is
* typed `double'. The default is `%g'.
*
Expand Down Expand Up @@ -303,6 +306,7 @@ typedef struct h5tool_format_t {
const char *fmt_ulong;
const char *fmt_llong;
const char *fmt_ullong;
const char *fmt_ldouble;
const char *fmt_double;
const char *fmt_float;
int ascii;
Expand Down
1 change: 1 addition & 0 deletions tools/lib/h5tools_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ h5tool_format_t h5tools_dataformat = {
"%lu", /*fmt_ulong */
NULL, /*fmt_llong */
NULL, /*fmt_ullong */
"%Lg", /*fmt_ldouble */
"%g", /*fmt_double */
"%g", /*fmt_float */

Expand Down
2 changes: 1 addition & 1 deletion tools/lib/h5tools_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
long double templdouble;

memcpy(&templdouble, vp, sizeof(long double));
h5tools_str_append(str, "%Lg", templdouble);
h5tools_str_append(str, OPT(info->fmt_ldouble, "%Lg"), templdouble);
}
else {
size_t i;
Expand Down
15 changes: 13 additions & 2 deletions tools/src/h5dump/h5dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct handler_t {
*/
/* The following initialization makes use of C language concatenating */
/* "xxx" "yyy" into "xxxyyy". */
static const char *s_opts = "a:b*c:d:ef:g:hik:l:m:n*o*pq:rs:t:uvw:xyz:A*BCD:E*F:G:HK:M:N:O*RS:VX:";
static const char *s_opts = "a:b*c:d:ef:g:hik:l:m:n*o*pq:rs:t:uvw:xyz:A*BCD:E*F:G:HK:L:M:N:O*RS:VX:";
static struct h5_long_options l_opts[] = {{"attribute", require_arg, 'a'},
{"binary", optional_arg, 'b'},
{"count", require_arg, 'c'},
Expand Down Expand Up @@ -134,6 +134,7 @@ static struct h5_long_options l_opts[] = {{"attribute", require_arg, 'a'},
{"vds-gap-size", require_arg, 'G'},
{"header", no_arg, 'H'},
{"page-buffer-size", require_arg, 'K'},
{"lformat", require_arg, 'L'},
{"packed-bits", require_arg, 'M'},
{"any_path", require_arg, 'N'},
{"ddl", optional_arg, 'O'},
Expand Down Expand Up @@ -285,6 +286,8 @@ usage(const char *prog)
PRINTVALSTREAM(rawoutstream, " -r, --string Print 1-byte integer datasets as ASCII\n");
PRINTVALSTREAM(rawoutstream, " -y, --noindex Do not print array indices with the data\n");
PRINTVALSTREAM(rawoutstream, " -m T, --format=T Set the floating point output format\n");
PRINTVALSTREAM(rawoutstream,
" -L T, --lformat=T Set the floating point long double output format\n");
PRINTVALSTREAM(rawoutstream, " -q Q, --sort_by=Q Sort groups and attributes by index Q\n");
PRINTVALSTREAM(rawoutstream, " -z Z, --sort_order=Z Sort groups and attributes by order Z\n");
PRINTVALSTREAM(rawoutstream,
Expand Down Expand Up @@ -346,7 +349,9 @@ usage(const char *prog)
PRINTVALSTREAM(rawoutstream, " F - is a filename.\n");
PRINTVALSTREAM(rawoutstream, " P - is the full path from the root group to the object.\n");
PRINTVALSTREAM(rawoutstream, " N - is an integer greater than 1.\n");
PRINTVALSTREAM(rawoutstream, " T - is a string containing the floating point format, e.g '%%.3f'\n");
PRINTVALSTREAM(rawoutstream, " T - is a string containing the floating point format, e.g '%%.3g'\n");
PRINTVALSTREAM(rawoutstream,
" T - is a string containing the floating point long double format, e.g '%%.3Lg'\n");
PRINTVALSTREAM(rawoutstream, " U - is a URI reference (as defined in [IETF RFC 2396],\n");
PRINTVALSTREAM(rawoutstream, " updated by [IETF RFC 2732])\n");
PRINTVALSTREAM(rawoutstream,
Expand Down Expand Up @@ -1056,6 +1061,12 @@ parse_command_line(int argc, const char *const *argv)
h5tools_nCols = 0;
break;

case 'L':
/* specify alternative floating point long double printing format */
fp_lformat = H5_optarg;
h5tools_nCols = 0;
break;

case 'X':
/* specify XML namespace (default="hdf5:"), or none */
/* To Do: check format of this value? */
Expand Down
5 changes: 4 additions & 1 deletion tools/src/h5dump/h5dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
* \li <strong>--string</strong> Print 1-byte integer datasets as ASCII
* \li <strong>--noindex</strong> Do not print array indices with the data
* \li <strong>--format=T</strong> Set the floating point output format
* \li <strong>--lformat=T</strong> Set the floating point long double output format
* \li <strong>--sort_by=Q</strong> Sort groups and attributes by index Q
* \li <strong>--sort_order=Z</strong> Sort groups and attributes by order Z
* \li <strong>--no-compact-subset</strong> Disable compact form of subsetting and allow the use
Expand Down Expand Up @@ -143,7 +144,8 @@
* \li <strong>F</strong> - is a filename.
* \li <strong>P</strong> - is the full path from the root group to the object.
* \li <strong>N</strong> - is an integer greater than 1.
* \li <strong>T</strong> - is a string containing the floating point format, e.g '%.3f'
* \li <strong>T</strong> - is a string containing the floating point format, e.g '%.3g'
* \li <strong>T</strong> - is a string containing the floating point long double format, e.g '%.3Lg'
* \li <strong>U</strong> - is a URI reference (as defined in [IETF RFC 2396],
* updated by [IETF RFC 2732])
* \li <strong>B</strong> - is the form of binary output: NATIVE for a memory type, FILE for the
Expand Down Expand Up @@ -239,6 +241,7 @@ bool hit_elink = false; /* whether we have traversed an external link *
size_t prefix_len = 1024;
char *prefix = NULL;
const char *fp_format = NULL;
const char *fp_lformat = NULL;

/* things to display or which are set via command line parameters */
typedef struct {
Expand Down
21 changes: 21 additions & 0 deletions tools/src/h5dump/h5dump_ddl.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ dump_attr_cb(hid_t oid, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -175,6 +178,9 @@ dump_all_cb(hid_t group, const char *name, const H5L_info2_t *linfo, void H5_ATT
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -646,6 +652,9 @@ dump_named_datatype(hid_t tid, const char *name)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -802,6 +811,9 @@ dump_group(hid_t gid, const char *name)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -928,6 +940,9 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -1098,6 +1113,9 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -1563,6 +1581,9 @@ handle_attributes(hid_t fid, const char *attr, void H5_ATTR_UNUSED *data, int H5
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down
1 change: 1 addition & 0 deletions tools/src/h5dump/h5dump_extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern bool hit_elink; /* whether we have traversed an external link */
extern size_t prefix_len;
extern char *prefix;
extern const char *fp_format;
extern const char *fp_lformat;

/* things to display or which are set via command line parameters */
typedef struct {
Expand Down
43 changes: 43 additions & 0 deletions tools/src/h5dump/h5dump_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static h5tool_format_t xml_dataformat = {
"%lu", /*fmt_ulong */
NULL, /*fmt_llong */
NULL, /*fmt_ullong */
"%Lg", /*fmt_ldouble */
"%g", /*fmt_double */
"%g", /*fmt_float */

Expand Down Expand Up @@ -152,6 +153,9 @@ xml_dump_all_cb(hid_t group, const char *name, const H5L_info2_t *linfo, void H5
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -885,6 +889,9 @@ xml_print_datatype(hid_t type, unsigned in_group)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -1582,6 +1589,9 @@ xml_dump_datatype(hid_t type)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -1716,6 +1726,9 @@ xml_dump_dataspace(hid_t space)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -1889,6 +1902,9 @@ xml_dump_data(hid_t obj_id, int obj_data, struct subset_t H5_ATTR_UNUSED *sset,
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -2056,6 +2072,9 @@ xml_dump_attr(hid_t attr, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -2387,6 +2406,9 @@ xml_dump_named_datatype(hid_t type, const char *name)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -2606,6 +2628,9 @@ xml_dump_group(hid_t gid, const char *name)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -3010,6 +3035,9 @@ xml_print_refs(hid_t did, int source)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -3166,6 +3194,9 @@ xml_print_strs(hid_t did, int source)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -3281,6 +3312,9 @@ check_filters(hid_t dcpl)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -3422,6 +3456,9 @@ xml_dump_fill_value(hid_t dcpl, hid_t type)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -3803,6 +3840,9 @@ xml_dump_dataset(hid_t did, const char *name, struct subset_t H5_ATTR_UNUSED *ss
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -4390,6 +4430,9 @@ xml_print_enum(hid_t type)
string_dataformat.fmt_double = fp_format;
string_dataformat.fmt_float = fp_format;
}
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down
Loading
Loading