Go to the previous, next section.
The function nctypelen (or NCTLEN for FORTRAN) returns
the number of bytes per netCDF data type.
In case of an error, nctypelen returns -1; NCTLEN returns a
nonzero value in rcode. One possible cause of errors is:
int nctypelen (nc_type datatype);
datatype
nc_type, is defined in the netCDF header file. The
valid netCDF data types are NC_BYTE, NC_CHAR,
NC_SHORT, NC_LONG, NC_FLOAT, and NC_DOUBLE.
nctypelen to determine how many bytes
are required to store a single value of the variable rh in an
existing netCDF file named `foo.nc':
#include "netcdf.h"
...
int ncid; /* netCDF ID */
int rh_id; /* variable ID */
nc_type rh_type; /* variable type */
int rh_ndims; /* number of dims */
int rh_dims[MAX_VAR_DIMS]; /* variable shape */
int rh_natts; /* number of attributes */
int rhbytes; /* number of bytes per value for "rh" */
...
ncid = ncopen("foo.nc", NC_NOWRITE);
...
rh_id = ncvarid (ncid, "rh");
/* get type. we don't need name, since we already know it */
ncvarinq (ncid, rh_id, (char *) 0, &rh_type, &rh_ndims, rh_dims,
&rh_natts);
rhbytes = nctypelen (rh_type);
INTEGER FUNCTION NCTLEN (INTEGER TYPE ,INTEGER RCODE)
TYPE
NCBYTE, NCCHAR, NCSHORT, NCLONG,
NCFLOAT, and NCDOUBLE.
RCODE
Here is an example using NCTLEN to determine how many bytes are
required to store a single value of the variable rh in an existing
netCDF file named `foo.nc':
INCLUDE 'netcdf.inc'
...
INTEGER NCID ! netCDF ID
INTEGER RHID ! variable ID
CHARACTER*31 RHNAME ! variable name
INTEGER RHTYPE ! variable type
INTEGER RHN ! number of dimensions
INTEGER RHDIMS(MAXVDIMS) ! variable shape
INTEGER RHNATT ! number of attributes
INTEGER RHBYTS ! bytes per value
...
NCID = NCOPN ('foo.nc', NCNOWRIT, RCODE)
...
RHID = NCVID (NCID, 'rh', RCODE)
* get type of "rh"
CALL NCVINQ (NCID, RHID, RHNAME, RHTYPE, RHN, RHDIMS, RHNATT,
+ RCODE)
RHBYTS = NCTLEN (RHTYPE)
Go to the previous, next section.