Open a NetCDF Dataset

View source: R/RNetCDF.R

open.ncR Documentation

Open a NetCDF Dataset


Open an existing NetCDF dataset for reading and (optionally) writing.

Usage, write=FALSE, share=FALSE, prefill=TRUE, diskless=FALSE, persist=FALSE,
           mpi_comm=NULL, mpi_info=NULL, ...)



Filename of the NetCDF dataset to be opened. If the underlying NetCDF library supports OPeNDAP, con may be an OPeNDAP URL.


If FALSE (default), the dataset will be opened read-only. If TRUE, the dataset will be opened read-write.


The buffer scheme. If FALSE (default), dataset access is buffered and cached for performance. However, if one or more processes may be reading while another process is writing the dataset, set to TRUE.


The prefill mode. If TRUE (default), newly defined variables are initialised with fill values when they are first accessed. This allows unwritten array elements to be detected when reading, but it also implies duplicate writes if all elements are subsequently written with user-specified data. Enhanced write performance can be obtained by setting prefill=FALSE.


When diskless=TRUE, the file is read entirely into memory, and any changes are kept in memory without writing to disk. The netcdf library may ignore this option for files in netcdf4 format.


When persist=TRUE, a file opened with diskless=TRUE is flushed to disk when closed. In some cases, this may be faster than manipulating files directly on disk.


Fortran handle of MPI communicator for parallel I/O. The default of NULL implies serial I/O. Valid Fortran handles may be obtained from your chosen MPI package for R - for example comm.c2f or mpi.comm.c2f.


Fortran handle of MPI Info object for parallel I/O. The default value NULL specifies that the MPI_INFO_NULL object is used. Other valid Fortran handles may be obtained from your chosen MPI package for R - for example info.c2f.


Arguments passed to or from other methods (not used).


This function opens an existing NetCDF dataset for access. By default, the dataset is opened read-only. If write=TRUE, then the dataset can be changed. This includes appending or changing data, adding dimensions, variables, and attributes.


Object of class NetCDF which points to the NetCDF dataset, returned invisibly.


Pavel Michna, Milton Woods



##  Create a void NetCDF dataset
file1 <- tempfile("open_", fileext=".nc")
nc <-

##  Open the NetCDF dataset for writing
nc <-, write=TRUE)

RNetCDF documentation built on Oct. 23, 2023, 9:06 a.m.