Creates a variable in a NetCDF file.
nccreate(filename, varname, [[name, value]...])
Path to a file (string).
Name of a variable (string).
One or more optional name-value pair arguments to customize the variable:
type of the variable: name 'Datatype'
, possible values are 'double'
, 'float'
, 'int32'
, 'uint32'
, 'int16'
, 'uint16'
, 'int8'
, 'uint8'
, 'char'
.
dimensions of the variable: name 'Dimensions'
, value is a list
containing the dimension names and sizes as following: list(<dim1_name>, <dim1_size>...,<dimN_name>, <dimN_size>).
fill value (the value used for missing data): name 'FillValue'
, value is a scalar (double, integer, or a char), or 'disable'
to disable the fill value replacement mechanism.
nccreate
creates a variable named varname in the file filename.
The location of the variable (i.e. the path of groups at which the variable is stored) can be specified in varname using the form /grp/subgrp/.../varname
.
The groups that do not exist in the path are created.
The variable can be a scalar, a matrix, or a hypermatrix of floating number, integer or char type. By default the variable is a scalar of double
.
Optional arguments given as [name, value] pairs are used to customize the variable, especially its type and dimensions.
Variable type is specified in a string after the key 'Datatype'
:
'double'
or 'float'
'int8'
, 'uint8'
, 'int16'
, 'uint16'
, 'int32'
, 'uint32'
(note: 64 bit integer types are not supported in Scilab 5).'char'
Dimensions are specified in a Scilab list
after the key 'Dimensions'
.
This list contains for each dimension a name, and in the following element, the size of this dimension (maximum number of elements).
The dimension order is the same as in Scilab, i.e. in the order of the fastest varying index in memory, beginning with the number of rows. For example, to create a hypermatrix with hypermat, you give first the row count, then the column count, finally the matrix count.
Variables can have illimited size, by specifying an infinite dimension size (%inf
). This dimension has to correspond to the slowest varying index in memory.
Note: if the file does not exist it is created (in the NetCDF4 enhanced format), otherwise it is open in append mode.
filename = fullfile(TMPDIR, 'nccreate.nc'); // Creates a double 'x' nccreate(filename, 'x'); // Creates a variable 'n' (int8 scalar) nccreate(filename, 'n', 'Datatype', 'int8'); // Creates a string 'str' in the group 'group' nccreate(filename, '/group/str', 'Datatype', 'char', 'Dimensions', list('len', %inf)); // Creates an unlimited integer matrix 'unltd_vec' nccreate(filename, 'unltd_vec', 'Datatype', 'int32', 'Dimensions', list('dim', %inf)); // Creates a double matrix 'mat' with 4 rows and 3 columns nccreate(filename, 'mat', 'Dimensions', list('r', 4, 'c', 3)); // Creates a double hypermatrix 'hypermat' composed of 2 matrixs, each with 4 rows and 3 columns nccreate(filename, 'hypermat', 'Dimensions', list('r', 4, 'c', 3, 'm', 2)); // Creates an unlimited hyper matrix 'unltd_hypermat', each matrix has 4 rows and 3 columns nccreate(filename, 'unltd_hypermat', 'Dimensions', list('idim', %inf, 'r', 4, 'c', 3)); ncdisp(filename); | ![]() | ![]() |