This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>cc: address@hidden, address@hidden >From: address@hidden (Don Hooper) >Subject: Re: bug/incompatibility in emulation of version 2 netCDF call in >version 3 lib >Date: Tue, 26 Nov 1997 19:47:56 -0700 >Keywords: 199711260248.TAA23133 netCDF 3.3.1 Hi Hoop, > A followup on my earlier report. To recap, when I tried to extend a file > along its unlimited dimension, I got a strange error message from the > emulation > of version 2 calls in version 3.3.1 ("ncvarput1: ncid 4: Not a netCDF data > type"). When I changed that call to its version 3 equivalents, the error > messages stopped, and the return value from the function call allowed my > program to continue. The new information is that the file was not, however, > extended. When I switched back to the version 2 call and re-linked the > program with the 2.4 library, I finally got a sensible and useful error > message. The _FillValue attribute had a different type than its variable. > This happened because my program to "pack" netCDF files did not adjust > that attribute. Fixing the _FillValue attribute fixed the problem, but > I am wary now of version 3.3.1, as I either get misleading error messages, > or no indication of error! Thanks for this and your following email. I've now been able to create a small program that demonstrates the bug, which produces a misleading error message, as you've observed. In my example, the same misleading error message was produced by substituting the version 3.3.1 call as with using the 2.4 call. I think the reason you were getting no indication of error may have been due to not checking the status returned by the nc_put_var1_float() call. In netCDF-3, checking the returned status from calls is required; you won't get an error message by default. This change to the error message behavior was requested by developers who use netCDF in applications where they want control of error messages (to generate alert boxes in a GUI, for example) rather than having them appear on stderr from the innards of the library. I've appended the test program that makes a netCDF-3 nc_put_vara_float() call and produces the output line 67 of bug1.c: Not a netCDF data type when compiled and linked against the 3.3.1 library. Glenn Davis is working on a fix. --Russ #include <stdlib.h> #include <stdio.h> #include "netcdf.h" void check_err(const int stat, const int line, const char *file) { if (stat != NC_NOERR) { (void) fprintf(stderr, "line %d of %s: %s\n", line, file, nc_strerror(stat)); exit(1); } } int main() { /* create dh.nc */ int ncid; /* netCDF id */ /* dimension ids */ int n_dim, r_dim; /* dimension lengths */ size_t n_len = 2; size_t r_len = NC_UNLIMITED; int stat; /* variable ids */ int z_id; /* rank (number of dimensions) for each variable */ # define RANK_z 2 /* variable shapes */ int dims[2]; short zfill = -999.; /* enter define mode */ ncid = nccreate("dh.nc", NC_CLOBBER); /* define dimensions */ n_dim = ncdimdef(ncid, "n", 2L); r_dim = ncdimdef(ncid, "r", NC_UNLIMITED); /* define variables */ dims[0] = r_dim; dims[1] = n_dim; z_id = ncvardef (ncid, "z", NC_FLOAT, 2, dims); ncattput(ncid, z_id, "_FillValue", NC_SHORT, 1, (void *) &zfill); /* leave define mode */ ncendef (ncid); { /* store z */ static size_t z_start[RANK_z]; static size_t z_count[RANK_z]; static float z[] = {-11, -12}; r_len = 1; /* number of records of z data */ z_start[0] = 0; z_start[1] = 0; z_count[0] = r_len; z_count[1] = n_len; stat = nc_put_vara_float(ncid, z_id, z_start, z_count, z); check_err(stat,__LINE__,__FILE__); } ncclose (ncid); return 0; }