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

**URL:** <https://forum.hdfgroup.org/t/how-to-set-the-array-size-and-value-when-creating-new-attribute/9608>\
**Category:** Uncategorized\
**Created:** [April 1, 2022, 5:14pm UTC](https://forum.hdfgroup.org/t/how-to-set-the-array-size-and-value-when-creating-new-attribute/9608 "2022-04-01T17:14:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kang\_peng](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/k/c5a1d2/32.png) [@kang\_peng](https://forum.hdfgroup.org/u/kang_peng)\
**Post date:** [April 1, 2022, 5:14pm UTC](https://forum.hdfgroup.org/t/how-to-set-the-array-size-and-value-when-creating-new-attribute/9608/1 "2022-04-01T17:14:58Z")

</div>

Hi all,

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

 ![image](https://hdf-discourse-1.s3.amazonaws.com/original/2X/e/e81d1f3c16d5fc1dbcc3ccdab0a417de00b38e73.jpg)  
Could you tell me how to set the array size and value?

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![contact](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/contact/32/1067_2.png) [@contact](https://forum.hdfgroup.org/u/contact)\
**Post date:** [April 1, 2022, 6:58pm UTC](https://forum.hdfgroup.org/t/how-to-set-the-array-size-and-value-when-creating-new-attribute/9608/3 "2022-04-01T18:58:00Z")

</div>

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](https://www.hdfql.com):

```
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!

---

<div class="post-metadata">

**Author:** ![kang\_peng](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/k/c5a1d2/32.png) [@kang\_peng](https://forum.hdfgroup.org/u/kang_peng)\
**Post date:** [April 4, 2022, 4:29pm UTC](https://forum.hdfgroup.org/t/how-to-set-the-array-size-and-value-when-creating-new-attribute/9608/4 "2022-04-04T16:29:20Z")

</div>

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.

 ![59](https://hdf-discourse-1.s3.amazonaws.com/original/2X/9/9dda9adb14334ec6d145155648f81d80865bbb08.jpg)

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.

 ![54](https://hdf-discourse-1.s3.amazonaws.com/original/2X/3/3aedab9bae2600ff4c6bf959992fae194985dc97.jpg)

---

<div class="post-metadata">

**Author:** ![byrn](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@byrn](https://forum.hdfgroup.org/u/byrn)\
**Post date:** [April 5, 2022, 3:11pm UTC](https://forum.hdfgroup.org/t/how-to-set-the-array-size-and-value-when-creating-new-attribute/9608/5 "2022-04-05T15:11:25Z")

</div>

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 */
```
