[R] [ncdf] programmatically copying a netCDF file
Tom Roche
Tom_Roche at pobox.com
Fri Jan 6 00:29:35 CET 2012
How to programmatically (i.e., without no or minimal handcoding) copy
a netCDF file? (Without calling
> system("cp whatever wherever")
:-) Why I ask:
I need to "do surgery" on a large netCDF file (technically an I/O API
file which uses netCDF). My group believes a data-assimilation error
caused a data variable to be corrupted in a certain way, so I'm going
to "decorrupt" it so we can compare values with the raw data. Thanks
to help from this list,
* I understand that, generally, R wants value semantics (though
mechanisms like package=proto allow reference semantics). Therefore,
ISTM, rather than attempting to modify a (copy of a) file in-place,
I should instead [copy the bits I want to keep from the source file
to the new/target file, read the one data variable I want to modify
from the source file, write the one modified datavar to the target
file]. (Please correct me if wrong!)
* I have a routine that (I believe) does the desired modification of
the one datavar.
And from reading `help(*ncdf)` and
http://www.image.ucar.edu/Software/Netcdf/
I believe (ICBW :-) I understand the definition, get, and put steps
that are involved in reading and writing netCDF. However,
* the file I'm working with is large and complex
* the examples above hand-craft their output files
So I'm wondering, can anyone point me to, or provide, code that copies
a netCDF file both
* completely: all coordinate variables, all data variables and their
attributes, and all global attributes, such that
$ diff -wB <( ncdump -h source.nc ) <( ncdump -h target.nc ) | wc -l
0
* programmatically: no or minimal hand-coding of, e.g., attribute
names and values, missing-value value.
? If not, can this be done in principle, or are there steps that must
(at least currently) necessarily be hand-coded?
TIA, Tom Roche <Tom_Roche at pobox.com>
More information about the R-help
mailing list