In article <davidf-ya023080002201971346190001@news.frii.com>
davidf@dfanning.com (David Fanning) writes:
> I have three vectors that represent randomly distributed
> longitude and latitude temperature data. Thus, I have three
> variables lat, lon, and temp that are all the same length
> and data type. I want to store them as a VDATA table
> in an HDF file.
>
> Then, I want to grid this data and make a regularly-spaced
> 2D array. I want to store this data in the same HDF file
> as a scientific dataset.
...
I apologize for the earlier incorrect posting (which I have since
deleted). I was playing with routines wrsdf and rdsdf, and
they still had errors.
I am not sure if this is helpful, since I have not tried to
change the shape mid-file, as you wish to, but it may help to
see a simpler example. I agree that the IDL manuals are quite
deceptive, in terms of not indicating that certain calls need to
be made for every variable.
Corrected versions are as follows:
----------File: wrsdf.pro----Cut here--------------------
; ---------------------------WrSDF---------------------------
pro WrSDF,filename,a,varname,frames=frames,palette=palette
; Write array to HDF file in a
; scientific data format.
; (Can be read back with rdsdf.pro.)
; ---------INPUT----------
; filename=Name of file to create.
; a=array to write to file.
; varname=name of variable (optional).
; if /frames is set, and the array
; is 3 dimensional (last dimension
; = # of frames), each frame will
; be written as a seperate HDF
; entry.
; (That is the usual way HDF movies
; are written.)
; if /palette is set, the current
; pallete will be added.
;Written by Mitchell R Grunes.
if n_elements(varname) eq 0 then varname='a'
if n_elements(frames) eq 0 then frames=0
if n_elements(palette) eq 0 then palette=0
if !prompt eq 'IDL> ' then begin
sd_id=HDF_SD_Start(filename,/create)
s=size(a)
vt=s(n_elements(s)-2) ; variable type
if vt lt 1 or vt gt 5 then stop,'Bad Data type in WrHDF'
ndim=s(0) ; # of dimensions
dims=s(1:ndim) ; dimensions
nFrames=1 ; # of frames
if ndim eq 3 and frames then begin
nframes=s(ndim)
dims=dims(0:1)
endif
print,'Adding variable ',a,' to HDF file ',filename
help,a
if ndim eq 3 and frames then begin
print,'Writing array as ',nframes,' frames.'
for i=0,nframes-1 do begin
sds_id=HDF_SD_Create(sd_id,varname,dims,byte=vt eq 1,int=vt eq 2, $
long=vt eq 3,float=vt eq 4,double=vt eq 5)
HDF_SD_AddData,sds_id,reform(a(*,*,i))
HDF_SD_EndAccess,sds_id
endfor
endif else begin
sds_id=HDF_SD_Create(sd_id,varname,dims,byte=vt eq 1,int=vt eq 2, $
long=vt eq 3,float=vt eq 4,double=vt eq 5)
HDF_SD_AddData,sds_id,a
HDF_SD_EndAccess,sds_id
endelse
HDF_SD_End,sd_id
if palette then begin
tvlct,/get,R,G,B
p=transpose([[R],[G],[B]])
hdf_dfp_addpal,filename,p
endif
endif else begin
stop,'My WrSDF stuff only works from IDL, not PV-WAVE.
endelse
end
-----------------------------Cut here--------------------
----------File: rdsdf.pro----Cut here--------------------
; ---------------------------RdSDF---------------------------
pro RdSDF,filename,a,name,number=number; Read array from HDF file in a
; scientific data format.
; ---------INPUT----------
; filename=Name of file to read.
; name (optional) specifies the array
; name to read.
; Number (optional)=0-origin sequence
; number of variable in file.
; ---------OUTPUT---------
; a=array to read from file
; name=name of variable.
; number=sequence number of variable.
;Written by Mitchell R Grunes.
if n_elements(number) eq 0 then number=0
loop:
if !prompt eq 'IDL> ' then begin
sd_id=HDF_SD_Start(filename,/read)
sds_id=hdf_sd_select(sd_id,number)
HDF_SD_GetInfo,sds_id,name=name2
print,'Sequence number=',number,' Variable Name=',name2
if n_elements(name) gt 0 then begin
if name ne name2 then begin
number=number+1
print,'Trying next sequence number.'
HDF_SD_EndAccess,sds_id
goto,loop
endif
endif
HDF_SD_GetData,sds_id,a
HDF_SD_EndAccess,sds_id
HDF_SD_End,sd_id
endif else begin
stop,'My RdSDF stuff only works from IDL, not PV-WAVE.
endelse
end
-----------------------------Cut here--------------------
------------------------------------------------------------ --------
Mitchell R Grunes, grunes@imsy1.nrl.navy.mil. Opinions are mine alone.
|