⇐ ⇒

[CF-metadata] CF convention for time variable dimension

From: Russ Rew <russ>
Date: Wed, 22 Jun 2005 13:17:05 -0600

Hi Chelle,

> In the CF conventions document:
>
> Time axis:
>
> double time(time) ;
> time:long_name = "time" ;
> time:units = "days since 1990-1-1 0:0:0" ;
>
> When I try to read a netCDF file that has been written with the
> recommended convention, it won't always work.
> Matlab yes. NCBROWSE yes. Fortran NO.
> In Fortran, you cannot have an dimension indice and a variable with
> the same name. I can easily program around this but not in an
> automated way for an unknown file format...
> The program cdf2fortran which is linked to on the UNIDATA website will
> take any netcdf file and create a fortran program to read it. This
> does not work with CF compliant data because of the way you have
> defined time(time). For that matter, lat(lat) also would break it...
>
> Is this a known problem?
> I can just change the time indice to ntime so time(ntime) and then it
> will work with C, fortran, ... you name it.
> But then I won't be CF compliant....

Using the same name for dimensions and their associated coordinate
variables is actually not just part of the CF conventions, it is a
basic netCDF convention that is discussed in section "2.3.1 Coordinate
Variables" in the NetCDF User's Guide:

  http://www.unidata.ucar.edu/packages/netcdf/docs/netcdf/Variables.html

This convention was intended to be a feature rather than a problem.
The rationale for using the same name to associate a dimension with
its coordinate variable was to provide a simple and
language-independent way to make this association, so even if
dimension and variable names use a non-English language, it would
still be easy to understand which variables are coordinate variables.

The program "cdf2fortran" is part of the "CIDS Tools" package
developed by others, and was intended to be a useful tool for
generating "boiler-plate" netCDF Fortran code that may be tedious to
write. Thanks for letting us know that it generates invalid Fortran
for the common case of coordinate variables with the same name as
dimensions, but it would be good to also report this to the tool's
author. I think a small change to that program would fix this
problem, for example it could be changed to follow the way "ncgen -f"
generates Fortran names for Fortran variables associated with netCDF
variables and dimensions.

For the following CDL:

  netcdf coordvars {
  dimensions:
    lat = 2;
    lon = 3;
    time = 4;
  variables:
    double time(time);
    float lat(lat);
    float lon(lon);
    float temp(time, lat, lon);
  }

invoking "ncgen -f" generates valid Fortran that includes the
following declarations for dimensions and coordinate variables:

* dimension lengths
      integer lat_len
      integer lon_len
      integer time_len
      parameter (lat_len = 2)
      parameter (lon_len = 3)
      parameter (time_len = 4)
* rank (number of dimensions) for each variable
      integer time_rank
      integer lat_rank
      integer lon_rank
      integer temp_rank
      parameter (time_rank = 1)
      parameter (lat_rank = 1)
      parameter (lon_rank = 1)
      parameter (temp_rank = 3)
* variable shapes
      integer time_dims(time_rank)
      integer lat_dims(lat_rank)
      integer lon_dims(lon_rank)
      integer temp_dims(temp_rank)
* data variables
      double precision time(time_len)
      real lat(lat_len)
      real lon(lon_len)
      real temp(lon_len, lat_len, time_len)

--Russ

_____________________________________________________________________

Russ Rew UCAR Unidata Program
russ at unidata.ucar.edu http://www.unidata.ucar.edu
Received on Wed Jun 22 2005 - 13:17:05 BST

This archive was generated by hypermail 2.3.0 : Tue Sep 13 2022 - 23:02:40 BST

⇐ ⇒