Infer Datatype

Hi,

I am storing 1000's of datasets of different types. In particular two of my types are LONG(any long) and DATETIME(long value representing #nano seconds since UNIX EPOCH). While I experiment LONG uses the H5T_STD_I64BE datatype and currently DATETIME uses H5T_STD_I64LE so I can use the endian flag to distinguish between the two.

Now when this data is read by various systems (in particular Java) and I am looking for an intuitive and efficient way to distinguish between these two datatypes. My current options are:

1. Make DATETIME signed and change EPOCH to 1900 or something.
2. Maked DATATIME little endian, as above.
3. Use a committed datatype.

Have I missed something and is there an alternative way to achieve this?

Thanks,

Matt

Hi,

I am using HDF.PInvoke 1.10.0.4 but I am struggling to read the string value of an attribute when it is variable length.

Ultimately I believe I need to call:

GCHandle hnd = GCHandle.Alloc(*data*, GCHandleType.Pinned);
int err = H5A.read(aid, *typeId*, hnd.AddrOfPinnedObject());
hnd.Free();

Where data is a suitable object.

I am confident that the attribute id (aid) is correct because it works for all the other attributes types.

I am not so confident on the typeId, I have tried:

    H5T.get_type(aid);
* H5T.get_native_type(tid);
    H5T.create(H5T.class_t.VLEN, H5T.VARIABLE);
    H5T.create(H5T.class_t.STRING, H5T.VARIABLE);

Likewise for the data and I have tried:

* data = new byte[256];
     data = new IntPtr[1]; => data[0] = GCHandle.Alloc(byte[256], GCHandleType.Pinned).AddrOfPinnedObject()

The only time some non-zero values were returned was case (*) but then I couldn't relate the values to the expected text.

Thanks,

Matt

What’s the storage layout of the attribute?
(i.e., is it H5S_SIMPLE or H5S_SCALAR?)

G.

···

From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of Matt Wood
Sent: Thursday, March 30, 2017 9:42 AM
To: hdf-forum@lists.hdfgroup.org
Subject: [Hdf-forum] Reading VLEN string attribute values.

Hi,

I am using HDF.PInvoke 1.10.0.4 but I am struggling to read the string value of an attribute when it is variable length.

Ultimately I believe I need to call:

GCHandle hnd = GCHandle.Alloc(data, GCHandleType.Pinned);
int err = H5A.read(aid, typeId, hnd.AddrOfPinnedObject());
hnd.Free();

Where data is a suitable object.

I am confident that the attribute id (aid) is correct because it works for all the other attributes types.

I am not so confident on the typeId, I have tried:

   H5T.get_type(aid);
* H5T.get_native_type(tid);
   H5T.create(H5T.class_t.VLEN, H5T.VARIABLE);
   H5T.create(H5T.class_t.STRING, H5T.VARIABLE);

Likewise for the data and I have tried:

* data = new byte[256];
    data = new IntPtr[1]; => data[0] = GCHandle.Alloc(byte[256], GCHandleType.Pinned).AddrOfPinnedObject()

The only time some non-zero values were returned was case (*) but then I couldn't relate the values to the expected text.

Thanks,

Matt

Try something like this, if you want a single string (not tested):

int byteLength = Marshal.SizeOf(Of IntPtr);
IntPtr intPtr = Marshal.AllocHGlobal(byteLength);

H5A.read(attributeId, attributeTypeId, intPtr);

string result = Marshal.PtrToStringAnsi(intPtr);

If you want a more general way to read multiple strings at once, the code must be modified slightly.

Best regards,
Vincent

···

Von: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] Im Auftrag von Gerd Heber
Gesendet: Donnerstag, 30. März 2017 16:58
An: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org>
Betreff: Re: [Hdf-forum] Reading VLEN string attribute values.

What’s the storage layout of the attribute?
(i.e., is it H5S_SIMPLE or H5S_SCALAR?)

G.

From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of Matt Wood
Sent: Thursday, March 30, 2017 9:42 AM
To: hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>
Subject: [Hdf-forum] Reading VLEN string attribute values.

Hi,

I am using HDF.PInvoke 1.10.0.4 but I am struggling to read the string value of an attribute when it is variable length.

Ultimately I believe I need to call:

GCHandle hnd = GCHandle.Alloc(data, GCHandleType.Pinned);
int err = H5A.read(aid, typeId, hnd.AddrOfPinnedObject());
hnd.Free();

Where data is a suitable object.

I am confident that the attribute id (aid) is correct because it works for all the other attributes types.

I am not so confident on the typeId, I have tried:

   H5T.get_type(aid);
* H5T.get_native_type(tid);
   H5T.create(H5T.class_t.VLEN, H5T.VARIABLE);
   H5T.create(H5T.class_t.STRING, H5T.VARIABLE);

Likewise for the data and I have tried:

* data = new byte[256];
    data = new IntPtr[1]; => data[0] = GCHandle.Alloc(byte[256], GCHandleType.Pinned).AddrOfPinnedObject()

The only time some non-zero values were returned was case (*) but then I couldn't relate the values to the expected text.

Thanks,

Matt