nc_create | R Documentation |
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 )
filename |
Name of the netCDF file to be created. |
vars |
Either an object of class |
force_v4 |
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. |
verbose |
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 dpierce@ucsd.edu
http://dwpierce.com/software
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( "states_population.nc", varPop )
# Write some values to this variable on disk.
popAlabama <- 4447100
ncvar_put( ncnew, varPop, popAlabama, start=1, count=1 )
nc_close(ncnew)
# Clean up example
file.remove( "states_population.nc" )
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.