Create the variable varname in the file filename.
The following properties can be used:
ncinfo
for the correspondence between Octave and NetCDF data
types). The default data type is a "double".
nccreate("test.nc","temp","Dimensions",{"lon",10,"lat",20},"Format","classic"); ncdisp("test.nc");
See also: ncwrite.
info =
ncinfo (filename)
¶info =
ncinfo (filename, varname)
¶info =
ncinfo (filename, groupname)
¶Return information about an entire NetCDF file filename (i.e. the root group "/"), about the variable called varname or the group called groupname.
The structure info has always the following fields:
The structure info has additional fields depending on whether a group of variable is queried.
Groups are returned as an array structure with the following fields:
Dimensions are returned as an array structure with the following fields:
Variables are returned as an array structure with the following fields:
Attributes are returned as an array structure with the following fields:
The following the the correspondence between the Octave and NetCDF data-types:
Octave type | NetCDF type |
---|---|
int8 | NC_BYTE |
uint8 | NC_UBYTE |
int16 | NC_SHORT |
uint16 | NC_USHORT |
int32 | NC_INT |
uint32 | NC_UINT |
int64 | NC_INT64 |
uint64 | NC_UINT64 |
single | NC_FLOAT |
double | NC_DOUBLE |
char | NC_CHAR |
The output of ncinfo
can be used to create a NetCDF file with the same
meta-data using ncwriteschema
.
Note: If there are no attributes (or variable or groups), the corresponding field is an empty matrix and not an empty struct array for compatibility with matlab.
See also: ncread,nccreate,ncwriteschema,ncdisp.
x =
ncread (filename, varname)
¶x =
ncread (filename, varname,start,count,stride)
¶Read the variable varname from the NetCDF file filename.
If start,count and stride are present, a subset of the variable is loaded. The parameter start contains the starting indices (1-based), count is the number of elements and stride the increment between two successive elements. These parameters are vectors whose length is equal to the number of dimension of the variable. Elements of count might be Inf which means that as many values as possible are loaded.
If the variable has the _FillValue attribute, then the corresponding values are replaced by NaN (except for characters). NetCDF attributes scale_factor (default 1) and add_offset (default 0) are use the transform the variable during the loading:
x = scale_factor * x_in_file + add_offset
The output data type matches the NetCDF datatype, except when the attributes _FillValue, add_offset or scale_factor are defined in which case the output is a array in double precision.
Note that values equal to the attribute missing_value are not replaced by NaN (for compatibility).
Read the data from variable ’mydata’ in the file test.nc.
data = ncread('test.nc','mydata');
See also: ncwrite,ncinfo,ncdisp.
val =
ncreadatt(filename,varname,attname) ¶Return the attribute attname of the variable varname in the file filename.
Global attributes can be accessed by using "/" or the group name as
varname. The type of attribute is mapped to the Octave data types.
(see ncinfo
).
Read global attribute ’creation_date’
d = ncreadatt('test.nc','/','creation_date')
Read atribute ’myattr’ assigned to variable mydata.
d = ncreadattr('test.nc', 'mydata', 'myattr');
See also: ncinfo,ncwriteatt.
(filename, varname, x)
¶(filename, varname, x, start, stride)
¶Write array x to the the variable varname in the NetCDF file filename.
The variable with the name varname and the appropriate dimension must already exist in the NetCDF file.
If start and stride are present, a subset of the variable is written. The parameter start contains the starting indices (1-based) and stride the increment between two successive elements. These parameters are vectors whose length is equal to the number of dimension of the variable.
If the variable has the _FillValue attribute, then the values equal to NaN are replaced by corresponding fill value NetCDF attributes scale_factor (default 1) and add_oddset (default 0) are use the transform the variable during writing:
x_in_file = (x - add_offset)/scale_factor
Create a netcdf file with a variable of ’mydata’ and then write data to that variable.
nccreate('myfile.nc','mydata'); ncwrite('myfile.nc','mydata', 101);
See also: ncread,nccreate.
Defines the attribute attname of the variable varname in the file filename with the value val.
Global attributes can be defined by using "/" or the group name as
varname. The type of value is mapped to the NetCDF data types.
(see ncinfo
).
Create a netcdf4 format file with a variable mydata and assign an attribute "units" to it.
nccreate("myfile.nc", "mydata", "Format", "netcdf4"); ncwriteatt("myfile.nc", "mydata", "Units", "K");
See also: ncinfo.
(filename, schema)
¶Create a NetCDF called filename with the dimensions, attributes, variables and groups given by the structure schema.
The variable schema has the same structure as the results of
ncinfo
. ncinfo
and ncwriteschema
can be used together to
create a NetCDF using another file as a template:
schema = ncinfo("template.nc"); # the new file should be named "new_file.nc" ncwriteschema("new_file.nc",schema);
Unused field in schema such as ChunkSize, Shuffle, DeflateLevel, FillValue, Checksum can be left-out if the corresponding feature is not used.
Dimensions are considered as limited if the field Unlimited is missing, unless the dimension length is Inf.
See also: ncinfo.