Next: , Previous: NF_CREATE, Up: Datasets


2.6 NF__CREATE

This function is a variant of NF_CREATE, NF__CREATE (note the double underscore) allows users to specify two tuning parameters for the file that it is creating. These tuning parameters are not written to the data file, they are only used for so long as the file remains open after an NF__CREATE.

This function creates a new netCDF dataset, returning a netCDF ID that can subsequently be used to refer to the netCDF dataset in other netCDF function calls. The new netCDF dataset opened for write access and placed in define mode, ready for you to add dimensions, variables, and attributes.

A creation mode flag specifies whether to overwrite any existing dataset with the same name and whether access to the dataset is shared.

Usage

     INTEGER FUNCTION NF__CREATE (CHARACTER*(*) PATH, INTEGER CMODE, INTEGER INITIALSZ,
                                 INTEGER BUFRSIZEHINT, INTEGER ncid)
PATH
The file name of the new netCDF dataset.
CMODE
The creation mode flag. The following flags are available: NF_NOCLOBBER, NF_SHARE, NF_64BIT_OFFSET, NF_NETCDF4, and NF_CLASSIC_MODEL.

Setting NF_NOCLOBBER means you do not want to clobber (overwrite) an existing dataset; an error (NF_EEXIST) is returned if the specified dataset already exists.

The NF_SHARE flag is appropriate when one process may be writing the dataset and one or more other processes reading the dataset concurrently; it means that dataset accesses are not buffered and caching is limited. Since the buffering scheme is optimized for sequential access, programs that do not access data sequentially may see some performance improvement by setting the NF_SHARE flag. This flag has no effect with netCDF-4/HDF5 files.

Setting NF_64BIT_OFFSET causes netCDF to create a 64-bit offset format file, instead of a netCDF classic format file. The 64-bit offset format imposes far fewer restrictions on very large (i.e. over 2 GB) data files. See Large File Support.

Setting NF_CLASSIC_MODEL causes netCDF to enforce the classic data model in this file. (This only has effect for netCDF-4/HDF5 files, as classic and 64-bit offset files always use the classic model.) When used with NF_NETCDF4, this flag ensures that the resulting netCDF-4/HDF5 file may never contain any new constructs from the enhanced data model. That is, it cannot contain groups, user defined types, multiple unlimited dimensions, or new atomic types. The advantage of this restriction is that such files are guarenteed to work with existing netCDF software.

A zero value (defined for convenience as NF_CLOBBER) specifies the default behavior: overwrite any existing dataset with the same file name and buffer and cache accesses for efficiency. The dataset will be in netCDF classic format. See NetCDF Classic Format Limitations.

INITIALSZ
This parameter sets the initial size of the file at creation time.
BUFRSIZEHINT
The argument referenced by BUFRSIZEHINT controls a space versus time tradeoff, memory allocated in the netcdf library versus number of system calls.

Because of internal requirements, the value may not be set to exactly the value requested. The actual value chosen is returned by reference.

Using the value NF_SIZEHINT_DEFAULT causes the library to choose a default. How the system chooses the default depends on the system. On many systems, the "preferred I/O block size" is available from the stat() system call, struct stat member st_blksize. If this is available it is used. Lacking that, twice the system pagesize is used.

Lacking a call to discover the system pagesize, we just set default bufrsize to 8192.

The BUFRSIZE is a property of a given open netcdf descriptor ncid, it is not a persistent property of the netcdf dataset.

ncid
Returned netCDF ID.

Errors

NF__CREATE returns the value NF_NOERR if no errors occurred. Possible causes of errors include:

Example

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

     INCLUDE 'netcdf.inc'
       ...
     INTEGER NCID, STATUS, INITIALSZ, BUFRSIZEHINT
     ...
     INITIALSZ = 2048
     BUFRSIZEHINT = 1024
     STATUS = NF__CREATE('foo.nc', NF_NOCLOBBER, INITIALSZ, BUFRSIZEHINT, NCID)
     IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)