[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 960214: NETCDF bug



>To:       address@hidden
>From: Harry Edmon <address@hidden>
>Organization: University of Washington
>Keywords: 199602142211.AA29015

Hi Harry,

> I have a netcdf file:
> ftp://ftp.atmos.washington.edu/pub/harry/ice_snap.cdf that gives the
> following error in ncdump on a DEC alpha running Digital Unix 3.2C:
> 
> 1 grayskies% ncdump ~harry/ice_snap.cdf 
> netcdf ice_snap {
> dimensions:
>         depth0 = 1 ;
  ...
>         double aice(time, depth0, slat, slon) ;
>                 aice:long_name = "Ice Compactness" ;
> *** ncdump: Out of memory!
>                 aice:units = 42 grayskies% 
> 
> It works properly on a Sun.  This is true of 2.3.2pl4 and 2.4beta6

The problem was not just that

                aice:units = "" ;

happened to be the empty string (which is represented as an NC_CHAR
attribute with 1 value that is '\0', and which ncdump handles properly), but
that it was an attribute with 0 values.  Although the library currently
permits defining attributes with 0 values, CDL has no way to represent them,
because, for example

                aice:units =  ;

is a syntax error in CDL, and furthermore there is no way to infer the type
of the attribute from such an empty list of constants.

Nevertheless, since the documentation explicitly says that an attribute
length can be nonnegative rather than positive, I decided to have ncdump
represent all attributes of 0 length by the empty string, "".  This will
lose the type information, but it turns out that wasn't being stored for
0-length attributes anyway (ncattinq for such attributes returns
NC_UNSPECIFIED for the type).

I've verified that the appended patch to 2.4beta6 fixes the problem on
alphas for the example file you provided to demonstrate the problem.  It
also includes fixes for a few other minor ncdump problems that have come up
since the 2.4beta6 release.

Thanks for reporting the bug.

--Russ
===================================================================
RCS file: /upc/share/CVS/netcdf/ncdump/ncdump.c,v
retrieving revision 1.40
retrieving revision 1.44
diff -c -1 -r1.40 -r1.44
*** 1.40        1996/01/08 21:51:24
--- 1.44        1996/02/15 20:42:56
***************
*** 3,5 ****
   *   See netcdf/README file for copying and redistribution conditions.
!  *   $Header: /upc/share/CVS/netcdf/ncdump/ncdump.c,v 1.40 1996/01/08 
21:51:24 russ Exp $
   *********************************************************************/
--- 3,5 ----
   *   See netcdf/README file for copying and redistribution conditions.
!  *   $Header: /upc/share/CVS/netcdf/ncdump/ncdump.c,v 1.44 1996/02/15 
20:42:56 russ Exp $
   *********************************************************************/
***************
*** 184,186 ****
        sp = gp.cp + len - 1;
!       while (*sp-- == '\0' && len > 0)
            len--;
--- 184,186 ----
        sp = gp.cp + len - 1;
!       while (len > 0 && *sp-- == '\0')
            len--;
***************
*** 320,322 ****
  
!     Printf ("variables:\n");
      /* get variable info, with variable attributes */
--- 320,323 ----
  
!     if (nvars > 0)
!       Printf ("variables:\n");
      /* get variable info, with variable attributes */
***************
*** 343,353 ****
  
!           att.val = (void *) malloc((unsigned)att.len*nctypelen(att.type));
!           if (!att.val) {
!               error("Out of memory!");
!               (void) ncclose(ncid);
!               if (vlist)
!                   free(vlist);
!               return;
            }
-           (void) ncattget(ncid, varid, att.name, att.val);
            pr_att_vals(att.type, att.len, att.val);
--- 344,361 ----
  
!           if (att.len == 0) { /* show 0-length attributes as empty strings */
!               att.type = NC_CHAR;
!               att.val = (char *) malloc(1);
!               att.len = 1;
!               *(char *)att.val = '\0';
!           } else {
!               att.val = (void *) 
malloc((unsigned)att.len*nctypelen(att.type));
!               if (!att.val) {
!                   error("Out of memory!");
!                   (void) ncclose(ncid);
!                   if (vlist)
!                       free(vlist);
!                   return;
!               }
!               (void) ncattget(ncid, varid, att.name, att.val);
            }
            pr_att_vals(att.type, att.len, att.val);
***************
*** 611,613 ****
            default:
!             error("invalid value for -b option: %s", optarg);
              exit(EXIT_FAILURE);
--- 619,621 ----
            default:
!             error("invalid value for -f option: %s", optarg);
              exit(EXIT_FAILURE);