ncinfo
Return information about netCDF data source
Description
Examples
Find Dimensions with Names Matching a Pattern
Get the file schema of the netCDF file example.nc
.
finfo = ncinfo("example.nc")
finfo = struct with fields: Filename: 'matlabroot\toolbox\matlab\demos\example.nc' Name: '/' Dimensions: [1×3 struct] Variables: [1×3 struct] Attributes: [1×1 struct] Groups: [1×2 struct] Format: 'netcdf4' Datatypes: []
Find dimensions with names that begin with x
.
dimNames = {finfo.Dimensions.Name};
dimMatch = strncmpi(dimNames,"x",1);
disp(finfo.Dimensions(dimMatch))
Name: 'x' Length: 50 Unlimited: 0
Get Size and Dimensionality of Variable
Get the variable schema of the peaks
variable in the netCDF file
example.nc
.
vinfo = ncinfo("example.nc","peaks")
vinfo = struct with fields: Filename: 'matlabroot\toolbox\matlab\demos\example.nc' Name: 'peaks' Dimensions: [1×2 struct] Size: [50 50] Datatype: 'int16' Attributes: [1×1 struct] ChunkSize: [] FillValue: -32767 DeflateLevel: [] Shuffle: 0 Format: 'netcdf4'
Find the size of the peaks
variable.
varSize = vinfo.Size
varSize = 50 50
Determine whether the peaks
variable has any unlimited
dimensions.
hasUnlimDim = any([vinfo.Dimensions.Unlimited])
hasUnlimDim = logical 0
Find Unlimited Dimensions in Group
Get the group schema of the /grid2
group in the netCDF file
example.nc
.
ginfo = ncinfo("example.nc","/grid2")
ginfo = struct with fields: Filename: 'matlabroot\toolbox\matlab\demos\example.nc' Name: 'grid2' Dimensions: [1×3 struct] Variables: [1×1 struct] Attributes: [1×1 struct] Groups: [] Format: 'netcdf4'
Find unlimited dimensions in the group.
unlimDims = [ginfo.Dimensions.Unlimited]; disp(ginfo.Dimensions(unlimDims))
Name: 'time' Length: 0 Unlimited: 1
Input Arguments
source
— Name of netCDF data source
string scalar | character vector
Name of the netCDF data source, specified as a string scalar or character vector. The
source
argument can be one of these values:
The path of a local netCDF source
The OPeNDAP URL of a remote OPeNDAP netCDF data source
The HTTP URL of a remote netCDF source, with
#mode=bytes
appended to the end of the URL to enable byte-range readingNote
Byte-range reading is slower than other methods for reading from remote sources. For more details about byte-range reading, see the netCDF documentation.
Example: "myNetCDFfile.nc"
Example: "http://
host_name
/netcdf_filename
#mode=bytes"
varname
— Variable name
string scalar | character vector
Variable name, specified as a string scalar or character vector containing the name of a variable in the netCDF data source.
If source
specifies a file with format
netcdf4
, you can specify the location of the variable within the
group hierarchy by specifying varname
as a fully qualified
name.
Example: "myVar"
Example: "/myGrp/mySubGrp/myNestedVar"
groupname
— Group name
string scalar | character vector
Group name, specified as a string scalar or character vector containing the name of a group in the netCDF data source.
Example: "myGrp"
Example: "/myGrp/mySubGrp"
Output Arguments
finfo
— NetCDF file schema
structure
NetCDF file schema, returned as a structure. This table describes the fields of the structure.
Field | Description |
---|---|
Filename | NetCDF filename or OPeNDAP URL, returned as a character vector |
Name | '/' (indicating the full file) |
Dimensions | Dimension schema, returned as a structure vector containing these fields:
|
Variables | Variable schema, as described in the vinfo output
argument, except without the Filename and
Format fields |
Attributes | Attribute schema, returned as a structure vector containing these fields:
|
Groups | Group schema, as described in the ginfo output
argument, except without the Filename and
Format fields, or an empty array ([] ) if
the file is not of format netcdf4 |
Format | NetCDF file format, returned as a character vector |
Datatypes | Structure vector of user-defined data types, containing these fields
(or an empty array (
|
vinfo
— NetCDF variable schema
structure
NetCDF variable schema, returned as a structure. This table describes the fields of the structure.
Field | Description |
---|---|
Filename | NetCDF filename or OPeNDAP URL, returned as a character vector |
Name | Name of the variable, returned as a character vector |
Dimensions | Dimension schema for the variable, returned as a structure vector containing these fields:
|
Size | Size of the current variable, returned as a numeric scalar or vector |
Datatype | MATLAB data type of the variable or name of the user-defined type, returned as a character vector |
Attributes | Attribute schema for the variable, returned as a structure vector containing these fields:
|
ChunkSize | Chunk size for the variable, returned as a numeric value, if defined;
otherwise, an empty array ([] ) |
FillValue | Fill value for the variable, returned as a scalar, if defined; otherwise,
an empty array ([] ) |
DeflateLevel | Deflate compression level for the variable, returned as a nonnegative
integer, if enabled; otherwise, an empty array ([] ) |
Shuffle | Whether the shuffle filter is enabled for the variable, returned as a logical scalar |
Format | NetCDF file format, returned as a character vector |
ginfo
— NetCDF group schema
structure
NetCDF group schema, returned as a structure. This table describes the fields of the structure.
Field | Description |
---|---|
Filename | NetCDF filename or OPeNDAP URL, returned as a character vector |
Name | Name of the group, returned as a character vector |
Dimensions | Dimension schema for the group, returned as a structure vector containing these fields:
|
Variables | Variable schema for the group, as described in the
vinfo output argument, except without the
Filename and Format fields |
Attributes | Attribute schema for the group, returned as a structure vector containing these fields:
|
Groups | Group schema for the group, as described in this output argument, except
without the Filename and Format
fields |
Format | NetCDF file format, returned as a character vector |
Tips
Use
ncdisp
for visual inspection of a netCDF source.
Version History
Introduced in R2011aR2022a: Byte-range reading of remote datasets
You can use ncinfo
for read-only access to remote datasets using
the HTTP byte-range capability, provided that the remote server supports byte-range
access.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)