[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 950915: netCDF and NC_UNLIMITED woes
- Subject: Re: 950915: netCDF and NC_UNLIMITED woes
- Date: Fri, 15 Sep 1995 13:55:07 -0600
>Organization: Geophysical Inst., Univ. of Alaska Fairbanks
>Keywords: 199509151936.AA08228
Hi Dave,
> I think my last email didn't get sent properly, so to summarise I have a
> similar problem that one person had on the support email replies, but I didn't
> see a solution. Basically I am trying to write a variable with an unlimited
> dimension, but ncdump shows me only the header. Here is a sample piece of code
> which has the problem.
>
> If I specify a finite time dimension it works fine. Thanks for your time.
>
> Regards,
>
> Dave
>
> #include "netcdf.h"
>
> #define TIMES 3
> #define LATS 5
> #define LONS 10
>
> main() {
> int ncid; /* netCDF ID */
> int rh_id; /* variable ID */
> static long start[] = {0, 0, 0}; /* start at first value */
> static long count[] = {1, LATS, LONS};
> int dimids[3];
> int time_def, lat_def, lon_def;
> double rh_vals[LATS*LONS]; /* array to hold values */
> int i,iret;
>
> ncid = nccreate("foo.nc", NC_NOCLOBBER);
> lat_def = ncdimdef(ncid,"lat",LATS);
> lon_def = ncdimdef(ncid,"lon",LONS);
> time_def = ncdimdef(ncid,"times",NC_UNLIMITED);
> dimids[0] = time_def;
> dimids[1] = lat_def;
> dimids[2] = lon_def;
> rh_id = ncvardef(ncid, "rh", NC_DOUBLE, 3, dimids);
> iret = ncendef(ncid);
>
> for (i = 0; i < LATS*LONS; i++)
> rh_vals[i] = 0.5;
>
> /* write hyperslab of values into netCDF variable */
> iret = ncvarput(ncid, rh_id, start, count, (void *) rh_vals);
> iret = ncclose(ncid);
>
> }
I just tested your code here (on a SPARCstation 10/Solaris 2.4 with netCDF
2.3.2) and it seems to work as intended:
test$ ncdump foo.nc
netcdf foo {
dimensions:
lat = 5 ;
lon = 10 ;
times = UNLIMITED ; // (1 currently)
variables:
double rh(times, lat, lon) ;
data:
rh =
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ;
}
Unless you are using "ncdump -h" or "ncdump -c" (which specifies not to
print the data), I don't see what the problem is. If you'll tell me
what computer and OS you are using, maybe we can duplicate the problem here.
Thanks.
--Russ
______________________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu