nc_create: Create a netCDF File

View source: R/ncdf4.R

nc_createR Documentation

Create a netCDF File


Creates a new netCDF file on disk, given the variables the new file is to contain.


 nc_create( filename, vars, force_v4=FALSE, verbose=FALSE )



Name of the netCDF file to be created.


Either an object of class ncvar4 describing the variable to be created, or a vector (or list) of such objects to be created.


If TRUE, then the created output file will always be in netcdf-4 format (which supports more features, but cannot be read by version 3 of the netcdf library). If FALSE, then the file is created in netcdf version 3 format UNLESS the user has requested features that require version 4. Deafult is FALSE.


If TRUE, then information is printed while the file is being created.


This routine creates a new netCDF file on disk. The routine must be called with the variables that will be created in the file. Keep in mind that the new file may not actually be written to disk until nc_close is called. Always call nc_close when you are done with your file, or before exiting R!


An object of class ncdf4, which has the fields described in nc_open.


David W. Pierce


See Also

ncdim_def, ncvar_def.


## Not run: 
# Define an integer dimension 
dimState <- ncdim_def( "StateNo", "count", 1:50 )

# Make an integer variable.  Note that an integer variable can have
# a double precision dimension, or vice versa; there is no fixed
# relationship between the precision of the dimension and that of the
# associated variable.  We just make an integer variable here for
# illustration purposes.
varPop <- ncvar_def("Pop", "count", dimState, -1, 
		longname="Population", prec="integer")

# Create a netCDF file with this variable
ncnew <- nc_create( "", varPop )

# Write some values to this variable on disk.
popAlabama <- 4447100
ncvar_put( ncnew, varPop, popAlabama, start=1, count=1 )


# Clean up example
file.remove( "" )

## End(Not run)

ncdf4 documentation built on Jan. 7, 2023, 1:12 a.m.