Skip to content

Commit

Permalink
fix set_formats for json, introduced in 490a9a5
Browse files Browse the repository at this point in the history
  • Loading branch information
jllodra committed Feb 8, 2020
1 parent 0ea3937 commit 44e3da8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/dumplib.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ init_epsilons(void) {
static char* has_c_format_att(int ncid, int varid);
static vnode* newvnode(void);

int float_digits_set = 0;
int double_digits_set = 0;
int float_precision_specified = 0; /* -p option specified float precision */
int double_precision_specified = 0; /* -p option specified double precision */
char float_var_fmt[] = "%.NNg";
Expand Down Expand Up @@ -335,6 +337,13 @@ set_formats(int float_digits, int double_digits) {
res = snprintf(double_att_fmt, strlen(double_att_fmt) + 1, "%%#.%dg",
double_digits) + 1;
assert(res <= sizeof (double_att_fmt));
float_digits_set = float_digits;
double_digits_set = double_digits;
}

void
fix_formats_for_json() {
set_formats(float_digits_set, double_digits_set);
}

static char *
Expand Down
2 changes: 2 additions & 0 deletions src/dumplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ extern size_t strlcat(char *dst, const char *src, size_t siz);
/* In case different formats specified with -d option, set them here. */
extern void set_formats ( int flt_digs, int dbl_digs );

extern void fix_formats_for_json ( void );

/* Determine print format to use for each value for this variable. */
const char * get_fmt ( int ncid, int varid, nc_type typeid );

Expand Down
3 changes: 3 additions & 0 deletions src/ncdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,9 @@ main(int argc, char *argv[]) {
return 0;
}

if (is_json) {
fix_formats_for_json();
}
set_max_len(max_len);

argc -= optind;
Expand Down

0 comments on commit 44e3da8

Please sign in to comment.