Hi,
I can create valid variable length string attribute and when I write data to it there is no errors or exception but when I open the file with HdfViewer I can see that it contains Null value.
Could someone explain why I can’t write my data to var-len-str attribute?
#include "hdf5.h"
#define H5FILE_NAME "Attributes.h5"
#define DATASET_RANK 1 /* Rank and size of the dataset */
#define DATASET_SIZE 7
#define ANAMES "Character attribute" /* Name of the string attribute */
int main(int argc, char *argv[])
{
hid_t file, dataset, attr; /* File and dataset identifiers */
hid_t dataset_space, attr_space; /* Dataset's and Attribute's dataspace id */
hid_t attr_type; /* Attribute type */
herr_t status; /* Return value */
hsize_t fdim[] = {DATASET_SIZE};
unsigned char data[] = {'A', 'S', 'D', '\0'}; /* Data to be written to the attribute */
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
dataset_space = H5Screate(H5S_SIMPLE);
status = H5Sset_extent_simple(dataset_space, DATASET_RANK, fdim, NULL);
dataset = H5Dcreate2(file, "my_dataset", H5T_NATIVE_INT, dataset_space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
attr_space = H5Screate(H5S_NULL);
attr_type = H5Tcopy(H5T_C_S1);
status = H5Tset_size(attr_type, H5T_VARIABLE);
status = H5Tset_strpad(attr_type, H5T_STR_NULLTERM);
status = H5Tset_cset(attr_type, H5T_CSET_UTF8);
attr = H5Acreate2(dataset, ANAMES, attr_type, attr_space, H5P_DEFAULT, H5P_DEFAULT);
status = H5Awrite(attr, attr_type, data);
H5Fclose(file);
}