Documentation Center

  • Trial Software
  • Product Updates

nccreate

Create variable in NetCDF file

Syntax

nccreate(filename,varname)
nccreate(filename,varname,Name,Value)

Description

nccreate(filename,varname) creates a scalar double variable named varname in the NetCDF file filename. If filename does not exist, nccreate creates the file using the netcdf4_classic format. To create a nonscalar variable, use the Dimensions argument.

nccreate(filename,varname,Name,Value) creates a variable named varname with additional options specified by one or more Name,Value pair arguments.

Input Arguments

filename

Text string specifying a NetCDF file, or the name you want to assign to a new NetCDF file.

varname

Text string specifying the name you want to assign to a variable in a NetCDF file.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

'Dimensions'

Cell array specifying dimensions for the variable in the NetCDF file. The cell array lists the dimension name as a string followed by its numerical length: {dname1,dlength1,dname2,dlength2, ...}. If a dimension exists, specifying its length is optional. Use Inf to specify an unlimited dimension.

All formats other than netcdf4 format files can have only one unlimited dimension per file and it has to be the last in the list specified. A netcdf4 format file can have any number of unlimited dimensions in any order.

A single-dimension variable is always treated as a column vector.

'Datatype'

Text string specifying a MATLAB® data type. When nccreate creates the variable in the NetCDF file, it uses a corresponding NetCDF datatype. The following table describes how MATLAB datatypes map to NetCDF datatypes.

MATLAB Data TypeCorresponding NetCDF Variable Type
doubleNC_DOUBLE
singleNC_FLOAT
int64NC_INT64*
uint64NC_UINT64*
int32NC_INT
uint32NC_UINT*
int16NC_SHORT
uint16NC_USHORT*
int8NC_BYTE
uint8NC_UBYTE*
charNC_CHAR

* These data types are only available when the file is a netcdf4 format file.

'Format'

Text string specifying the type of NetCDF file you want to create.

Format StringDescription
classicNetCDF 3
64bitNetCDF 3, with 64-bit offsets
netcdf4_classicNetCDF 4 classic model
netcdf4NetCDF 4 model (Use this to enable group hierarchy)

If varname specifies a group (e.g.,'/grid3/temperature'), nccreate sets the value of format to 'netcdf4'.

Default: netcdf4_classic

'FillValue'

A scalar specifying the value to use for missing values. To disable fill values, set FillValue to the text string 'disable'. (Available for netcdf4 or netcdf4_classic formats only.)

Default: Value specified by the NetCDF library

'ChunkSize'

Vector specifying the size of the chunk along each dimension, [num_rows,num_cols,..., num_ndims]. (Available for netcdf4 or netcdf4_classic formats only.)

Default: Set by the NetCDF library

'DeflateLevel'

Numeric value between 0 (least) and 9 (most) specifying the compression setting for the deflate filter, or the text string disable. (Available for netcdf4 or netcdf4_classic formats only.)

Default: Disabled

'Shuffle'

Boolean flag to turn on the shuffle filter. (Available for netcdf4 or netcdf4_classic formats only.)

Default: False

Examples

Create a new 2–D variable in a classic format file. Write data to this variable

 nccreate('myncclassic.nc','peaks',...
          'Dimensions',{'r' 200 'c' 200},...
          'Format','classic');
 ncwrite('myncclassic.nc','peaks', peaks(200));
 ncdisp('myncclassic.nc');

See Also

| | | |

Tutorials

Was this topic helpful?