Return numeric value of named constant


val = netcdf.getConstant(param_name)


val = netcdf.getConstant(param_name) returns the numeric value corresponding to the name of a constant defined by the netCDF library. For example, netcdf.getConstant('NC_NOCLOBBER') returns the numeric value corresponding to the netCDF constant NC_NOCLOBBER.

The value for param_name can be either upper- or lowercase, and does not need to include the leading three characters 'NC_'. To retrieve a list of all the names defined by the netCDF library, use the netcdf.getConstantNames function.

This function has no direct equivalent in the netCDF C interface. To find out more about NetCDF, see netcdf.


This example opens the example netCDF file included with MATLAB®,

% Open example file.
ncid ='','NC_NOWRITE');

% Determine contents of the file.
[ndims nvars natts dimm] = netcdf.inq(ncid);

% Get name of global attribute. 
% Note: You must use netcdf.getConstant to specify NC_GLOBAL.
attname = netcdf.inqattname(ncid,netcdf.getConstant('NC_GLOBAL'),0)

attname =

Was this topic helpful?