MATLAB®
netcdf
package of low-level functions and its correspondence with
the NetCDF C library.
MATLAB provides access to the routines in the NetCDF C
library through a set of low-level functions that are grouped into
a package called netcdf
. Use the functions in this
package to read and write data to and from NetCDF files. To use the MATLAB NetCDF
functions effectively, you should be familiar with the NetCDF C interface.
Usually, the MATLAB functions in the netcdf
package
correspond directly to routines in the NetCDF C library. For example,
the MATLAB function netcdf.open
corresponds
to the NetCDF library routine nc_open
. In some
cases, one MATLAB function corresponds to a group of NetCDF library
functions. For example, instead of creating MATLAB versions of
every NetCDF library nc_put_att_
function,
where type
type
represents a data type, MATLAB uses
one function, netcdf.putAtt
, to handle all supported
data types.
To call one of the functions in the netcdf
package,
you must prefix the function name with the package name. The syntax
of the MATLAB functions is similar to the NetCDF library routines.
However, the NetCDF C library routines use input parameters to return
data, while their MATLAB counterparts use one or more return
values. For example, this is the function signature of the nc_open
routine
in the NetCDF library:
int nc_open (const char *path, int omode, int *ncidp); /* C syntax */
The NetCDF file identifier is returned in the ncidp
argument.
This is the signature of the corresponding MATLAB function, netcdf.open
:
ncid = netcdf.open(filename, mode)
Like its NetCDF C library counterpart, the MATLAB NetCDF
function accepts a file name and a constant that specifies the access
mode. However, that the MATLAB netcdf.open
function
returns the file identifier, ncid
, as a return
value.
The MATLAB NetCDF functions automatically choose the MATLAB class that best matches the NetCDF data type. This table shows the default mapping.
NetCDF Data Type | MATLAB Class |
---|---|
'NC_BYTE' | int8 or uint8 [a] |
'NC_CHAR' | char |
'NC_SHORT' | int16 |
'NC_INT' | int32 |
'NC_FLOAT' | single |
'NC_DOUBLE' | double |
[a] NetCDF interprets byte data as either signed or unsigned. |
You can override the default and specify the class of the return
data by using an optional argument to the netcdf.getVar
function.