Saving to netCDF [message #7761] |
Thu, 16 January 1997 00:00  |
mal3p
Messages: 13 Registered: June 1994
|
Junior Member |
|
|
This is probably a no-brainer, but I don't have time right
now to figure how to do this: I'd like to be able to save variables-
including arrays and arrays of structures, to one of the public
domain scientific formats. Ideally, I would like to be able to "save"
the session's current variables to such a file.
Michael Lefsky
--
|
|
|
|
Re: Saving to netCDF [message #7888 is a reply to message #7761] |
Fri, 17 January 1997 00:00  |
agraps
Messages: 35 Registered: September 1994
|
Member |
|
|
mal3p@faraday.clas.Virginia.EDU (Michael A. Lefsky) writes:
> This is probably a no-brainer, but I don't have time right
> now to figure how to do this: I'd like to be able to save variables-
> including arrays and arrays of structures, to one of the public
> domain scientific formats. Ideally, I would like to be able to "save"
> the session's current variables to such a file.
Actually I thought netCDF was a really nonintuitive format, so I
wouldn't call it a no-brainer. It seems unneccessarily complicated to
me. I spent a day or so trying to understand how reading and writing
in netCDF works.
I cannibalized one of my programs to give you this netCDF example. It
should work, but I haven't tested these code fragments, so no
guarantees. Here it goes.
Amara
-----------------------------------------------------------
Say you have a volume of data: call it "freqcube" dimensions float(x,y,f).
And say that you have a long string that describes the data, say "header"
And say that you want to create a netCDF file called "freq.nc"
;-----------------------
;Write out netCDF data
;-----------------------
;Create file
cd,'/tmp20/amara/'
newfile = 'freq.nc'
id_main = NCDF_CREATE(newfile,/CLOBBER)
IF (id_main eq -1) THEN BEGIN
PRINT, 'Unable to create file ', newfile
RETURN
END
;I will write out one attribute of "header" and one of "data".
;------------------
;Header Definition
;------------------
hsize = N_ELEMENTS(header)
dimheader = NCDF_DIMDEF(id_main, 'dimheader', /unlimited)
id_header = NCDF_VARDEF(id_main, 'header', dimheader, /char)
;---------------
;Data Definition
;---------------
sz = SIZE(freqcube)
xdim = sz(1)
ydim = sz(2)
zdim = sz(3)
xid = NCDF_DIMDEF(id_main,'x',xdim)
yid = NCDF_DIMDEF(id_main,'y',ydim)
zid = NCDF_DIMDEF(id_main,'z',zdim)
id_freq = NCDF_VARDEF(id_main,'freqcube',[xid,yid,zid],/FLOAT)
;End Definition
NCDF_CONTROL, id_main, /endef
print, ' '
print, 'Writing Variable Information..'
print, ' '
;------------
;Header Write
;------------
;Write header line into the one netCDF 'header' variable.
NCDF_VARPUT, id_main, id_header, header
;----------
;Data Write
;----------
print, ' '
print, 'Writing Variable Data..'
print, ' '
NCDF_VARPUT, id_main, id_freq, freqcube
NCDF_CLOSE, id_main
-----------------------------------------------------------
--
************************************************************ *************
Amara Graps email: agraps@netcom.com
Computational Physics vita: finger agraps@best.com
Multiplex Answers URL: http://www.amara.com/
************************************************************ *************
|
|
|