On Wed, Sep 7, 2011 at 2:25 PM, Ross Maidment <
R.I.Maidment@pgr.reading.ac.uk> wrote:

> Hi,
>
> I am using the package ncdf to create netCDF files and I want to mimic the
> the header of an exiting netCDF file created outside of R. Below is what the
> existing header looks like (part of it that is different):
>
> netcdf ccd1984_05_08 {
> dimensions:
>        lat = 1974 ;
> [...listings omitted...]
> I am unable to replicate the variables attributes that exist in the first
> example in the second example. Is there anyway to transfer across the header
> information or edit the ncdf package to do this?
>

Hi Ross,

to specify the units attribute in the output file, you just set the units
parameter correctly when calling dim.def.ncdf. Since your ncdf-created file
has blank units attributes, I can only assume your R code is doing something
like this:

dim_lon <- dim.def.ncdf( 'lon', "", lonvals )

when it should be doing something more like this:

dim_lon <- dim.def.ncdf( 'lon', "degrees_east", lonvals ), etc.

Easiest way to "copy" a dimension is R code like this:

file2copy = 'old_file.nc'
ncid_old = open.ncdf( file2copy )
dim2copy = "lon"
old_dim = ncid_old$dim[[ dim2copy ]]
new_dim = dim.def.ncdf( old_dim$name, old_dim$units, old_dim$vals,
unlim=old_dim$unlim, longname=old_dim$longname )

For attributes other than units, you can use the att.put.ncdf() call. You
make this call AFTER you have created the output file:

...
ncid_out = create.ncdf( 'new_output_file.nc',
list(output_vars1,...,output_varN))

att.put.ncdf( ncid_out, 'lat', 'axis', 'Y' )
att.put.ncdf( ncid_out, 'ccd', 'Unit_duration', 7.5 )

etc.

--Dave


>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
David W. Pierce
Division of Climate, Atmospheric Science, and Physical Oceanography
Scripps Institution of Oceanography
(858) 534-8276 (voice)  /  (858) 534-8561 (fax)    dpierce@ucsd.edu

	[[alternative HTML version deleted]]

