Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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 determines the type of file access. Specify cmode as one of these character vectors.

Value of cmodeDescription
'NOCLOBBER'Prevent overwriting of existing file with the same name.
'CLOBBER'Overwrite any existing file with the same name.
'SHARE'Allow synchronous file updates.
'64BIT_OFFSET'Allow easier creation of files and variables which are larger than two gigabytes.
'NETCDF4'Create a NetCDF-4/HDF5 file
'CLASSIC_MODEL'Enforce 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 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)

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?