Go to the previous, next section.

Open a NetCDF File for Access

The function ncopen (or NCOPN for FORTRAN) opens an existing netCDF file for access.

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

ncopen: C Interface

int ncopen(const char* path,int mode);

path
Absolute or relative file name for netCDF file to be opened.

mode
Either NC_WRITE, to open the file for writing, or NC_NOWRITE, to open the file read-only. "Writing" means any kind of change to the file, including appending or changing data, adding or renaming dimensions, variables, and attributes, or deleting attributes.

Here is an example using ncopen to open an existing netCDF file named `foo.nc' for reading:

#include "netcdf.h"
   ...
int ncid;
   ...
ncid = ncopen("foo.nc", NC_NOWRITE);

NCOPN: FORTRAN Interface

      INTEGER FUNCTION NCOPN(CHARACTER*(*) PATH,
     +                       INTEGER RWMODE,
     +                       INTEGER RCODE)

PATH
Absolute or relative file name for netCDF file to be opened.

RWMODE
Either NCWRITE, to open the file for writing, or NCNOWRIT, to open the file read-only. "Writing" means any kind of change to the file, including appending or changing data, adding or renaming dimensions, variables, and attributes, or deleting attributes.

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

Here is an example of using NCOPN to open an existing netCDF file named `foo.nc' for reading:

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID
         ...
      NCID = NCOPN('foo.nc', NCNOWRIT, RCODE)

Go to the previous, next section.