# 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)
# }
Run the code above in your browser using DataLab