Skip to content

Commit

Permalink
Add long double format option to h5dump (HDFGroup#5025)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnHDF authored and brtnfld committed Nov 4, 2024
1 parent 05d22c0 commit d3cfa11
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 182 deletions.
34 changes: 12 additions & 22 deletions hl/tools/h5watch/h5watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,17 @@ static struct h5_long_options l_opts[] = {{"help", no_arg, 'h'}, {"hel",
static herr_t
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]; /* Format info */
static char fmt_float[16]; /* Format info */
static char fmt_ldouble_complex[32]; /* Format info */
static char fmt_double_complex[32]; /* Format info */
static char fmt_float_complex[16]; /* Format info */
struct subset_t subset; /* Subsetting info */
hsize_t ss_start[H5S_MAX_RANK]; /* Info for hyperslab */
hsize_t ss_stride[H5S_MAX_RANK]; /* Info for hyperslab */
hsize_t ss_block[H5S_MAX_RANK]; /* Info for hyperslab */
hsize_t ss_count[H5S_MAX_RANK]; /* Info for hyperslab */
int i; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
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 */
hsize_t ss_stride[H5S_MAX_RANK]; /* Info for hyperslab */
hsize_t ss_block[H5S_MAX_RANK]; /* Info for hyperslab */
hsize_t ss_count[H5S_MAX_RANK]; /* Info for hyperslab */
int i; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */

/* Subsetting information for the tools library printing routines */
subset.start.data = ss_start;
Expand Down Expand Up @@ -180,14 +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", LDBL_DIG);
snprintf(fmt_ldouble, sizeof(fmt_ldouble), "%%1.%dLg", DBL_DIG);
info.fmt_ldouble = fmt_ldouble;
snprintf(fmt_float_complex, sizeof(fmt_float_complex), "%%1.%dg%%+1.%dgi", FLT_DIG, FLT_DIG);
info.fmt_float_complex = fmt_float_complex;
snprintf(fmt_double_complex, sizeof(fmt_double_complex), "%%1.%dg%%+1.%dgi", DBL_DIG, DBL_DIG);
info.fmt_double_complex = fmt_double_complex;
snprintf(fmt_ldouble_complex, sizeof(fmt_ldouble_complex), "%%1.%dLg%%+1.%dLgi", LDBL_DIG, LDBL_DIG);
info.fmt_ldouble_complex = fmt_ldouble_complex;

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
9 changes: 7 additions & 2 deletions tools/lib/h5tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ typedef struct h5tool_format_t {
* typed `unsigned long long'. The default depends on what
* printf() format is available to print this datatype.
*
* fmt_float: The printf() format to use when rendering data which is
* typed `float'. The default is `%g'.
* 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'.
*
* fmt_double: The printf() format to use when rendering data which is
* typed `double'. The default is `%g'.
Expand Down Expand Up @@ -320,6 +323,8 @@ 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;
const char *fmt_double;
const char *fmt_ldouble;
Expand Down
31 changes: 14 additions & 17 deletions tools/lib/h5tools_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,20 @@
h5tool_format_t h5tools_dataformat = {
0, /*raw */

"", /*fmt_raw */
"%hhd", /*fmt_schar */
"%u", /*fmt_uchar */
"%d", /*fmt_short */
"%u", /*fmt_ushort */
"%d", /*fmt_int */
"%u", /*fmt_uint */
"%ld", /*fmt_long */
"%lu", /*fmt_ulong */
NULL, /*fmt_llong */
NULL, /*fmt_ullong */
"%g", /*fmt_float */
"%g", /*fmt_double */
"%Lg", /*fmt_ldouble */
"%g%+gi", /*fmt_float_complex */
"%g%+gi", /*fmt_double_complex */
"%Lg%+Lgi", /*fmt_ldouble_complex */
"", /*fmt_raw */
"%d", /*fmt_int */
"%u", /*fmt_uint */
"%hhd", /*fmt_schar */
"%u", /*fmt_uchar */
"%d", /*fmt_short */
"%u", /*fmt_ushort */
"%ld", /*fmt_long */
"%lu", /*fmt_ulong */
NULL, /*fmt_llong */
NULL, /*fmt_ullong */
"%Lg", /*fmt_ldouble */
"%g", /*fmt_double */
"%g", /*fmt_float */

0, /*ascii */
0, /*str_locale */
Expand Down
6 changes: 6 additions & 0 deletions tools/src/h5dump/h5dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,12 @@ parse_command_line(int argc, const char *const *argv)
break;
}

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

case 'L':
/* specify alternative floating point long double printing format */
fp_lformat = H5_optarg;
Expand Down
15 changes: 7 additions & 8 deletions tools/src/h5dump/h5dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,13 @@ typedef struct h5dump_table_list_t {
h5dump_table_list_t table_list = {0, 0, NULL};
table_t *group_table = NULL, *dset_table = NULL, *type_table = NULL;

unsigned dump_indent = 0; /* how far in to indent the line */
int unamedtype = 0; /* shared datatype with no name */
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;
const char *complex_format = NULL; /* format for printing complex numbers */
unsigned dump_indent = 0; /* how far in to indent the line */
int unamedtype = 0; /* shared datatype with no name */
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
28 changes: 0 additions & 28 deletions tools/src/h5dump/h5dump_ddl.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ dump_attr_cb(hid_t oid, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}
if (complex_format) {
string_dataformat.fmt_double_complex = complex_format;
string_dataformat.fmt_float_complex = complex_format;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -185,10 +181,6 @@ dump_all_cb(hid_t group, const char *name, const H5L_info2_t *linfo, void H5_ATT
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}
if (complex_format) {
string_dataformat.fmt_double_complex = complex_format;
string_dataformat.fmt_float_complex = complex_format;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -663,10 +655,6 @@ dump_named_datatype(hid_t tid, const char *name)
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}
if (complex_format) {
string_dataformat.fmt_double_complex = complex_format;
string_dataformat.fmt_float_complex = complex_format;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -826,10 +814,6 @@ dump_group(hid_t gid, const char *name)
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}
if (complex_format) {
string_dataformat.fmt_double_complex = complex_format;
string_dataformat.fmt_float_complex = complex_format;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -959,10 +943,6 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset)
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}
if (complex_format) {
string_dataformat.fmt_double_complex = complex_format;
string_dataformat.fmt_float_complex = complex_format;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -1137,10 +1117,6 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index)
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}
if (complex_format) {
string_dataformat.fmt_double_complex = complex_format;
string_dataformat.fmt_float_complex = complex_format;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down Expand Up @@ -1609,10 +1585,6 @@ handle_attributes(hid_t fid, const char *attr, void H5_ATTR_UNUSED *data, int H5
if (fp_lformat) {
string_dataformat.fmt_ldouble = fp_lformat;
}
if (complex_format) {
string_dataformat.fmt_double_complex = complex_format;
string_dataformat.fmt_float_complex = complex_format;
}

if (h5tools_nCols == 0) {
string_dataformat.line_ncols = 65535;
Expand Down
1 change: 0 additions & 1 deletion tools/src/h5dump/h5dump_extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ extern size_t prefix_len;
extern char *prefix;
extern const char *fp_format;
extern const char *fp_lformat;
extern const char *complex_format; /* format for complex number */

/* things to display or which are set via command line parameters */
typedef struct {
Expand Down
Loading

0 comments on commit d3cfa11

Please sign in to comment.