Hi,
Rather than producing another minor release of the netcdf distribution for
every bug fix, we will be accumulating fixes and enhancements for a while.
But to make bug fixes available, we will occasionally post patches that are
to be applied to the current distribution. These patches are also available
via anonymous FTP from unidata.ucar.edu in the pub/netcdf directory.
This is patch #2 for netcdf 2.3.2. It is independent of patch #1. It
accomplishes the following:
BUG FIXES
A bug in ncgen is fixed in which trailing zeros were trimmed from the
exponents in the initialization of C constants generated by "ncgen -c"
invocations. (Thanks to schall@xxxxxxxxxxxx for reporting the bug.)
A bug in ncdump is fixed in which the output included an extraneous
decimal point added to the end of some floating-point attributes that
require exponential notation, e.g. "1.5e+30.".
This patch-file is designed to be applied from the top-level netcdf source
directory via Larry Wall's patch(1) utility, e.g.
$ cd /usr/local/src/netcdf-2.3.2
$ patch -p1 < [this_file]
The "-p1" option is necessary.
________________________________________________________________________
Russ Rew Unidata Program Center
russ@xxxxxxxxxxxxxxxx UCAR, PO Box 3000
Boulder, CO 80307-3000
==================================================================
diff -c1 -r netcdf-2.3.2/ncdump/ncdump.c netcdf-2.3.2+/ncdump/ncdump.c
*** netcdf-2.3.2/ncdump/ncdump.c Wed Feb 17 09:54:18 1993
--- netcdf-2.3.2+/ncdump/ncdump.c Wed Jun 23 13:27:24 1993
***************
*** 102,103 ****
--- 102,134 ----
/*
+ * Remove trailing zeros (after decimal point) but not trailing decimal
+ * point from ss, a string representation of a floating-point number that
+ * might include an exponent part.
+ */
+ static void
+ tztrim(ss)
+ char *ss; /* returned string representing dd */
+ {
+ char *cp, *ep;
+
+ cp = ss;
+ if (*cp == '-')
+ cp++;
+ while(isdigit((int)*cp) || *cp == '.')
+ cp++;
+ if (*--cp == '.')
+ return;
+ ep = cp+1;
+ while (*cp == '0')
+ cp--;
+ cp++;
+ if (cp == ep)
+ return;
+ while (*ep)
+ *cp++ = *ep++;
+ *cp = '\0';
+ return;
+ }
+
+
+ /*
* Print list of attribute values. Attribute values must be printed with
***************
*** 122,125 ****
char gps[30]; /* for ascii of a float or double precision */
! char *f_fmt = "%.8g";
! char *d_fmt = "%.16g";
--- 153,156 ----
char gps[30]; /* for ascii of a float or double precision */
! char *f_fmt = "%#.8g";
! char *d_fmt = "%#.16g";
***************
*** 191,193 ****
(void) sprintf(gps, f_fmt, * gp.fp++);
- /* make sure we get a decimal point for float type attributes */
/* append a trailing "f" for floating-point attributes */
--- 222,223 ----
***************
*** 194,197 ****
ll = strlen(gps);
- if (!strchr(gps, '.'))
- gps[ll++] = '.';
gps[ll + 1] = '\0';
--- 224,225 ----
***************
*** 198,199 ****
--- 226,228 ----
gps[ll] = 'f';
+ tztrim(gps); /* trim trailing 0's after '.' */
Printf ("%s%s", gps, iel<len-1 ? ", " : "");
***************
*** 205,212 ****
(void) sprintf(gps, d_fmt, *gp.dp++);
! /* make sure we get a decimal point for float type attributes */
! if (!strchr(gps, '.')) {
! int ll = strlen(gps);
! gps[ll++] = '.';
! gps[ll] = '\0';
! }
Printf ("%s%s", gps, iel<len-1 ? ", " : "");
--- 234,236 ----
(void) sprintf(gps, d_fmt, *gp.dp++);
! tztrim(gps); /* trim trailing 0's after '.' */
Printf ("%s%s", gps, iel<len-1 ? ", " : "");
***************
*** 242,243 ****
--- 266,271 ----
+ if (ncid == -1) {
+ error("ncopen failed on %s", path);
+ return;
+ }
/*
diff -c1 -r netcdf-2.3.2/ncgen/load.c netcdf-2.3.2+/ncgen/load.c
*** netcdf-2.3.2/ncgen/load.c Wed Mar 17 22:32:56 1993
--- netcdf-2.3.2+/ncgen/load.c Wed Jun 23 13:29:53 1993
***************
*** 118,134 ****
/*
! * Like sprintf(ss, "%#.16g", dd) except we remove trailing zero but not
! * trailing decimal point.
*/
! char *
! sdprintf(ss, dd)
char *ss; /* returned string representing dd */
- double dd;
{
! char *cp;
! sprintf(ss, "%#.16g", dd);
! cp = ss + strlen(ss) - 1;
while (*cp == '0')
! *cp-- = '\0';
! return ss;
}
--- 119,147 ----
/*
! * Remove trailing zeros (after decimal point) but not trailing decimal
! * point from ss, a string representation of a floating-point number that
! * might include an exponent part.
*/
! static void
! tztrim(ss)
char *ss; /* returned string representing dd */
{
! char *cp, *ep;
! cp = ss;
! if (*cp == '-')
! cp++;
! while(isdigit((int)*cp) || *cp == '.')
! cp++;
! if (*--cp == '.')
! return;
! ep = cp+1;
while (*cp == '0')
! cp--;
! cp++;
! if (cp == ep)
! return;
! while (*ep)
! *cp++ = *ep++;
! *cp = '\0';
! return;
}
***************
*** 242,244 ****
case NC_DOUBLE:
! sdprintf(s2, *doublevalp++);
strcat(s2, ", ");
--- 255,258 ----
case NC_DOUBLE:
! sprintf(s2, "%#.16g", *doublevalp++);
! tztrim(s2);
strcat(s2, ", ");
***************
*** 270,272 ****
case NC_DOUBLE:
! sdprintf(s2, *doublevalp++);
break;
--- 284,287 ----
case NC_DOUBLE:
! sprintf(s2, "%#.16g", *doublevalp++);
! tztrim(s2);
break;
***************
*** 329,331 ****
doublevalp = (double *) rec_start;
! sdprintf(s2, *doublevalp++);
strcat(stmnt, s2);
--- 344,347 ----
doublevalp = (double *) rec_start;
! sprintf(s2, "%#.16g", *doublevalp++);
! tztrim(s2);
strcat(stmnt, s2);
***************
*** 467,469 ****
for (ival = 0; ival < var_len-1; ival++) {
! sdprintf(s2, *doublevalp++);
fstrcat(s2, ", ", &stmnt_len);
--- 483,486 ----
for (ival = 0; ival < var_len-1; ival++) {
! sprintf(s2, "%#.16g", *doublevalp++);
! tztrim(s2);
fstrcat(s2, ", ", &stmnt_len);
***************
*** 471,473 ****
}
! sdprintf(s2, *doublevalp++);
fstrcat(stmnt, s2, &stmnt_len);
--- 488,491 ----
}
! sprintf(s2, "%#.16g", *doublevalp++);
! tztrim(s2);
fstrcat(stmnt, s2, &stmnt_len);