MUQ  0.4.3
HDF5Types.cpp
Go to the documentation of this file.
2 #include <iostream>
3 
4 using namespace muq::Utilities;
5 
7 {
8  if (sizeof(bool) == sizeof(int)) {
9  return H5T_NATIVE_INT;
10  } else if (sizeof(bool) == sizeof(short)) {
11  return H5T_NATIVE_SHORT;
12  } else if (sizeof(bool) == sizeof(char)) {
13  return H5T_NATIVE_CHAR;
14  } else {
15  return H5T_NATIVE_CHAR; //safe default, don't read more than one byte
16  }
17 }
18 
20  const char *obj_name,
21  const char *attr_name,
22  hid_t mem_type_id,
23  void *buffer,
24  size_t size)
25 {
26  if (mem_type_id == H5T_NATIVE_DOUBLE) {
27  return H5LTset_attribute_double(loc_id, obj_name, attr_name, (double *)buffer, size);
28  } else if (mem_type_id == H5T_NATIVE_FLOAT) {
29  return H5LTset_attribute_float(loc_id, obj_name, attr_name, (float *)buffer, size);
30  } else if (mem_type_id == H5T_NATIVE_INT) {
31  return H5LTset_attribute_int(loc_id, obj_name, attr_name, (int *)buffer, size);
32  } else if (mem_type_id == H5T_NATIVE_UINT) {
33  return H5LTset_attribute_uint(loc_id, obj_name, attr_name, (unsigned *)buffer, size);
34  } else if (mem_type_id == H5T_NATIVE_SHORT) {
35  return H5LTset_attribute_short(loc_id, obj_name, attr_name, (short *)buffer, size);
36  } else if (mem_type_id == H5T_NATIVE_CHAR) {
37  return H5LTset_attribute_char(loc_id, obj_name, attr_name, (char *)buffer, size);
38  } else {
39  return -1;
40  }
41  return -1;
42 }
43 
44 
45 std::string muq::Utilities::H5TypeToString(hid_t type)
46 {
47  if(type==H5T_NATIVE_DOUBLE){
48  return "double";
49  }else if(type==H5T_NATIVE_LDOUBLE){
50  return "long double";
51  }else if(type==H5T_NATIVE_INT){
52  return "int";
53  }else if(type==H5T_NATIVE_LONG){
54  return "long";
55  }else if(type==H5T_NATIVE_ULONG){
56  return "unsigned long";
57  }else if(type==H5T_NATIVE_UINT){
58  return "unsigned int";
59  }else if(type==H5T_NATIVE_FLOAT){
60  return "float";
61  }else if(type==H5T_NATIVE_USHORT){
62  return "unsigned short";
63  }else if(type==H5T_NATIVE_SHORT){
64  return "short";
65  }else if(type==H5T_NATIVE_CHAR){
66  return "char";
67  }else{
68  return "?";
69  }
70 }
herr_t H5LTset_attribute(hid_t loc_id, const char *obj_name, const char *attr_name, hid_t mem_type_id, void *buffer, size_t size)
Definition: HDF5Types.cpp:19
std::string H5TypeToString(hid_t type)
Definition: HDF5Types.cpp:45
static hid_t GetFlag()
Definition: HDF5Types.h:72