HDF_VD_WRITE for string data [message #62875] |
Tue, 14 October 2008 05:32  |
Brian
Messages: 27 Registered: March 2001
|
Junior Member |
|
|
I'm attempting to add string data to VDATA. I've been mixing data
types using the HDF_PACKDATA function (float and long in example
below), but can't get the string type to work. Instead of "Test" I get
a 4 byte value.
Any suggestions?
------------------------------------------------------------ ------------------------------------------
PRO testvd
fid = HDF_OPEN('out.hdf', /CREATE)
Vdat = HDF_VD_ATTACH(fid, -1, /WRITE)
HDF_VD_SETINFO, Vdat, NAME='ancillary'
HDF_VD_FDEFINE, Vdat, 'VAR1', /FLOAT, ORDER=1
HDF_VD_FDEFINE, Vdat, 'VAR2', /LONG, ORDER=1
HDF_VD_FDEFINE, Vdat, 'VAR3', /BYTE, ORDER=4
v1 = 134.5
v2 = 30000L
v3 = 'Test'
odata = HDF_PACKDATA(v1,v2,v3,HDF_TYPE=[5,24,4],HDF_ORDER=[0,0,4])
HDF_VD_WRITE,Vdat,'VAR1, VAR2, VAR3',odata
HDF_VD_Detach,Vdat
HDF_CLOSE, fid
END
|
|
|
Re: HDF_VD_WRITE for string data [message #62955 is a reply to message #62875] |
Tue, 14 October 2008 11:42  |
jameskuyper
Messages: 79 Registered: October 2007
|
Member |
|
|
Brian wrote:
> I'm attempting to add string data to VDATA. I've been mixing data
> types using the HDF_PACKDATA function (float and long in example
> below), but can't get the string type to work. Instead of "Test" I get
> a 4 byte value.
>
> Any suggestions?
>
> ------------------------------------------------------------ ------------------------------------------
> PRO testvd
>
> fid = HDF_OPEN('out.hdf', /CREATE)
> Vdat = HDF_VD_ATTACH(fid, -1, /WRITE)
> HDF_VD_SETINFO, Vdat, NAME='ancillary'
> HDF_VD_FDEFINE, Vdat, 'VAR1', /FLOAT, ORDER=1
> HDF_VD_FDEFINE, Vdat, 'VAR2', /LONG, ORDER=1
> HDF_VD_FDEFINE, Vdat, 'VAR3', /BYTE, ORDER=4
>
> v1 = 134.5
> v2 = 30000L
> v3 = 'Test'
>
> odata = HDF_PACKDATA(v1,v2,v3,HDF_TYPE=[5,24,4],HDF_ORDER=[0,0,4])
> HDF_VD_WRITE,Vdat,'VAR1, VAR2, VAR3',odata
>
> HDF_VD_Detach,Vdat
> HDF_CLOSE, fid
>
> END
HDF doesn't have a string type, as such. The closest it comes is an
array of character type. It has special type codes for DFNT_CHAR8 (=4)
and DFNT_UCHAR (=3). These are different type codes than the ones
used for 8 bit integers: DFNT_INT8(=20) and DFNT_UINT8(=21). However,
not all of the IDL HDF routine support all of the possible HDF type
codes. The /BYTE option of HDF_VD_FDEFINE is the only documented
option that produces an 8-bit type, and that type is DFNT_UINT8.
According to the documentation for "IDL and HDF Data Types",
DFNT_CHAR8 is recognized by IDL's routines, and in some unspecified
contexts it is matched up with IDL's string types, but HDF_VD_FDEFINE
is apparantly not one of those contexts.
|
|
|