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

Re: 971125: NC type version 2 vs version 3



>To: address@hidden
>cc: address@hidden,
>cc: address@hidden
>From: address@hidden (Don Hooper)
>Subject: bug/incompatibility in emulation of version 2 netCDF call in version 
>3 lib
>Organization: NOAA / CDC
>Keywords: 199711260248.TAA23133

Hi Don,

> I'm using netCDF version 3.3.1.  I've a program that uses version 2 calls,
> and I'm using it to update files built with the version 2.4 library.  All
> went well until I got around to wanting to extend the file along the
> UNLIMITED dimension.  Then, ncvarput1 told me that my variable had an
> unknown type ("ncvarput1: ncid 4: Not a netCDF data type").  This happened
> for both NC_DOUBLE and NC_FLOAT data.  Oddly enough, a call to ncvarinq
> returned the expected type value.  I looked a bit at 3.3.1 source code, and
> discovered that ncvarput1 went down a different function call path than its
> version 3 equivalent.  So, I changed my ncvarput1 calls to nc_put_var1_double,
> nc_put_var1_float, and nc_put_var1_short, as appropriate.  No more problems.
> I saw nothing about this on the "Known Problems" web page:
>       http://www.unidata.ucar.edu/packages/netcdf/known_problems.html
> Any notions?

I can't duplicate the problem.  Do you have a small example that
demonstrates the problem?

I just tried using the netCDF 2.4.3 version of ncgen to generate a C
program that uses just the 2.4 C interface from the following CDL:

    netcdf dh {
    dimensions:
            n = 2;
            r = unlimited;
    variables:
            float z(r,n);   // a 2D record variable
    data:
            z = -11, -12, -21, -22;
    }

I changed the resulting C program to use ncvarput1 calls for the second
record after writing the first record with an ncvarput call.

I've appended the resulting C program, which links with the netCDF-3.3.1
library, runs without error, and produces the expected file, as I verify
with ncdump.  If you try this on your platform and it doesn't work,
we'll have something we can work with to diagnose the problem.
Otherwise, it would be helpful if you could supply another example that
fails so we can reproduce the problem.

Thanks.

--Russ


#include "netcdf.h"

int
main() {                        /* create dh.nc */

   int  ncid;                   /* netCDF id */

   /* dimension ids */
   int  n_dim, r_dim;

   /* variable ids */
   int  z_id;

   /* variable shapes */
   int dims[2];

   /* 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);

   /* leave define mode */
   ncendef (ncid);

   {                    /* store z */
    static long z_start[] = {0, 0};
    static long z_edges[] = {1, 2};
    static float z[] = {-11, -12};
    ncvarput(ncid, z_id, z_start, z_edges, (void *)z);
   }

   {                    /* store z */
    static long z_index[] = {1, 0};
    static float z[] = {-21, -22};
    ncvarput1(ncid, z_id, z_index, (void *)&z[0]); /* write z(1,0) */
    z_index[1] = 1;
    ncvarput1(ncid, z_id, z_index, (void *)&z[1]); /* write z(1,1) */
  }
   ncclose (ncid);
   return 0;
}