comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: netCDF Read/Write Variable

Re: netCDF Read/Write Variable
type: item
description: 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
creator: Homeyer
date: 2009-03-06T17:08:02-00:00

Re: netCDF Read/Write Variable
type: item
description: 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.")
creator: David Fanning
date: 2009-03-06T17:21:07-00:00