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

Home » Public Forums » archive » writing fixed-length string arrays to netcdf-4
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: writing fixed-length string arrays to netcdf-4 [message #86390 is a reply to message #86389] Mon, 04 November 2013 10:48 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Well, I don't know. My NCDF_File object seems to do it just fine.

Here is essentially the same program, but using string arrays.

;----------------------------------------------------------- ----------
; Create a ncdf file with variable length and fixed length strings.
fileObj = Obj_New('ncdf_file', 'tester.nc', /Clobber, /Create)
fileObj -> WriteDim, 'xdim', [10], OBJECT=xdimObj
fileObj -> WriteDim, 'ydim', [3], OBJECT=ydimObj
dimNames = [xdimObj->GetName(), ydimObj->GetName()]
v1 = ['cat','coyote','elephant']
v2 = String(v1, Format='(A10)')
fileObj -> WriteVarDef, 'v11', dimNames, DATATYPE='STRING', OBJECT=v1Obj
fileObj -> WriteVarDef, 'v22', dimNames, DATATYPE='STRING', OBJECT=v2Obj

fileObj -> WriteVarData, v1Obj, v1
fileObj -> WriteVarData, v2Obj, v2

fileObj -> Sync
Obj_Destroy, fileObj


; Read the data out of the file.
fObj = Obj_New('ncdf_file', 'tester.nc')
v_1 = fObj -> GetVarData('v11')
v_2 = fObj -> GetVarData('v22')
Help, v_1, v_2
Obj_Destroy, fObj
END
;----------------------------------------------------------- ----------

Here is what I get when I run it.

IDL> .go
V_1 STRING = Array[3]
V_2 STRING = Array[3]
IDL> print, v_1
cat coyote elephant
IDL> print, v_2
cat coyote elephant

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Difficulty in succesfully creating a runtime app
Next Topic: derivative function in IDL similar as DIFF in matlab

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

Current Time: Wed Oct 08 18:38:54 PDT 2025

Total time taken to generate the page: 0.00826 seconds