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

[netCDF #AKU-355464]: Coordinate axis values for an UNLIMITED dimension



Hi Jennifer,

> I would like to write out a netcdf file that has an unlimited dimension.
> The problem is that the resulting file does not contain values for that
> dimension -- they appear to be missing. I have attached below a modified
> version of press_temp_4D_wr.c, which was included in the library source
> code, and which creates a file with the following output from ncdump:
> 
> netcdf pres_temp_4D {
> dimensions:
> level = 2 ;
> latitude = 6 ;
> longitude = 12 ;
> time = UNLIMITED ; // (2 currently)
> variables:
> float longitude(longitude) ;
> longitude:units = "degrees_east" ;
> float latitude(latitude) ;
> latitude:units = "degrees_north" ;
> float level(level) ;
> float time(time) ;
> float pressure(time, level, latitude, longitude) ;
> pressure:units = "hPa" ;
> float temperature(time, level, latitude, longitude) ;
> temperature:units = "celsius" ;
> data:
> 
> longitude = -125, -120, -115, -110, -105, -100, -95, -90, -85, -80, -75, -70 ;
> 
> latitude = 25, 30, 35, 40, 45, 50 ;
> 
> level = 1, 6 ;
> 
> time = _, _ ;
> }
> 
> 
> How can I get it to write out the defined values for the time axis
> instead of "time = _, _ ;" ?
> 
> It will work if I change this:
> 
> nc_def_dim(ncid, REC_NAME, NC_UNLIMITED, &rec_dimid)
> to
> nc_def_dim(ncid, REC_NAME, NREC, &rec_dimid)
> 
> But then the dimension is no longer a record dimension.
> 
> --Jennifer

I suspect you are trying to write the time dimension with nc_put_var, rather 
than nc_put_vara().

See this note from the nc_put_var() documentation for why nc_put_var() won't 
work as expected 
until some record data has already been written to the file:

  Take care when using this function with record variables (variables
  that use the NC_UNLIMITED dimension). If you try to write all the
  values of a record variable into a netCDF file that has no record
  data yet (hence has 0 records), nothing will be written. Similarly,
  if you try to write all the values of a record variable but there
  are more records in the file than you assume, more in-memory data
  will be accessed than you supply, which may result in a segmentation
  violation. To avoid such problems, it is better to use the
  nc_put_vara interfaces for variables that use the NC_UNLIMITED
  dimension.

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: AKU-355464
Department: Support netCDF
Priority: Normal
Status: Closed


NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.