Go to the previous, next section.

Synchronize an Open NetCDF File to Disk

The function ncsync (or NCSNC for FORTRAN) makes sure that the disk copy of a netCDF file open for writing is current. The netCDF file must be in data mode. A netCDF file in define mode is synchronized to disk only when ncendef (or NCENDF) is called. A process that is reading a netCDF file that another process is writing can also call ncsync (or NCSNC for FORTRAN) to get updated with the changes made by the writing process (e.g. the number of records written), without having to close and reopen the file.

It can be expensive in computer resources to always synchronize to disk after every write of variable data or change of an attribute value. There are two reasons you might want to synchronize after writes:

Data is automatically synchronized to disk when a netCDF file is closed, or whenever you leave define mode.

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

ncsync: C Interface

int ncsync(int ncid);

ncid
NetCDF ID, returned from a previous call to ncopen or nccreate.

Here is an example using ncsync to synchronize the disk writes of a netCDF file named `foo.nc':

#include "netcdf.h"
   ...
int ncid;
   ...
ncid = ncopen("foo.nc", NC_WRITE);  /* open for writing */

   ...          /* write data or change attributes */

ncsync(ncid);      /* synchronize to disk */

NCSNC: FORTRAN Interface

      SUBROUTINE NCSNC(INTEGER NCID, INTEGER RCODE)

NCID
NetCDF ID, returned from a previous call to NCOPN or NCCRE.

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

Here is an example using NCSNC to synchronize the disk writes of a netCDF file named `foo.nc':

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID, RCODE
         ...
      NCID = NCOPN('foo.nc', NCWRITE, RCODE)
         ...
* write data or change attributes
         ...
      CALL NCSNC(NCID, RCODE)

Go to the previous, next section.