comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: netCDF Read/Write Variable
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: netCDF Read/Write Variable [message #65488] Fri, 06 March 2009 09:21
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Homeyer writes:

> Ive attached some test code to illustrate the process.

Thank you, I appreciate it. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: netCDF Read/Write Variable [message #65489 is a reply to message #65488] Fri, 06 March 2009 09:08 Go to previous message
Homeyer is currently offline  Homeyer
Messages: 9
Registered: March 2009
Junior Member
On Mar 6, 7:19 am, David Fanning <n...@dfanning.com> wrote:
> Folks,
>
> Rather than fooling around with this for an hour while I have
> better things to do, I thought I would just ask.
>
> Would it be possible to read a single variable out of
> an netCDF file, massage it a bit, and then stick it
> back into the same file? Presume that I (a) don't change
> the variable dimensions or type, and (b) do change the variable
> dimensions or type.
>
> Thanks,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

David,

Ive attached some test code to illustrate the process. First, creating
a simple netCDF:

IDL> id = NCDF_CREATE('test.nc')
IDL> xid = NCDF_DIMDEF(id, 'x', 20)
IDL> vid = NCDF_VARDEF(id, 'y', [xid], /FLOAT)
IDL> NCDF_CONTROL, id, /ENDEF
IDL> NCDF_VARPUT, id, 'y', FINDGEN(20)
IDL> NCDF_CLOSE, id

For situation (a), it is simple:

IDL> id = NCDF_OPEN('test.nc', /WRITE)
IDL> NCDF_VARGET, id, 'y', values
IDL> values2 = 2.0*VALUES
IDL> NCDF_VARPUT, id, 'y', values2, OFFSET = 0
IDL> NCDF_CLOSE, id

For situation (b), I am not aware of a way to redefine a netCDF
dimension or variable. However, an alternative solution would be to
rename the old dimension and data and write a new dimension and data
for the massaged version:

IDL> id = NCDF_OPEN('test.nc', /WRITE)
IDL> NCDF_CONTROL, id, /REDEF
IDL> NCDF_DIMRENAME, id, 'x', 'x_old'
IDL> NCDF_VARRENAME, id, 'y', 'y_old'
IDL> xid = NCDF_DIMDEF(id, 'x', 21)
IDL> vid = NCDF_VARDEF(id, 'y', [xid], /LONG)
IDL> NCDF_CONTROL, id, /ENDEF
IDL> NCDF_VARPUT, id, 'y', LINDGEN(21)
IDL> NCDF_CLOSE, id

Cheers,
Cameron Homeyer
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: R for Astronomers
Next Topic: Treating an object as a structure

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:13:53 PDT 2025

Total time taken to generate the page: 0.00504 seconds