Documentation

netcdf.create

Create new NetCDF dataset

Syntax

ncid = netcdf.create(filename,cmode)
[chunksize_out,ncid] = netcdf.create(filename,cmode,initsz,chunksize)

Description

ncid = netcdf.create(filename,cmode) creates a new NetCDF file according to the file creation mode. The return value ncid is a file ID. The cmode parameter is a text string that describes the type of file access, which can have any of the following values.

Value of cmodeDescription
NOCLOBBERPrevent overwriting of existing file with the same name.
CLOBBEROverwrite any existing file with the same name.
SHAREAllow synchronous file updates.
64BIT_OFFSETAllow easier creation of files and variables which are larger than two gigabytes.
NETCDF4Create a NetCDF-4/HDF5 file
CLASSIC_MODELEnforce the classic model; has no effect unless used in a bitwise-or with NETCDF4

    Note:   You can specify the mode as a numeric value, retrieved using the netcdf.getConstant function. To specify more than one mode, use a bitwise-OR of the numeric values of the modes.

[chunksize_out,ncid] = netcdf.create(filename,cmode,initsz,chunksize) creates a new NetCDF file, but with additional performance tuning parameters. initsz sets the initial size of the file. chunksize can affect I/O performance. The actual value chosen by the NetCDF library might not correspond to the input value.

This function corresponds to the nc_create and nc__create functions in the NetCDF library C API. To use this function, you should be familiar with the NetCDF programming paradigm. See netcdf for more information.

Examples

collapse all

Create NetCDF File Without Overwriting Existing File

Create a NetCDF dataset named foo.nc, only if no other file with the same name exists in the current directory. To run this example, you must have write permission in your current directory.

ncid = netcdf.create('foo.nc','NOCLOBBER')
ncid =

       65536

netcdf.create returns a file identifier.

Close the file

netcdf.close(ncid)

Create NetCDF-4 File Using Classic Model

Get the numeric values corresponding to the NETCDF4 and CLASSIC_MODEL constants defined by the NetCDF library. Use a bitwise-OR of the numeric values to specify more than one creation mode.

cmode = netcdf.getConstant('NETCDF4');
cmode = bitor(cmode,netcdf.getConstant('CLASSIC_MODEL'));

Create a NetCDF-4 file that uses the classic model by specifying the creation mode value, cmode.

ncid = netcdf.create('myfile.nc',cmode);

Close the file.

netcdf.close(ncid);
Was this topic helpful?