SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HDF5File.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2010 Soeren Sonnenburg
8  * Copyright (C) 2010 Berlin Institute of Technology
9  */
10 
11 #include <shogun/lib/config.h>
12 
13 #ifdef HAVE_HDF5
14 #include <stdio.h>
15 #include <string.h>
16 #include <hdf5.h>
17 
18 #include <shogun/lib/memory.h>
19 #include <shogun/io/HDF5File.h>
20 #include <shogun/io/SGIO.h>
21 
22 using namespace shogun;
23 
24 CHDF5File::CHDF5File()
25 {
26  SG_UNSTABLE("CHDF5File::CHDF5File()", "\n")
27 
28  get_boolean_type();
29  h5file = -1;
30 }
31 
32 CHDF5File::CHDF5File(char* fname, char rw, const char* name) : CFile()
33 {
34  get_boolean_type();
35  H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
36 
37  if (name)
38  set_variable_name(name);
39 
40  switch (rw)
41  {
42  case 'r':
43  h5file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
44  break;
45  case 'w':
46  h5file = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
47  break;
48  case 'a':
49  h5file = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT);
50  if (h5file <0)
51  h5file = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
52  break;
53  default:
54  SG_ERROR("unknown mode '%c'\n", rw)
55  };
56 
57  if (h5file<0)
58  SG_ERROR("Could not open file '%s'\n", fname)
59 }
60 
61 CHDF5File::~CHDF5File()
62 {
63  H5Fclose(h5file);
64 }
65 
66 #define GET_VECTOR(fname, sg_type, datatype) \
67 void CHDF5File::fname(sg_type*& vec, int32_t& len) \
68 { \
69  if (!h5file) \
70  SG_ERROR("File invalid.\n") \
71  \
72  int32_t* dims; \
73  int32_t ndims; \
74  int64_t nelements; \
75  hid_t dataset = H5Dopen2(h5file, variable_name, H5P_DEFAULT); \
76  if (dataset<0) \
77  SG_ERROR("Error opening data set\n") \
78  hid_t dtype = H5Dget_type(dataset); \
79  H5T_class_t t_class=H5Tget_class(dtype); \
80  TSGDataType t datatype; hid_t h5_type=get_compatible_type(t_class, &t); \
81  if (h5_type==-1) \
82  { \
83  H5Dclose(dataset); \
84  SG_INFO("No compatible datatype found\n") \
85  } \
86  get_dims(dataset, dims, ndims, nelements); \
87  if (!((ndims==2 && dims[0]==nelements && dims[1]==1) || \
88  (ndims==2 && dims[0]==1 && dims[1]==nelements) || \
89  (ndims==1 && dims[0]==nelements))) \
90  SG_ERROR("Error not a 1-dimensional vector (ndims=%d, dims[0]=%d)\n", ndims, dims[0]) \
91  vec=SG_MALLOC(sg_type, nelements); \
92  len=nelements; \
93  herr_t status = H5Dread(dataset, h5_type, H5S_ALL, \
94  H5S_ALL, H5P_DEFAULT, vec); \
95  H5Dclose(dataset); \
96  H5Tclose(dtype); \
97  SG_FREE(dims); \
98  if (status<0) \
99  { \
100  SG_FREE(vec); \
101  SG_ERROR("Error reading dataset\n") \
102  } \
103 }
104 
105 GET_VECTOR(get_vector, bool, (CT_VECTOR, ST_NONE, PT_BOOL))
106 GET_VECTOR(get_vector, int8_t, (CT_VECTOR, ST_NONE, PT_INT8))
107 GET_VECTOR(get_vector, uint8_t, (CT_VECTOR, ST_NONE, PT_UINT8))
108 GET_VECTOR(get_vector, char, (CT_VECTOR, ST_NONE, PT_CHAR))
109 GET_VECTOR(get_vector, int32_t, (CT_VECTOR, ST_NONE, PT_INT32))
110 GET_VECTOR(get_vector, uint32_t, (CT_VECTOR, ST_NONE, PT_UINT32))
111 GET_VECTOR(get_vector, float32_t, (CT_VECTOR, ST_NONE, PT_FLOAT32))
112 GET_VECTOR(get_vector, float64_t, (CT_VECTOR, ST_NONE, PT_FLOAT64))
113 GET_VECTOR(get_vector, floatmax_t, (CT_VECTOR, ST_NONE, PT_FLOATMAX))
114 GET_VECTOR(get_vector, int16_t, (CT_VECTOR, ST_NONE, PT_INT16))
115 GET_VECTOR(get_vector, uint16_t, (CT_VECTOR, ST_NONE, PT_INT16))
116 GET_VECTOR(get_vector, int64_t, (CT_VECTOR, ST_NONE, PT_INT64))
117 GET_VECTOR(get_vector, uint64_t, (CT_VECTOR, ST_NONE, PT_UINT64))
118 #undef GET_VECTOR
119 
120 #define GET_MATRIX(fname, sg_type, datatype) \
121 void CHDF5File::fname(sg_type*& matrix, int32_t& num_feat, int32_t& num_vec) \
122 { \
123  if (!h5file) \
124  SG_ERROR("File invalid.\n") \
125  \
126  int32_t* dims; \
127  int32_t ndims; \
128  int64_t nelements; \
129  hid_t dataset = H5Dopen2(h5file, variable_name, H5P_DEFAULT); \
130  if (dataset<0) \
131  SG_ERROR("Error opening data set\n") \
132  hid_t dtype = H5Dget_type(dataset); \
133  H5T_class_t t_class=H5Tget_class(dtype); \
134  TSGDataType t datatype; hid_t h5_type=get_compatible_type(t_class, &t); \
135  if (h5_type==-1) \
136  { \
137  H5Dclose(dataset); \
138  SG_INFO("No compatible datatype found\n") \
139  } \
140  get_dims(dataset, dims, ndims, nelements); \
141  if (ndims!=2) \
142  SG_ERROR("Error not a 2-dimensional matrix\n") \
143  matrix=SG_MALLOC(sg_type, nelements); \
144  num_feat=dims[0]; \
145  num_vec=dims[1]; \
146  herr_t status = H5Dread(dataset, h5_type, H5S_ALL, \
147  H5S_ALL, H5P_DEFAULT, matrix); \
148  H5Dclose(dataset); \
149  H5Tclose(dtype); \
150  SG_FREE(dims); \
151  if (status<0) \
152  { \
153  SG_FREE(matrix); \
154  SG_ERROR("Error reading dataset\n") \
155  } \
156 }
157 
158 GET_MATRIX(get_matrix, bool, (CT_MATRIX, ST_NONE, PT_BOOL))
159 GET_MATRIX(get_matrix, char, (CT_MATRIX, ST_NONE, PT_CHAR))
160 GET_MATRIX(get_matrix, uint8_t, (CT_MATRIX, ST_NONE, PT_UINT8))
161 GET_MATRIX(get_matrix, int32_t, (CT_MATRIX, ST_NONE, PT_INT32))
162 GET_MATRIX(get_matrix, uint32_t, (CT_MATRIX, ST_NONE, PT_INT32))
163 GET_MATRIX(get_matrix, int64_t, (CT_MATRIX, ST_NONE, PT_INT64))
164 GET_MATRIX(get_matrix, uint64_t, (CT_MATRIX, ST_NONE, PT_INT64))
165 GET_MATRIX(get_matrix, int16_t, (CT_MATRIX, ST_NONE, PT_INT16))
166 GET_MATRIX(get_matrix, uint16_t, (CT_MATRIX, ST_NONE, PT_INT16))
167 GET_MATRIX(get_matrix, float32_t, (CT_MATRIX, ST_NONE, PT_FLOAT32))
168 GET_MATRIX(get_matrix, float64_t, (CT_MATRIX, ST_NONE, PT_FLOAT64))
169 GET_MATRIX(get_matrix, floatmax_t, (CT_MATRIX, ST_NONE, PT_FLOATMAX))
170 #undef GET_MATRIX
171 
172 void CHDF5File::get_ndarray(uint8_t*& array, int32_t*& dims, int32_t& num_dims)
173 {
174 }
175 
176 void CHDF5File::get_ndarray(char*& array, int32_t*& dims, int32_t& num_dims)
177 {
178 }
179 
180 void CHDF5File::get_ndarray(int32_t*& array, int32_t*& dims, int32_t& num_dims)
181 {
182 }
183 
184 void CHDF5File::get_ndarray(float32_t*& array, int32_t*& dims, int32_t& num_dims)
185 {
186 }
187 
188 void CHDF5File::get_ndarray(float64_t*& array, int32_t*& dims, int32_t& num_dims)
189 {
190 }
191 
192 void CHDF5File::get_ndarray(int16_t*& array, int32_t*& dims, int32_t& num_dims)
193 {
194 }
195 
196 void CHDF5File::get_ndarray(uint16_t*& array, int32_t*& dims, int32_t& num_dims)
197 {
198 }
199 
200 #define GET_SPARSEMATRIX(fname, sg_type, datatype) \
201 void CHDF5File::fname(SGSparseVector<sg_type>*& matrix, int32_t& num_feat, int32_t& num_vec) \
202 { \
203  if (!(file)) \
204  SG_ERROR("File invalid.\n") \
205 }
206 GET_SPARSEMATRIX(get_sparse_matrix, bool, DT_SPARSE_BOOL)
207 GET_SPARSEMATRIX(get_sparse_matrix, char, DT_SPARSE_CHAR)
208 GET_SPARSEMATRIX(get_sparse_matrix, int8_t, DT_SPARSE_INT8)
209 GET_SPARSEMATRIX(get_sparse_matrix, uint8_t, DT_SPARSE_BYTE)
210 GET_SPARSEMATRIX(get_sparse_matrix, int32_t, DT_SPARSE_INT)
211 GET_SPARSEMATRIX(get_sparse_matrix, uint32_t, DT_SPARSE_UINT)
212 GET_SPARSEMATRIX(get_sparse_matrix, int64_t, DT_SPARSE_LONG)
213 GET_SPARSEMATRIX(get_sparse_matrix, uint64_t, DT_SPARSE_ULONG)
214 GET_SPARSEMATRIX(get_sparse_matrix, int16_t, DT_SPARSE_SHORT)
215 GET_SPARSEMATRIX(get_sparse_matrix, uint16_t, DT_SPARSE_WORD)
216 GET_SPARSEMATRIX(get_sparse_matrix, float32_t, DT_SPARSE_SHORTREAL)
217 GET_SPARSEMATRIX(get_sparse_matrix, float64_t, DT_SPARSE_REAL)
218 GET_SPARSEMATRIX(get_sparse_matrix, floatmax_t, DT_SPARSE_LONGREAL)
219 #undef GET_SPARSEMATRIX
220 
221 
222 #define GET_STRING_LIST(fname, sg_type, datatype) \
223 void CHDF5File::fname(SGString<sg_type>*& strings, int32_t& num_str, int32_t& max_string_len) \
224 { \
225 }
226 
227 GET_STRING_LIST(get_string_list, bool, DT_STRING_BOOL)
228 GET_STRING_LIST(get_string_list, char, DT_STRING_CHAR)
229 GET_STRING_LIST(get_string_list, int8_t, DT_STRING_INT8)
230 GET_STRING_LIST(get_string_list, uint8_t, DT_STRING_BYTE)
231 GET_STRING_LIST(get_string_list, int32_t, DT_STRING_INT)
232 GET_STRING_LIST(get_string_list, uint32_t, DT_STRING_UINT)
233 GET_STRING_LIST(get_string_list, int64_t, DT_STRING_LONG)
234 GET_STRING_LIST(get_string_list, uint64_t, DT_STRING_ULONG)
235 GET_STRING_LIST(get_string_list, int16_t, DT_STRING_SHORT)
236 GET_STRING_LIST(get_string_list, uint16_t, DT_STRING_WORD)
237 GET_STRING_LIST(get_string_list, float32_t, DT_STRING_SHORTREAL)
238 GET_STRING_LIST(get_string_list, float64_t, DT_STRING_REAL)
239 GET_STRING_LIST(get_string_list, floatmax_t, DT_STRING_LONGREAL)
240 #undef GET_STRING_LIST
241 
244 #define SET_VECTOR(fname, sg_type, dtype, h5type) \
245 void CHDF5File::fname(const sg_type* vec, int32_t len) \
246 { \
247  if (h5file<0 || !vec) \
248  SG_ERROR("File or vector invalid.\n") \
249  \
250  create_group_hierarchy(); \
251  \
252  hsize_t dims=(hsize_t) len; \
253  hid_t dataspace, dataset, status; \
254  dataspace=H5Screate_simple(1, &dims, NULL); \
255  if (dataspace<0) \
256  SG_ERROR("Could not create hdf5 dataspace\n") \
257  dataset=H5Dcreate2(h5file, variable_name, h5type, dataspace, H5P_DEFAULT,\
258  H5P_DEFAULT, H5P_DEFAULT); \
259  if (dataset<0) \
260  { \
261  SG_ERROR("Could not create hdf5 dataset - does" \
262  " dataset '%s' already exist?\n", variable_name); \
263  } \
264  status=H5Dwrite(dataset, h5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, vec); \
265  if (status<0) \
266  SG_ERROR("Failed to write hdf5 dataset\n") \
267  H5Dclose(dataset); \
268  H5Sclose(dataspace); \
269 }
270 SET_VECTOR(set_vector, bool, DT_VECTOR_BOOL, boolean_type)
271 SET_VECTOR(set_vector, int8_t, DT_VECTOR_BYTE, H5T_NATIVE_INT8)
272 SET_VECTOR(set_vector, uint8_t, DT_VECTOR_BYTE, H5T_NATIVE_UINT8)
273 SET_VECTOR(set_vector, char, DT_VECTOR_CHAR, H5T_NATIVE_CHAR)
274 SET_VECTOR(set_vector, int32_t, DT_VECTOR_INT, H5T_NATIVE_INT32)
275 SET_VECTOR(set_vector, uint32_t, DT_VECTOR_UINT, H5T_NATIVE_UINT32)
276 SET_VECTOR(set_vector, float32_t, DT_VECTOR_SHORTREAL, H5T_NATIVE_FLOAT)
277 SET_VECTOR(set_vector, float64_t, DT_VECTOR_REAL, H5T_NATIVE_DOUBLE)
278 SET_VECTOR(set_vector, floatmax_t, DT_VECTOR_LONGREAL, H5T_NATIVE_LDOUBLE)
279 SET_VECTOR(set_vector, int16_t, DT_VECTOR_SHORT, H5T_NATIVE_INT16)
280 SET_VECTOR(set_vector, uint16_t, DT_VECTOR_WORD, H5T_NATIVE_UINT16)
281 SET_VECTOR(set_vector, int64_t, DT_VECTOR_LONG, H5T_NATIVE_LLONG)
282 SET_VECTOR(set_vector, uint64_t, DT_VECTOR_ULONG, H5T_NATIVE_ULLONG)
283 #undef SET_VECTOR
284 
285 #define SET_MATRIX(fname, sg_type, dtype, h5type) \
286 void CHDF5File::fname(const sg_type* matrix, int32_t num_feat, int32_t num_vec) \
287 { \
288  if (h5file<0 || !matrix) \
289  SG_ERROR("File or matrix invalid.\n") \
290  \
291  create_group_hierarchy(); \
292  \
293  hsize_t dims[2]={(hsize_t) num_feat, (hsize_t) num_vec}; \
294  hid_t dataspace, dataset, status; \
295  dataspace=H5Screate_simple(2, dims, NULL); \
296  if (dataspace<0) \
297  SG_ERROR("Could not create hdf5 dataspace\n") \
298  dataset=H5Dcreate2(h5file, variable_name, h5type, dataspace, H5P_DEFAULT, \
299  H5P_DEFAULT, H5P_DEFAULT); \
300  if (dataset<0) \
301  { \
302  SG_ERROR("Could not create hdf5 dataset - does" \
303  " dataset '%s' already exist?\n", variable_name); \
304  } \
305  status=H5Dwrite(dataset, h5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, matrix); \
306  if (status<0) \
307  SG_ERROR("Failed to write hdf5 dataset\n") \
308  H5Dclose(dataset); \
309  H5Sclose(dataspace); \
310 }
311 SET_MATRIX(set_matrix, bool, DT_DENSE_BOOL, boolean_type)
312 SET_MATRIX(set_matrix, char, DT_DENSE_CHAR, H5T_NATIVE_CHAR)
313 SET_MATRIX(set_matrix, int8_t, DT_DENSE_BYTE, H5T_NATIVE_INT8)
314 SET_MATRIX(set_matrix, uint8_t, DT_DENSE_BYTE, H5T_NATIVE_UINT8)
315 SET_MATRIX(set_matrix, int32_t, DT_DENSE_INT, H5T_NATIVE_INT32)
316 SET_MATRIX(set_matrix, uint32_t, DT_DENSE_UINT, H5T_NATIVE_UINT32)
317 SET_MATRIX(set_matrix, int64_t, DT_DENSE_LONG, H5T_NATIVE_INT64)
318 SET_MATRIX(set_matrix, uint64_t, DT_DENSE_ULONG, H5T_NATIVE_UINT64)
319 SET_MATRIX(set_matrix, int16_t, DT_DENSE_SHORT, H5T_NATIVE_INT16)
320 SET_MATRIX(set_matrix, uint16_t, DT_DENSE_WORD, H5T_NATIVE_UINT16)
321 SET_MATRIX(set_matrix, float32_t, DT_DENSE_SHORTREAL, H5T_NATIVE_FLOAT)
322 SET_MATRIX(set_matrix, float64_t, DT_DENSE_REAL, H5T_NATIVE_DOUBLE)
323 SET_MATRIX(set_matrix, floatmax_t, DT_DENSE_LONGREAL, H5T_NATIVE_LDOUBLE)
324 #undef SET_MATRIX
325 
326 #define SET_SPARSEMATRIX(fname, sg_type, dtype) \
327 void CHDF5File::fname(const SGSparseVector<sg_type>* matrix, \
328  int32_t num_feat, int32_t num_vec) \
329 { \
330  if (!(file && matrix)) \
331  SG_ERROR("File or matrix invalid.\n") \
332  \
333 }
334 SET_SPARSEMATRIX(set_sparse_matrix, bool, DT_SPARSE_BOOL)
335 SET_SPARSEMATRIX(set_sparse_matrix, char, DT_SPARSE_CHAR)
336 SET_SPARSEMATRIX(set_sparse_matrix, int8_t, DT_SPARSE_INT8)
337 SET_SPARSEMATRIX(set_sparse_matrix, uint8_t, DT_SPARSE_BYTE)
338 SET_SPARSEMATRIX(set_sparse_matrix, int32_t, DT_SPARSE_INT)
339 SET_SPARSEMATRIX(set_sparse_matrix, uint32_t, DT_SPARSE_UINT)
340 SET_SPARSEMATRIX(set_sparse_matrix, int64_t, DT_SPARSE_LONG)
341 SET_SPARSEMATRIX(set_sparse_matrix, uint64_t, DT_SPARSE_ULONG)
342 SET_SPARSEMATRIX(set_sparse_matrix, int16_t, DT_SPARSE_SHORT)
343 SET_SPARSEMATRIX(set_sparse_matrix, uint16_t, DT_SPARSE_WORD)
344 SET_SPARSEMATRIX(set_sparse_matrix, float32_t, DT_SPARSE_SHORTREAL)
345 SET_SPARSEMATRIX(set_sparse_matrix, float64_t, DT_SPARSE_REAL)
346 SET_SPARSEMATRIX(set_sparse_matrix, floatmax_t, DT_SPARSE_LONGREAL)
347 #undef SET_SPARSEMATRIX
348 
349 #define SET_STRING_LIST(fname, sg_type, dtype) \
350 void CHDF5File::fname(const SGString<sg_type>* strings, int32_t num_str) \
351 { \
352  if (!(file && strings)) \
353  SG_ERROR("File or strings invalid.\n") \
354  \
355 }
356 SET_STRING_LIST(set_string_list, bool, DT_STRING_BOOL)
357 SET_STRING_LIST(set_string_list, char, DT_STRING_CHAR)
358 SET_STRING_LIST(set_string_list, int8_t, DT_STRING_INT8)
359 SET_STRING_LIST(set_string_list, uint8_t, DT_STRING_BYTE)
360 SET_STRING_LIST(set_string_list, int32_t, DT_STRING_INT)
361 SET_STRING_LIST(set_string_list, uint32_t, DT_STRING_UINT)
362 SET_STRING_LIST(set_string_list, int64_t, DT_STRING_LONG)
363 SET_STRING_LIST(set_string_list, uint64_t, DT_STRING_ULONG)
364 SET_STRING_LIST(set_string_list, int16_t, DT_STRING_SHORT)
365 SET_STRING_LIST(set_string_list, uint16_t, DT_STRING_WORD)
366 SET_STRING_LIST(set_string_list, float32_t, DT_STRING_SHORTREAL)
367 SET_STRING_LIST(set_string_list, float64_t, DT_STRING_REAL)
368 SET_STRING_LIST(set_string_list, floatmax_t, DT_STRING_LONGREAL)
369 #undef SET_STRING_LIST
370 
371 void CHDF5File::get_boolean_type()
372 {
373  boolean_type=H5T_NATIVE_UCHAR;
374  switch (sizeof(bool))
375  {
376  case 1:
377  boolean_type = H5T_NATIVE_UCHAR;
378  break;
379  case 2:
380  boolean_type = H5T_NATIVE_UINT16;
381  break;
382  case 4:
383  boolean_type = H5T_NATIVE_UINT32;
384  break;
385  case 8:
386  boolean_type = H5T_NATIVE_UINT64;
387  break;
388  default:
389  SG_ERROR("Boolean type not supported on this platform\n")
390  }
391 }
392 
393 hid_t CHDF5File::get_compatible_type(H5T_class_t t_class,
394  const TSGDataType* datatype)
395 {
396  switch (t_class)
397  {
398  case H5T_FLOAT:
399  case H5T_INTEGER:
400  switch (datatype->m_ptype)
401  {
402  case PT_BOOL: return boolean_type;
403  case PT_CHAR: return H5T_NATIVE_CHAR;
404  case PT_INT8: return H5T_NATIVE_INT8;
405  case PT_UINT8: return H5T_NATIVE_UINT8;
406  case PT_INT16: return H5T_NATIVE_INT16;
407  case PT_UINT16: return H5T_NATIVE_UINT16;
408  case PT_INT32: return H5T_NATIVE_INT32;
409  case PT_UINT32: return H5T_NATIVE_UINT32;
410  case PT_INT64: return H5T_NATIVE_INT64;
411  case PT_UINT64: return H5T_NATIVE_UINT64;
412  case PT_FLOAT32: return H5T_NATIVE_FLOAT;
413  case PT_FLOAT64: return H5T_NATIVE_DOUBLE;
414  case PT_FLOATMAX: return H5T_NATIVE_LDOUBLE;
415  case PT_COMPLEX128:
416  SG_ERROR("complex128_t not compatible with HDF5File!");
417  return -1;
418  case PT_SGOBJECT:
419  case PT_UNDEFINED:
420  SG_ERROR("Implementation error during writing "
421  "HDF5File!");
422  return -1;
423  }
424  case H5T_STRING:
425  SG_ERROR("Strings not supported")
426  return -1;
427  case H5T_VLEN:
428  SG_ERROR("Variable length containers currently not supported")
429  return -1;
430  case H5T_ARRAY:
431  SG_ERROR("Array containers currently not supported")
432  return -1;
433  default:
434  SG_ERROR("Datatype mismatchn")
435  return -1;
436  }
437 }
438 
439 void CHDF5File::get_dims(hid_t dataset, int32_t*& dims, int32_t& ndims, int64_t& total_elements)
440 {
441  hid_t dataspace = H5Dget_space(dataset);
442  if (dataspace<0)
443  SG_ERROR("Error obtaining hdf5 dataspace\n")
444 
445  ndims = H5Sget_simple_extent_ndims(dataspace);
446  total_elements=H5Sget_simple_extent_npoints(dataspace);
447  hsize_t* dims_out=SG_MALLOC(hsize_t, ndims);
448  dims=SG_MALLOC(int32_t, ndims);
449  H5Sget_simple_extent_dims(dataspace, dims_out, NULL);
450  for (int32_t i=0; i<ndims; i++)
451  dims[i]=dims_out[i];
452  SG_FREE(dims_out);
453  H5Sclose(dataspace);
454 }
455 
456 void CHDF5File::create_group_hierarchy()
457 {
458  char* vname=get_strdup(variable_name);
459  int32_t vlen=strlen(vname);
460  for (int32_t i=0; i<vlen; i++)
461  {
462  if (i!=0 && vname[i]=='/')
463  {
464  vname[i]='\0';
465  hid_t g = H5Gopen2(h5file, vname, H5P_DEFAULT);
466  if (g<0)
467  {
468  g=H5Gcreate2(h5file, vname, H5P_DEFAULT, H5P_DEFAULT,
469  H5P_DEFAULT);
470  if (g<0)
471  SG_ERROR("Error creating group '%s'\n", vname)
472  vname[i]='/';
473  }
474  H5Gclose(g);
475  }
476  }
477  SG_FREE(vname);
478 }
479 #endif // HDF5

SHOGUN Machine Learning Toolbox - Documentation