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

Re: 970113: NetCDF problem



>To: address@hidden
>From: Robert Fischer <address@hidden>
>Subject: NetCDF problem
>Organization: Harvard
>Keywords: 199701131824.LAA04274

Hi Bob,

> i'm using netCDF 2.4.3 on Solaris 2.4
> 
> i want to produce, using ncgen, a file with some zero dimensions (and 1-D
> arrays using these dimensions).  but ncgen doesn't allow dimensions of
> less than 1, calling them 'negative'.  the problem is in the following
> production in the ncgen.y grammar:
> 
> dimdecl:        dimd '=' LONG_CONST
>                  { if (long_val <= 0)
>                        derror("negative dimension size");
>                    dims[ndims].size = long_val;
>                    ndims++;
>                  }
>                 | dimd '=' NC_UNLIMITED_K
>                  {  if (rec_dim != -1)
>                        derror("only one NC_UNLIMITED dimension
> allowed");
>                    rec_dim = ndims; /* the unlimited (record) dimension
> */
>                    dims[ndims].size = NC_UNLIMITED;
>                    ndims++;
>                  }
> 
> it could easily be changed to allow dimensions of 0.  is there any reason
> this should NOT be done?  will it break somewhere else?

If you changed this, the result would be the same as if you specified
"unlimited" for the dimension length, because of the following
definition in the netcdf.h include file:

    /*
     * 'size' argument to ncdimdef for an unlimited dimension
     */
    #define NC_UNLIMITED 0L

If you are not using the unlimited dimension for any other purpose in
the file you want to produce, then using the unlimited dimension as a
zero-length dimension will work fine, and you don't even have to change
ncgen.y; just use "unlimited" for the dimension length.

However, if you are already using the unlimited dimension, there is
currently no way to define another dimension with length zero, as netCDF
doesn't support multiple unlimited dimensions or zero-length arrays (but
neither does C or FORTRAN).  About the best you could do in this case
would be to use a dimension of length one, possibly with a name that
indicated the real intent.

The error message "negative dimension size" is misleading when zero is
specified; I'll change change this to "dimension length must be
positive".  Thanks for pointing out the problem.

--Russ

_____________________________________________________________________

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