Go to the previous, next section.

Create a NetCDF file

The function nccreate (or NCCRE for FORTRAN) creates a new netCDF file, returning a netCDF ID that can subsequently be used to refer to the netCDF file. The new netCDF file is placed in define mode.

In case of an error, nccreate returns -1; NCCRE returns a nonzero value in rcode. Possible causes of errors include::

nccreate: C Interface

int nccreate (const char* path, int cmode);

path
The file name of the new netCDF file. This can be given as either an absolute path name (from the root of the file system) or a relative path name (from the current directory).

cmode
Should be specified as either NC_CLOBBER or NC_NOCLOBBER. These constants are defined in the include file named `netcdf.h'. NC_CLOBBER means that even if the file already exists, you want to create a new file with the same name, erasing the old file's contents. NC_NOCLOBBER means you want to create a new netCDF file only if the given file name does not refer to a file that already exists.

In this example we create a netCDF file named `foo.nc'; we want the file to be created in the current directory only if a file with that name does not already exist:

#include "netcdf.h"
   ...
int ncid;
   ...
ncid = nccreate("foo.nc", NC_NOCLOBBER);

NCCRE: FORTRAN Interface

INTEGER FUNCTION NCCRE (CHARACTER*(*) PATH, INTEGER CMODE,
                        INTEGER RCODE)

PATH
The file name of the new netCDF file. This can be given as either an absolute path name (from the root of the file system) or a relative path name (from the current directory).

CMODE
Should be specified as either NCCLOB or NCNOCLOB. These constants are defined in the include file `netcdf.inc'. NCCLOB means that even if the file already exists, you want to create a new file with the same name, erasing the old file's contents. NCNOCLOB means you want to create a new netCDF file only if the given file name does not refer to a file that already exists.

RCODE
Returned error code. If no errors occurred, 0 is returned.

In this example we create a netCDF file named `foo.nc', assuming we want the file to be created in the current directory only if a file with that name does not already exist:

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID
         ...
      NCID = NCCRE('foo.nc', NCNOCLOB, RCODE)

Go to the previous, next section.