Main Content

ncinfo

Return information about NetCDF data source

Syntax

finfo = ncinfo(source)
vinfo = ncinfo(source,varname)
ginfo = ncinfo(source,groupname)

Description

finfo = ncinfo(source) returns information in the structure finfo about the entire NetCDF data source specified by source, where source can be the name of a NetCDF file, the URL of an OPeNDAP NetCDF data source, or the HTTP URL of a remote NetCDF file (with the #mode=bytes suffix for byte-range reading).

vinfo = ncinfo(source,varname) returns information in the structure vinfo about the variable varname in source.

ginfo = ncinfo(source,groupname) returns information in the structure ginfo about the group groupname in source (only NetCDF4 data sources).

Note

Use ncdisp for visual inspection of a NetCDF source.

Input Arguments

source

Character vector or string scalar specifying the name of a NetCDF file, the URL of an OPeNDAP NetCDF data source, or an HTTP URL of a remote NetCDF file for byte-range reading. To enable byte-range reading of remote datasets, append #mode=bytes to the end of the HTTP URL. For details about byte-range reading, consult the NetCDF documentation.

Example: "myNetCDFfile.nc"

varname

Character vector or string scalar specifying the name of a variable in a NetCDF file or OPeNDAP data source.

groupname

Character vector or string scalar specifying the name of a group in a NetCDF file or OPeNDAP data source.

Output Arguments

finfo

A structure with the following fields.

FieldDescription 
FilenameNetCDF file name or OPeNDAP URL 
Name'/', indicating the full file 
DimensionsAn array of structures with these fields:
 NameDimension name
 LengthCurrent length of dimension
 UnlimitedBoolean flag, true for unlimited dimensions
VariablesAn array of structures with these fields:
 NameVariable name
 DimensionsAssociated dimensions
 SizeCurrent variable size
 DatatypeMATLAB® data type or name of the user-defined type
 AttributesAssociated variable attributes
 ChunkSizeChunk size, if defined, [] otherwise
 FillValueFill value of the variable
 DeflateLevelDeflate filter level, if enabled
 ShuffleShuffle filter enabled flag
AttributesAn array of global attributes with these fields:
 NameAttribute name
 ValueAttribute value
GroupsAn array of groups present in the file for netcdf4 files. An empty array ([]) for all other NetCDF file formats.
FormatFormat of the NetCDF file 
DatatypesAn array of structures containing information about each supported user-defined type in the NetCDF file with these fields (empty for files with no user-defined types):
 NameType name
 ClassClass (for NC_VLEN types, contains NC_VLEN)
 TypeType-specific information (for NC_VLEN types, contains base type as a MATLAB data type)
 ByteSizeSize of the type in bytes

vinfo

A structure containing only the variable fields from finfo.

FieldDescription
FilenameNetCDF file name
NameName of the variable
DimensionsDimensions of the variable
SizeSize of the current variable
DatatypeMATLAB data type or name of the user-defined type
AttributesAttributes associated with the variable
ChunkSizeChunk size, if defined; otherwise, []
FillValueFill value used in the variable
DeflateLevelDeflate filter level, if enabled
ShuffleShuffle filter enabled flag
FormatFormat of the NetCDF file

ginfo

A structure containing only the group fields from finfo.

FieldDescription
FilenameNetCDF file name
NameName of the group
DimensionsOnly dimensions defined in the specified group
VariablesOnly variables defined in the specified group
AttributesAttributes associated with the variable
GroupsNames of groups, if defined; otherwise, []
FormatFormat of the NetCDF file

Examples

Search for dimensions with names that start with the character x in the file.

finfo = ncinfo('example.nc');
disp(finfo);
dimNames = {finfo.Dimensions.Name};
dimMatch = strncmpi(dimNames,'x',1);
disp(finfo.Dimensions(dimMatch));

Obtain the size of a variable and check if it has any unlimited dimensions.

vinfo = ncinfo('example.nc','peaks');
varSize = vinfo.Size;
disp(vinfo);
hasUnLimDim = any([vinfo.Dimensions.Unlimited]);

Find all unlimited dimensions defined in a group.

ginfo = ncinfo('example.nc','/grid2/');
unlimDims = [ginfo.Dimensions.Unlimited];
disp(ginfo.Dimensions(unlimDims));

Limitations

  • The performance of byte-range reading is slower than reading from other sources.

Version History

Introduced in R2011a