[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 970603: netCDF 3 problem
- Subject: Re: 970603: netCDF 3 problem
- Date: Wed, 04 Jun 1997 09:24:05 -0600
> To: address@hidden (Russ Rew)
>From: address@hidden (Chris Webster)
>Subject: Re: 970603: netCDF 3 problem.
>Organization: .
>Keywords: 199706032302.RAA03280
Chris,
> ... So I'm having trouble duplicating the problem. Could you
> >tell me which variable's units attribute appears to have the wrong
> >length?
>
> None "appear" to be wrong, until I performed the following:
>
> nc_get_att_text(dataFile[set->fileIndex].ncid,
> set->varInfo->inVarID, "units", set->stats.units);
>
> Which creamed a couple of arrays (Variable O3FC only), ok bad programming
> practice. I then added:
>
> nc_inq_attlen(ncid, inVarID, "units", &len);
> printf("%d\n", len);
>
>
> and len was 128.
OK, the length of the attribute is 128, and the values for the attribute
are 'p', 'p', 'b', 'v', '\0', '\0', ...'\0', so ncdump uses the C
convention that '\0' is a string terminator and only prints the
attribute as "ppbv".
But I don't see this as a bug in the netCDF 3 library, because I get
exactly the same attribute length with the netCDF 2 library. If I run
the appended program that uses the netcdf-2 interface, either explicitly
linked to the library from netcdf-2.4.3 or using the netCDF-2
compatibility interface from netcdf-3.3, I also get an attribute length
of 128.
It appears that when the attribute was defined, a length of 128 was
used. In fact, running a little program to print attribute lengths
shows all the following variables in the file have a units attribute
length of 128:
length of O3FC:units is = 128
length of O3FF:units is = 128
length of O3FN:units is = 128
length of O3FP:units is = 128
length of O3FT:units is = 128
length of O3FV:units is = 128
length of COMED:units is = 128
length of XCO2ZERO:units is = 128
length of PALTC:units is = 128
and there are a couple of variables with much longer units attributes:
length of base_time:units is = 2010
length of time_offset:units is = 2010
So I still can't see that this demonstrates a bug with netCDF 3; there
may be a bug in the program that wrote the files, using a larger length
than necessary when defining the units attributes for some variables.
--Russ
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <netcdf.h>
int
main(int argc, char * argv[]) { /* uses netcdf-2 interface */
int ncid;
int varid;
char varname[] = "O3FC";
char attname[] = "units";
int lenatt;
char attval[128];
int i;
if (argc != 2) {
fprintf(stderr, "usage: %s file\n", argv[0]);
return -1;
}
ncid = ncopen(argv[1], NC_NOWRITE);
varid = ncvarid(ncid, varname);
ncattinq(ncid, varid, attname, 0, &lenatt);
ncattget(ncid, varid, attname, attval);
printf("lenatt = %d\n", lenatt);
for (i=0; i<lenatt; i++)
printf("att[%d] = %c\n", i, attval[i]);
return 0;
}