[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IDL HDF Question

David Rapchun wrote:
> Is it possible to create an SD in a HDF file that is "growable" i.e.
> I do not know the dimension ahead of time.  This can be a 1D SD, but
> it needs to be growable...

To create a SDS with an unlimited dimension, set the size of the last
dimension to zero in the call to HDF_SD_CREATE, as shown in the
following example:


;- Get data
file = filepath('ctscan.dat', subdir='examples/data')
openr, lun, file, /get_lun
data = bytarr(256, 256)
readu, lun, data
free_lun, lun

;- Create the file
hdfid = hdf_sd_start('ctscan.hdf', /create)
dims = [256L, 0L]    ; NOTE Last dimension is zero
varid = hdf_sd_create(hdfid, 'image', dims, /byte)
hdf_sd_endaccess, varid
hdf_sd_end, hdfid

;- Write the data one row at a time
hdfid = hdf_sd_start('ctscan.hdf', /rdwr)
index = hdf_sd_nametoindex(hdfid, 'image')
varid = hdf_sd_select(hdfid, index)
for row = 0, 255 do begin
  hdf_sd_adddata, varid, data[*, row], start=[0, row]
hdf_sd_endaccess, varid
hdf_sd_end, hdfid


To run the example program:

IDL> .compile test
IDL> test

To check the contents of the file, I used ncdump:

% ncdump -h ctscan.hdf
netcdf ctscan {
        fakeDim0 = UNLIMITED ; // (256 currently)
        fakeDim1 = 256 ;

        byte image(fakeDim0, fakeDim1) ;