|
|
|||
|
||||
Dimensions for a netCDF file are defined when it is created,
while the netCDF file is in define mode. Additional dimensions may be added
later by reentering define mode. A netCDF dimension has a name and a size. At
most one dimension in a netCDF file can have the NC_UNLIMITED size,
which means variables using this dimension can grow along this dimension.
There is a suggested limit (100) to the number of dimensions
that can be defined in a single netCDF file. The limit is the value of the predefined
macro MAX_NC_DIMS (MAXNCDIM for FORTRAN). The purpose of the limit
is to make writing generic applications simpler. They need only provide an array
of MAX_NC_DIMS dimensions to handle any netCDF file. The implementation
of the netCDF library does not enforce this advisory maximum, so it is possible
to use more dimensions, if necessary; just don't expect generic applications
or netCDF utilities to be able to handle the resulting netCDF files.
Ordinarily, the name and size of a dimension are fixed when the dimension is first defined. The name may be changed later, but the size of a dimension cannot be changed without copying all the data to a new netCDF file with a redefined dimension size.
Dimension sizes in the C interface are type long rather than type
int to make it possible to access all the data in a netCDF file
on a platform that only supports a 16-bit int data type, for example
MSDOS. If dimension sizes were type int instead, it would not be
possible to access data from variables with a dimension size greater than a
16-bit int can accommodate.
A netCDF dimension in an open netCDF file is referred to in the C and FORTRAN interfaces by a small integer called a dimension ID. In the C interface, dimension IDs are 0, 1, 2, ..., whereas in the FORTRAN interface, the associated IDs are instead 1, 2, 3, ..., in the order in which the dimensions were defined.
Operations supported on dimensions are:
The function ncdimdef (or NCDDEF
for FORTRAN) adds a new dimension to an open netCDF file in define mode. It
returns a dimension ID, given the netCDF ID, the dimension name, and the dimension
size. At most one unlimited size dimension, called the record dimension, may
be defined for each netCDF file.
In case of an error, ncdimdef returns -1; NCDDEF
returns a nonzero value in rcode. Possible causes of errors include:
int ncdimdef(int ncid, const char* name, long size);
ncidncopen or nccreate.namesizelong) or the predefined constant NC_UNLIMITED. Here is an example using ncdimdef
to create a dimension named lat of size 18 and a record dimension
named rec in a new netCDF file named `foo.nc':
#include <netcdf.h>
...
int ncid, latid, recid;
...
ncid = nccreate("foo.nc", NC_NOCLOBBER);
...
latid = ncdimdef(ncid, "lat", 18L);
recid = ncdimdef(ncid, "rec", NC_UNLIMITED);
INTEGER FUNCTION NCDDEF (INTEGER NCID,
+ CHARACTER*(*) DIMNAM,
+ INTEGER DIMSIZ,
+ INTEGER RCODE)
NCIDNCOPN or NCCRE.DIMNAMDIMSIZNCUNLIM.RCODE Here is an example using NCDDEF
to create a dimension named lat of size 18 and a record dimension
named rec in a new netCDF file named `foo.nc':
INCLUDE 'netcdf.inc'
...
INTEGER NCID, RCODE, LATID, RECID
...
NCID = NCCRE('foo.nc', NCNOCLOB, RCODE)
...
LATID = NCDDEF(NCID, 'lat', 18, RCODE)
RECID = NCDDEF(NCID, 'rec', NCUNLIM, RCODE)
The function ncdimid (or NCDID for FORTRAN) returns
the ID of a netCDF dimension, given the name of the dimension. If ndims
is the number of dimensions defined for a netCDF file, each dimension has an
ID between 0 and ndims-1 (or 1 and ndims
for FORTRAN).
In case of an error, ncdimid returns -1; NCDID returns
a nonzero value in rcode. Possible causes of errors include:
int ncdimid(int ncid, const char* name);
ncidncopen or nccreate.name Here is an example using ncdimid
to determine the dimension ID of a dimension named lat, assumed
to have been defined previously in an existing netCDF file named `foo.nc':
#include <netcdf.h>
...
int ncid, latid;
...
ncid = ncopen("foo.nc", NC_NOWRITE); /* open for reading */
...
latid = ncdimid(ncid, "lat");
INTEGER FUNCTION NCDID (INTEGER NCID,
+ CHARACTER*(*) DIMNAME,
+ INTEGER RCODE)
NCIDNCOPN or NCCRE.DIMNAMERCODE Here is an example using NCDID
to determine the dimension ID of a dimension named lat, assumed
to have been defined previously in an existing netCDF file named `foo.nc':
INCLUDE 'netcdf.inc'
...
INTEGER NCID, RCODE, LATID
...
NCID = NCOPN('foo.nc', NCNOWRIT, RCODE)
...
LATID = NCDID(NCID, 'lat', RCODE)
The function ncdiminq
(or NCDINQ for FORTRAN) returns the name and size of a dimension,
given its ID. The size for the unlimited dimension, if any, is the number of
records written so far.
In case of an error, ncdiminq returns -1; NCDINQ
returns a nonzero value in rcode. Possible causes of errors include:
int ncdiminq(int ncid, int dimid, char* name, long* size);
ncidncopen or nccreate.dimidncdimid or
ncdimdef. nameMAX_NC_NAME. If the name parameter
is given as `0' (a null pointer), no name will be returned
so no space needs to be allocated.size Here is an example using ncdiminq
to determine the size of a dimension named lat, and the name and
current maximum size of the unlimited (or record) dimension for an existing
netCDF file named `foo.nc':
#include <netcdf.h>
...
int ncid, latid, ndims, nvars, ngatts, recid;
long latsize, recs;
char recname[MAX_NC_NAME];
...
ncid = ncopen("foo.nc", NC_NOWRITE); /* open for reading */
...
latid = ncdimid(ncid, "lat");
/* get lat size, but don't get name, since we already know it */
ncdiminq(ncid, latid, 0, &latsize);
/* get ID of record dimension (among other things) */
ncinquire(ncid, &ndims, &nvars, &ngatts, &recid);
/* get record dimension name and current size */
ncdiminq(ncid, recid, recname, &recs);
SUBROUTINE NCDINQ (INTEGER NCID, INTEGER DIMID,
+ CHARACTER*(*) DIMNAM, INTEGER DIMSIZ,
+ INTEGER RCODE)
NCIDNCOPN or NCCRE.DIMIDNCDID or
NCDDEF. DIMNAMMAXNCNAM.DIMSIZRCODE Here is an example using NCDINQ
to determine the size of a dimension named lat, and the name and
current maximum size of the unlimited (or record) dimension for an existing
netCDF file named `foo.nc':
INCLUDE 'netcdf.inc'
...
INTEGER NCID, RCODE, LATID, LATSIZ
INTEGER NDIMS, NVARS, NGATTS, RECID, NRECS
* 31 in following statement is parameter MAXNCNAM
CHARACTER*31 LATNAM, RECNAM
...
NCID = NCOPN('foo.nc', NCNOWRIT, RCODE)
...
LATID = NCDID(NCID, 'lat', RCODE)
* get lat name and size, (even though we already know name)
CALL NCDINQ(NCID, LATID, LATNAM, LATSIZ, RCODE)
* get ID of record dimension (among other things)
CALL NCINQ(NCID, NDIMS, NVARS, NGATTS, RECID, RCODE)
* get record dimension name and current size
CALL NCDINQ(NCID, RECID, RECNAME, NRECS, RCODE)
The function ncdimrename (or NCDREN
for FORTRAN) renames an existing dimension in a netCDF file open for writing.
If the new name is longer than the old name, the netCDF dataset must be in define
mode. You cannot rename a dimension to have the same name as another dimension.
In case of an error, ncdimrename returns -1; NCDREN
returns a nonzero value in rcode. Possible causes of errors include:
int ncdimrename(int ncid, int dimid, const char* name);
ncidncopen or nccreate.dimidncdimid or
ncdimdef.name Here is an example using ncdimrename
to rename the dimension lat to latitude in an existing
netCDF file named `foo.nc':
#include <netcdf.h>
...
int ncid, latid;
...
ncid = ncopen("foo.nc", NC_WRITE); /* open for writing */
...
ncredef(ncid); /* put in define mode to rename dimension */
latid = ncdimid(ncid, "lat");
ncdimrename(ncid, latid, "latitude");
ncendef(ncid); /* leave define mode */
SUBROUTINE NCDREN (INTEGER NCID, INTEGER DIMID,
+ CHARACTER*(*) DIMNAME, INTEGER RCODE)
NCIDNCOPN or NCCRE.DIMIDNCDID or
NCDDEF.DIMNAMRCODE Here is an example using NCDREN
to rename the dimension "lat" to "latitude" in an existing
netCDF file named `foo.nc':
INCLUDE 'netcdf.inc'
...
INTEGER NCID, RCODE, LATID
...
NCID = NCOPN('foo.nc', NCWRITE, RCODE)
...
* put in define mode to rename dimension
CALL NCREDF(NCID, RCODE)
LATID = NCDID(NCID, 'lat', RCODE)
CALL NCDREN(NCID, LATID, 'latitude', RCODE)
* leave define mode
CALL NCENDF(NCID, RCODE)
| Contact Us Site Map Search Terms and Conditions Privacy Policy Participation Policy | ||||||
|
||||||