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

[netCDF #LJH-172688]: NF90_ENDDEF error



Hi Carlos,

The netCDF-3 and netCDF-4 data models and formats support shared dimensions, 
which means a dimension can be shared by multiple variables.  HDF5 doesn't 
support shared dimensions, so netCDF-4, which is implemented over an HDF5 
storage layer, emulates shared dimensions imperfectly with HDF5 objects. In 
particular, the way netCDF-4 was implemented depends on shared dimensions being 
defined *before* shared variables that use those dimensions. I suspect that is 
the cause of the problem you are seeing.

I think you are defining the 'nlats' variable incorrectly, if you intend that 
it is a coordinate variable that contains the latitude values for the 'nlats' 
dimension.  For that, you would need for the 'nlats' variable to be a 1D 
variable with NLATS values, and to use the dimension ID of the 'nlats' 
dimension in its definition.  See this example for how to do this:

  http://www.unidata.ucar.edu/netcdf/examples/programs/sfc_pres_temp_wr.f90

If you really intend the 'nlats' variable to be a scalar (no dimensions), I 
don't understand what value you intend it to contain.  You don't need it to 
hold the length of the 'nlats' dimension, that's already associated with that 
dimension. Coordinate variables must be 1D, with a dimension that has the same 
name as the variable:

   
https://www.unidata.ucar.edu/netcdf/docs/netcdf_data_set_components.html#coordinate_variables

But if you have some reason to define a scalar variable with the same name as a 
dimension, define the dimension before the variables that has the same name. 

> The concern we have is that we want to upgrade our model from netCDF 3.6.3 to 
> netCDF 4.3 to take advantage of file compression. Refactoring the model to 
> change the dimension names will be tedious and prone to error and we want to 
> know whether there is workaround that avoids changing the names of the 
> dimensions (currently the model has 75 named dimensions that are DEFined).

I don't see why you would have to change dimension names, just define the 
dimensions before the corresponding variables.

--Russ

> Full Name: Carlos Cruz
> Organization: NASA GSFC
> Package Version: netCDF 4.3.2
> Operating System: Linux
> Hardware:
> Description of problem: The attached reproducer fails with the following 
> error:
> 
> 20  Error:         -101
> NetCDF: HDF error
> 
> The reproducer shows a series of steps used to define dimensions and 
> variables in one of the climate models we support. Specifically, in the model 
> the scalar dimensions are always defined as variables (NF90_DEF_VAR) BEFORE 
> they are defined as dimensions (NF90_DEF_DIM). Note that the VARiable and the 
> DIMension have the same name. If we change one of them, then the code works. 
> The code also works with netCDF  3.6.3, which is the version currently used 
> in the model, and when we change the file format from NF90_NETCDF4 to 
> nf_64bit_offset (this latter is currently used in the model).
> 
> The questions I have is:
> 
> Is there a reason why this works in one version (or file format) and not 
> another? What is the correct procedure to define a variable dimension?
> 
> The concern we have is that we want to upgrade our model from netCDF 3.6.3 to 
> netCDF 4.3 to take advantage of file compression. Refactoring the model to 
> change the dimension names will be tedious and prone to error and we want to 
> know whether there is workaround that avoids changing the names of the 
> dimensions (currently the model has 75 named dimensions that are DEFined).
> 
> Thank you.
> 
> ---
> Carlos Cruz
> 
> 
> 
Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: LJH-172688
Department: Support netCDF
Priority: Normal
Status: Closed