How to set the array size and value when creating new attribute


#1

Hi all,

I’m trying to set an attribute like this, but always failed.


Could you tell me how to set the array size and value?

Thanks,
Peter


#3

Hi @kang_peng,

Looking at the screenshot you posted, it seems that you want to create a one dimensional (size 1) attribute of data type enumeration containing two members: FALSE (with value 0) and TRUE (with value 1). The attribute stores value TRUE (i.e. 1). If this interpretation is correct, you could implement your user-case as follows using HDFql:

CREATE ATTRIBUTE Transient AS ENUMERATION(FALSE AS 0, TRUE AS 1)(1) VALUES(1)

Some notes:

  1. Since the first member has a value of 0 and subsequent members have a value incremented one unit, you could have just done ...AS ENUMERATION(FALSE, TRUE)... when creating the attribute above.
  2. Since the attribute has only one dimension of size 1, you could eventually have it just as a scalar (by removing the first (1) in the code above).
  3. Since the range of values is between 0 and 1 (inclusive), HDFql creates the attribute as an 8 bit enumeration (as this is enough to store such range). If the range of values is wider, HDFql automatically uses more bits to properly store it (i.e. 16 bit, 32 bit or 64 bit).

Hope it helps!


#4

Thanks for your help.

Actually, I used Matlab to create the HDF5 file I needed, but I found that the attributes I created were different from the attributes I wanted to get, and after several attempts, it didn’t work.

Here are the Matlab codes.

h5writeatt('tt.h5','/tide','Dimension', "XY");
h5writeatt('tt.h5','/tide','Discretization', [2.0 3.0]);
h5writeatt('tt.h5','/tide','Origin', [-1.0 -1.0]);
h5writeatt('tt.h5','/tide','Max Buffer Size', int32(4));
h5writeatt('tt.h5','/tide','Transient', "TRUE");
h5writeatt('tt.h5','/tide','Time Units', "d");

This is type of attributes I want to create.

So I tried to create the attribute table manually in HDFView software, but I don’t know how to set the BOOL type attribute, how to set the “Array Size” and “Value”? And I also want to find a method to revise my Matlab code to create the type of attributes I want.

Here is the setting window in HDFView software.


#5

There is not a boolean type in hdf5:
typedef enum H5T_class_t {
H5T_NO_CLASS = -1, /< error */
H5T_INTEGER = 0, /
< integer types */
H5T_FLOAT = 1, /< floating-point types */
H5T_TIME = 2, /
< date and time types */
H5T_STRING = 3, /< character string types */
H5T_BITFIELD = 4, /
< bit field types */
H5T_OPAQUE = 5, /< opaque types */
H5T_COMPOUND = 6, /
< compound types */
H5T_REFERENCE = 7, /< reference types */
H5T_ENUM = 8, /
< enumeration types */
H5T_VLEN = 9, /< variable-Length types */
H5T_ARRAY = 10, /
< array types */

H5T_NCLASSES /**< sentinel: this must be last             */