Create new NetCDF dataset


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


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

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,mode,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.


This example creates a netCDF dataset named, 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('','NOCLOBBER');

This example creates a netCDF-4 file that uses the classic model.

mode = netcdf.getConstant('NETCDF4');
mode = bitor(mode,netcdf.getConstant('CLASSIC_MODEL'));
ncid = netcdf.create('',mode);
Was this topic helpful?