Skip to content

Commit

Permalink
Merge pull request #21 from subsurfaceinsights/master
Browse files Browse the repository at this point in the history
Avoid using '#' in float format specifier for float attributes for valid JSON
  • Loading branch information
jllodra authored Nov 24, 2021
2 parents 41d2207 + a8c7f47 commit d0f5299
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/ncdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,14 @@ pr_att_valgs(
ff = ((float *) vals)[iel];
if (isfinite(ff)) {
int res;
res = snprintf(gps, PRIM_LEN, float_att_fmt, ff);
const char* fmt;
/* Avoid trailing '.' with # flag in format specifier for JSON */
if (!is_json) {
fmt = float_att_fmt;
} else {
fmt = float_var_fmt;
}
res = snprintf(gps, PRIM_LEN, fmt, ff);
assert(res < PRIM_LEN);
if (!is_json) {
tztrim(gps); /* trim trailing 0's after '.' */
Expand All @@ -444,7 +451,14 @@ pr_att_valgs(
dd = ((double *) vals)[iel];
if (isfinite(dd)) {
int res;
res = snprintf(gps, PRIM_LEN, double_att_fmt, dd);
const char* fmt;
/* Avoid trailing '.' with # flag in format specifier for JSON */
if (!is_json) {
fmt = double_att_fmt;
} else {
fmt = double_var_fmt;
}
res = snprintf(gps, PRIM_LEN, fmt, dd);
assert(res < PRIM_LEN);
if (!is_json) {
tztrim(gps); /* trim trailing 0's after '.' */
Expand Down

0 comments on commit d0f5299

Please sign in to comment.