Closed lucasbanting closed 1 year ago
Can you elaborate what you mean by "write out"? Do you mean you want to encode the attribute in the HDF5 as ASCII ?
I’be added an attribute ‘Type’ to my file as:
GROUP “VTKHDF” { ATTRIBUTE “Type” { DATATYPE H5T_STRING { STRSIZE 16; STRPAD H5T_STR_NULLTERM; CSET H5T_CSET_UTF8; CTYPE H5T_C_S1; } DATASPACE SCALAR DATA { (0): “UnstructuredGrid” } }
And I would like CSET to be ASCII instead of UTF-8.
I'm not sure how you created the type, but here's the low level commands.
julia> h5t = HDF5.Datatype(HDF5.API.h5t_create(HDF5.API.H5T_STRING, 16))
HDF5.Datatype: H5T_STRING {
STRSIZE 16;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}
julia> HDF5.API.h5t_set_cset(h5t, HDF5.API.H5T_CSET_UTF8); h5t
HDF5.Datatype: H5T_STRING {
STRSIZE 16;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_UTF8;
CTYPE H5T_C_S1;
}
julia> HDF5.API.h5t_set_cset(h5t, HDF5.API.H5T_CSET_ASCII); h5t
HDF5.Datatype: H5T_STRING {
STRSIZE 16;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}
This is what I ended up doing:
type = "UnstructuredGrid"
dspace = HDF5.dataspace(type)
dtype = HDF5.datatype(type)
HDF5.h5t_set_cset(dtype, HDF5.H5T_CSET_ASCII)
attr = create_attribute(VTKHDF, "Type", dtype, dspace)
write_attribute(attr, dtype, type)
How can I output a string attribute as ascii instead of utf-8?
I imagine it may involves creating a custom Datatype?
Forum post: https://discourse.julialang.org/t/writing-a-hdf5-attribute-as-an-ascii-string-in-hdf5-jl/98450