H5Tvlen_create type problem.


#1

Hello all,

I am currently writing some code like below and used version 1.12.1-2.
But seems doesn’t work add value of variable length when to set H5T_NATIVE_UINT.
But works ok case of H5T_NATIVE_INT.

hid_t vlen_t = H5Tvlen_create(H5T_NATIVE_UINT); // H5T_NATIVE_INT ok.

How can i fix?

Thanks.

typedef struct {
	hvl_t nodes;
} __BAR;

hid_t bar_t = H5Tcreate (H5T_COMPOUND, sizeof (__BAR));
hid_t vlen_t = H5Tvlen_create(H5T_NATIVE_UINT);
status = H5Tinsert (bar_t, "nodes", HOFFSET (__BAR, nodes), vlen_t);

std::vector<__BAR> data_bar;

int size=2;
unsigned int *data = (unsigned int*)malloc((size+1) * sizeof(unsigned int));
for(unsigned int i=0; i<size; i++) {
	((unsigned int*)data)[i] = i;
}

__BAR v;
v.nodes.p = data;
v.nodes.len = nodes.size();
data_bar.push_back(v);

hsize_t  dims[1] = {data_bar.size()};
hid_t space = H5Screate_simple (1, dims, NULL);
hid_t dset = H5Dcreate (file, "/bars", bar_t, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite (dset, bar_t, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data_bar[0] );

#2

An incomplete MWE requires the reader to augment the snippet with the missing parts. Can you provide a Minimum Working Example that demonstrates the problem?
best wishes: steve


#3

Thanks reply.

Here is a reproduce code.
If I just change from H5T_NATIVE_UINT to H5T_NATIVE_INT seems to ok.

This is added value in nodes field with H5T_NATIVE_INT
{(0, 1)}

This is added value in nodes field with H5T_NATIVE_UINT
{}

But I have to use unsigned int type.
How can I fix?

#include <hdf5.h>
#include <vector>
#include <stdlib.h>

typedef struct {
	hvl_t nodes;
} __BAR;


int main(void)
{
	hid_t file = H5Fcreate("a.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

	hid_t bar_t = H5Tcreate (H5T_COMPOUND, sizeof (__BAR));
	hid_t vlen_t = H5Tvlen_create(H5T_NATIVE_UINT);
	herr_t status = H5Tinsert (bar_t, "nodes", HOFFSET (__BAR, nodes), vlen_t);

	std::vector<__BAR> data_bar;

	int size=2;
	unsigned int *data = (unsigned int*)malloc((size+1) * sizeof(unsigned int));
	for(unsigned int i=0; i<size; i++) {
		((unsigned int*)data)[i] = i;
	}

	__BAR v;
	v.nodes.p = data;
	v.nodes.len = size;
	data_bar.push_back(v);

	hsize_t  dims[1] = {data_bar.size()};
	hid_t space = H5Screate_simple (1, dims, NULL);
	hid_t dset = H5Dcreate (file, "/bars", bar_t, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	H5Dwrite (dset, bar_t, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data_bar[0] );
}

#4

What’s the error message you are getting? Your code builds and runs just fine for me. The output looks like this

h5dump a.h5 
HDF5 "a.h5" {
GROUP "/" {
   DATASET "bars" {
      DATATYPE  H5T_COMPOUND {
         H5T_VLEN { H5T_STD_U32LE} "nodes";
      }
      DATASPACE  SIMPLE { ( 1 ) / ( 1 ) }
      DATA {
      (0): {
            (0, 1)
         }
      }
   }
}
}

G.


#5

Ditto with signed integers:

h5dump a.h5 
HDF5 "a.h5" {
GROUP "/" {
   DATASET "bars" {
      DATATYPE  H5T_COMPOUND {
         H5T_VLEN { H5T_STD_I32LE} "nodes";
      }
      DATASPACE  SIMPLE { ( 1 ) / ( 1 ) }
      DATA {
      (0): {
            (0, 1)
         }
      }
   }
}
}

#6

Same here @gheber@inhak.min why the variable length datatype? as opposed to say using fixed length with compression?
Also: __ are reserved in C and C++: Rule 16 Do not use identifiers which begin with one or two underscores (_’ or __').


#7

Thanks for reply gheber.

Compile is ok too for me.
But added value is wrong with H5T_NATIVE_UINT.
H5T_NATIVE_UINT is ok.


#8

I found problem.
My code is all ok regarding H5T_NATIVE_INT & H5T_NATIVE_UINT.

HDF5 "C:/temp/a.h5" {
GROUP "/" {
   DATASET "bars" {
      DATATYPE  H5T_COMPOUND {
         H5T_VLEN { H5T_STD_I32LE} "nodes";
      }
      DATASPACE  SIMPLE { ( 1 ) / ( 1 ) }
      DATA {
      (0): {
            (0, 1)
         }
      }
   }
}
}

HDF5 "C:/temp/a.h5" {
GROUP "/" {
   DATASET "bars" {
      DATATYPE  H5T_COMPOUND {
         H5T_VLEN { H5T_STD_U32LE} "nodes";
      }
      DATASPACE  SIMPLE { ( 1 ) / ( 1 ) }
      DATA {
      (0): {
            (0, 1)
         }
      }
   }
}
}

Just HDFView 3.1.3 was wrong displayed.

Thanks.


#9

How was HDFView displaying wrong?


#10

HDFView was shown like below.

Case of H5T_NATIVE_INT
nodes
{(0, 1)}

Case of H5T_NATIVE_UINT
nodes
{}