SHOGUN
v2.0.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2010 Soeren Sonnenburg 00008 * Copyright (C) 2010 Berlin Institute of Technology 00009 */ 00010 00011 #include <shogun/lib/config.h> 00012 00013 #ifdef HAVE_HDF5 00014 #include <stdio.h> 00015 #include <stdlib.h> 00016 #include <string.h> 00017 #include <hdf5.h> 00018 00019 #include <shogun/io/HDF5File.h> 00020 00021 #include <shogun/features/StringFeatures.h> 00022 #include <shogun/features/SparseFeatures.h> 00023 00024 using namespace shogun; 00025 00026 CHDF5File::CHDF5File() 00027 { 00028 SG_UNSTABLE("CHDF5File::CHDF5File()", "\n"); 00029 00030 get_boolean_type(); 00031 h5file = -1; 00032 } 00033 00034 CHDF5File::CHDF5File(char* fname, char rw, const char* name) : CFile() 00035 { 00036 get_boolean_type(); 00037 H5Eset_auto2(H5E_DEFAULT, NULL, NULL); 00038 00039 if (name) 00040 set_variable_name(name); 00041 00042 switch (rw) 00043 { 00044 case 'r': 00045 h5file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT); 00046 break; 00047 case 'w': 00048 h5file = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 00049 break; 00050 case 'a': 00051 h5file = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT); 00052 if (h5file <0) 00053 h5file = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 00054 break; 00055 default: 00056 SG_ERROR("unknown mode '%c'\n", rw); 00057 }; 00058 00059 if (h5file<0) 00060 SG_ERROR("Could not open file '%s'\n", fname); 00061 } 00062 00063 CHDF5File::~CHDF5File() 00064 { 00065 H5Fclose(h5file); 00066 } 00067 00068 #define GET_VECTOR(fname, sg_type, datatype) \ 00069 void CHDF5File::fname(sg_type*& vec, int32_t& len) \ 00070 { \ 00071 if (!h5file) \ 00072 SG_ERROR("File invalid.\n"); \ 00073 \ 00074 int32_t* dims; \ 00075 int32_t ndims; \ 00076 int64_t nelements; \ 00077 hid_t dataset = H5Dopen2(h5file, variable_name, H5P_DEFAULT); \ 00078 if (dataset<0) \ 00079 SG_ERROR("Error opening data set\n"); \ 00080 hid_t dtype = H5Dget_type(dataset); \ 00081 H5T_class_t t_class=H5Tget_class(dtype); \ 00082 TSGDataType t datatype; hid_t h5_type=get_compatible_type(t_class, &t); \ 00083 if (h5_type==-1) \ 00084 { \ 00085 H5Dclose(dataset); \ 00086 SG_INFO("No compatible datatype found\n"); \ 00087 } \ 00088 get_dims(dataset, dims, ndims, nelements); \ 00089 if (!((ndims==2 && dims[0]==nelements && dims[1]==1) || \ 00090 (ndims==2 && dims[0]==1 && dims[1]==nelements) || \ 00091 (ndims==1 && dims[0]==nelements))) \ 00092 SG_ERROR("Error not a 1-dimensional vector (ndims=%d, dims[0]=%d)\n", ndims, dims[0]); \ 00093 vec=SG_MALLOC(sg_type, nelements); \ 00094 len=nelements; \ 00095 herr_t status = H5Dread(dataset, h5_type, H5S_ALL, \ 00096 H5S_ALL, H5P_DEFAULT, vec); \ 00097 H5Dclose(dataset); \ 00098 H5Tclose(dtype); \ 00099 SG_FREE(dims); \ 00100 if (status<0) \ 00101 { \ 00102 SG_FREE(vec); \ 00103 SG_ERROR("Error reading dataset\n"); \ 00104 } \ 00105 } 00106 00107 GET_VECTOR(get_vector, bool, (CT_VECTOR, ST_NONE, PT_BOOL)) 00108 GET_VECTOR(get_vector, uint8_t, (CT_VECTOR, ST_NONE, PT_UINT8)) 00109 GET_VECTOR(get_vector, char, (CT_VECTOR, ST_NONE, PT_CHAR)) 00110 GET_VECTOR(get_vector, int32_t, (CT_VECTOR, ST_NONE, PT_INT32)) 00111 GET_VECTOR(get_vector, float32_t, (CT_VECTOR, ST_NONE, PT_FLOAT32)) 00112 GET_VECTOR(get_vector, float64_t, (CT_VECTOR, ST_NONE, PT_FLOAT64)) 00113 GET_VECTOR(get_vector, int16_t, (CT_VECTOR, ST_NONE, PT_INT16)) 00114 GET_VECTOR(get_vector, uint16_t, (CT_VECTOR, ST_NONE, PT_INT16)) 00115 #undef GET_VECTOR 00116 00117 #define GET_MATRIX(fname, sg_type, datatype) \ 00118 void CHDF5File::fname(sg_type*& matrix, int32_t& num_feat, int32_t& num_vec) \ 00119 { \ 00120 if (!h5file) \ 00121 SG_ERROR("File invalid.\n"); \ 00122 \ 00123 int32_t* dims; \ 00124 int32_t ndims; \ 00125 int64_t nelements; \ 00126 hid_t dataset = H5Dopen2(h5file, variable_name, H5P_DEFAULT); \ 00127 if (dataset<0) \ 00128 SG_ERROR("Error opening data set\n"); \ 00129 hid_t dtype = H5Dget_type(dataset); \ 00130 H5T_class_t t_class=H5Tget_class(dtype); \ 00131 TSGDataType t datatype; hid_t h5_type=get_compatible_type(t_class, &t); \ 00132 if (h5_type==-1) \ 00133 { \ 00134 H5Dclose(dataset); \ 00135 SG_INFO("No compatible datatype found\n"); \ 00136 } \ 00137 get_dims(dataset, dims, ndims, nelements); \ 00138 if (ndims!=2) \ 00139 SG_ERROR("Error not a 2-dimensional matrix\n"); \ 00140 matrix=SG_MALLOC(sg_type, nelements); \ 00141 num_feat=dims[0]; \ 00142 num_vec=dims[1]; \ 00143 herr_t status = H5Dread(dataset, h5_type, H5S_ALL, \ 00144 H5S_ALL, H5P_DEFAULT, matrix); \ 00145 H5Dclose(dataset); \ 00146 H5Tclose(dtype); \ 00147 SG_FREE(dims); \ 00148 if (status<0) \ 00149 { \ 00150 SG_FREE(matrix); \ 00151 SG_ERROR("Error reading dataset\n"); \ 00152 } \ 00153 } 00154 00155 GET_MATRIX(get_matrix, bool, (CT_MATRIX, ST_NONE, PT_BOOL)) 00156 GET_MATRIX(get_matrix, char, (CT_MATRIX, ST_NONE, PT_CHAR)) 00157 GET_MATRIX(get_matrix, uint8_t, (CT_MATRIX, ST_NONE, PT_UINT8)) 00158 GET_MATRIX(get_matrix, int32_t, (CT_MATRIX, ST_NONE, PT_INT32)) 00159 GET_MATRIX(get_uint_matrix, uint32_t, (CT_MATRIX, ST_NONE, PT_INT32)) 00160 GET_MATRIX(get_long_matrix, int64_t, (CT_MATRIX, ST_NONE, PT_INT64)) 00161 GET_MATRIX(get_ulong_matrix, uint64_t, (CT_MATRIX, ST_NONE, PT_INT64)) 00162 GET_MATRIX(get_matrix, int16_t, (CT_MATRIX, ST_NONE, PT_INT16)) 00163 GET_MATRIX(get_matrix, uint16_t, (CT_MATRIX, ST_NONE, PT_INT16)) 00164 GET_MATRIX(get_matrix, float32_t, (CT_MATRIX, ST_NONE, PT_FLOAT32)) 00165 GET_MATRIX(get_matrix, float64_t, (CT_MATRIX, ST_NONE, PT_FLOAT64)) 00166 GET_MATRIX(get_longreal_matrix, floatmax_t, (CT_MATRIX, ST_NONE, PT_FLOATMAX)) 00167 #undef GET_MATRIX 00168 00169 void CHDF5File::get_ndarray(uint8_t*& array, int32_t*& dims, int32_t& num_dims) 00170 { 00171 } 00172 00173 void CHDF5File::get_ndarray(char*& array, int32_t*& dims, int32_t& num_dims) 00174 { 00175 } 00176 00177 void CHDF5File::get_ndarray(int32_t*& array, int32_t*& dims, int32_t& num_dims) 00178 { 00179 } 00180 00181 void CHDF5File::get_ndarray(float32_t*& array, int32_t*& dims, int32_t& num_dims) 00182 { 00183 } 00184 00185 void CHDF5File::get_ndarray(float64_t*& array, int32_t*& dims, int32_t& num_dims) 00186 { 00187 } 00188 00189 void CHDF5File::get_ndarray(int16_t*& array, int32_t*& dims, int32_t& num_dims) 00190 { 00191 } 00192 00193 void CHDF5File::get_ndarray(uint16_t*& array, int32_t*& dims, int32_t& num_dims) 00194 { 00195 } 00196 00197 #define GET_SPARSEMATRIX(fname, sg_type, datatype) \ 00198 void CHDF5File::fname(SGSparseVector<sg_type>*& matrix, int32_t& num_feat, int32_t& num_vec) \ 00199 { \ 00200 if (!(file)) \ 00201 SG_ERROR("File invalid.\n"); \ 00202 } 00203 GET_SPARSEMATRIX(get_sparse_matrix, bool, DT_SPARSE_BOOL) 00204 GET_SPARSEMATRIX(get_sparse_matrix, char, DT_SPARSE_CHAR) 00205 GET_SPARSEMATRIX(get_sparse_matrix, uint8_t, DT_SPARSE_BYTE) 00206 GET_SPARSEMATRIX(get_sparse_matrix, int32_t, DT_SPARSE_INT) 00207 GET_SPARSEMATRIX(get_uint_sparsematrix, uint32_t, DT_SPARSE_UINT) 00208 GET_SPARSEMATRIX(get_long_sparsematrix, int64_t, DT_SPARSE_LONG) 00209 GET_SPARSEMATRIX(get_ulong_sparsematrix, uint64_t, DT_SPARSE_ULONG) 00210 GET_SPARSEMATRIX(get_sparse_matrix, int16_t, DT_SPARSE_SHORT) 00211 GET_SPARSEMATRIX(get_sparse_matrix, uint16_t, DT_SPARSE_WORD) 00212 GET_SPARSEMATRIX(get_sparse_matrix, float32_t, DT_SPARSE_SHORTREAL) 00213 GET_SPARSEMATRIX(get_sparse_matrix, float64_t, DT_SPARSE_REAL) 00214 GET_SPARSEMATRIX(get_longreal_sparsematrix, floatmax_t, DT_SPARSE_LONGREAL) 00215 #undef GET_SPARSEMATRIX 00216 00217 00218 #define GET_STRING_LIST(fname, sg_type, datatype) \ 00219 void CHDF5File::fname(SGString<sg_type>*& strings, int32_t& num_str, int32_t& max_string_len) \ 00220 { \ 00221 } 00222 00223 GET_STRING_LIST(get_string_list, bool, DT_STRING_BOOL) 00224 GET_STRING_LIST(get_string_list, char, DT_STRING_CHAR) 00225 GET_STRING_LIST(get_string_list, uint8_t, DT_STRING_BYTE) 00226 GET_STRING_LIST(get_string_list, int32_t, DT_STRING_INT) 00227 GET_STRING_LIST(get_uint_string_list, uint32_t, DT_STRING_UINT) 00228 GET_STRING_LIST(get_long_string_list, int64_t, DT_STRING_LONG) 00229 GET_STRING_LIST(get_ulong_string_list, uint64_t, DT_STRING_ULONG) 00230 GET_STRING_LIST(get_string_list, int16_t, DT_STRING_SHORT) 00231 GET_STRING_LIST(get_string_list, uint16_t, DT_STRING_WORD) 00232 GET_STRING_LIST(get_string_list, float32_t, DT_STRING_SHORTREAL) 00233 GET_STRING_LIST(get_string_list, float64_t, DT_STRING_REAL) 00234 GET_STRING_LIST(get_longreal_string_list, floatmax_t, DT_STRING_LONGREAL) 00235 #undef GET_STRING_LIST 00236 00239 #define SET_VECTOR(fname, sg_type, dtype, h5type) \ 00240 void CHDF5File::fname(const sg_type* vec, int32_t len) \ 00241 { \ 00242 if (h5file<0 || !vec) \ 00243 SG_ERROR("File or vector invalid.\n"); \ 00244 \ 00245 create_group_hierarchy(); \ 00246 \ 00247 hsize_t dims=(hsize_t) len; \ 00248 hid_t dataspace, dataset, status; \ 00249 dataspace=H5Screate_simple(1, &dims, NULL); \ 00250 if (dataspace<0) \ 00251 SG_ERROR("Could not create hdf5 dataspace\n"); \ 00252 dataset=H5Dcreate2(h5file, variable_name, h5type, dataspace, H5P_DEFAULT,\ 00253 H5P_DEFAULT, H5P_DEFAULT); \ 00254 if (dataset<0) \ 00255 { \ 00256 SG_ERROR("Could not create hdf5 dataset - does" \ 00257 " dataset '%s' already exist?\n", variable_name); \ 00258 } \ 00259 status=H5Dwrite(dataset, h5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, vec); \ 00260 if (status<0) \ 00261 SG_ERROR("Failed to write hdf5 dataset\n"); \ 00262 H5Dclose(dataset); \ 00263 H5Sclose(dataspace); \ 00264 } 00265 SET_VECTOR(set_vector, bool, DT_VECTOR_BOOL, boolean_type) 00266 SET_VECTOR(set_vector, uint8_t, DT_VECTOR_BYTE, H5T_NATIVE_UINT8) 00267 SET_VECTOR(set_vector, char, DT_VECTOR_CHAR, H5T_NATIVE_CHAR) 00268 SET_VECTOR(set_vector, int32_t, DT_VECTOR_INT, H5T_NATIVE_INT32) 00269 SET_VECTOR(set_vector, float32_t, DT_VECTOR_SHORTREAL, H5T_NATIVE_FLOAT) 00270 SET_VECTOR(set_vector, float64_t, DT_VECTOR_REAL, H5T_NATIVE_DOUBLE) 00271 SET_VECTOR(set_vector, int16_t, DT_VECTOR_SHORT, H5T_NATIVE_INT16) 00272 SET_VECTOR(set_vector, uint16_t, DT_VECTOR_WORD, H5T_NATIVE_UINT16) 00273 #undef SET_VECTOR 00274 00275 #define SET_MATRIX(fname, sg_type, dtype, h5type) \ 00276 void CHDF5File::fname(const sg_type* matrix, int32_t num_feat, int32_t num_vec) \ 00277 { \ 00278 if (h5file<0 || !matrix) \ 00279 SG_ERROR("File or matrix invalid.\n"); \ 00280 \ 00281 create_group_hierarchy(); \ 00282 \ 00283 hsize_t dims[2]={(hsize_t) num_feat, (hsize_t) num_vec}; \ 00284 hid_t dataspace, dataset, status; \ 00285 dataspace=H5Screate_simple(2, dims, NULL); \ 00286 if (dataspace<0) \ 00287 SG_ERROR("Could not create hdf5 dataspace\n"); \ 00288 dataset=H5Dcreate2(h5file, variable_name, h5type, dataspace, H5P_DEFAULT, \ 00289 H5P_DEFAULT, H5P_DEFAULT); \ 00290 if (dataset<0) \ 00291 { \ 00292 SG_ERROR("Could not create hdf5 dataset - does" \ 00293 " dataset '%s' already exist?\n", variable_name); \ 00294 } \ 00295 status=H5Dwrite(dataset, h5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, matrix); \ 00296 if (status<0) \ 00297 SG_ERROR("Failed to write hdf5 dataset\n"); \ 00298 H5Dclose(dataset); \ 00299 H5Sclose(dataspace); \ 00300 } 00301 SET_MATRIX(set_matrix, bool, DT_DENSE_BOOL, boolean_type) 00302 SET_MATRIX(set_matrix, char, DT_DENSE_CHAR, H5T_NATIVE_CHAR) 00303 SET_MATRIX(set_matrix, uint8_t, DT_DENSE_BYTE, H5T_NATIVE_UINT8) 00304 SET_MATRIX(set_matrix, int32_t, DT_DENSE_INT, H5T_NATIVE_INT32) 00305 SET_MATRIX(set_uint_matrix, uint32_t, DT_DENSE_UINT, H5T_NATIVE_UINT32) 00306 SET_MATRIX(set_long_matrix, int64_t, DT_DENSE_LONG, H5T_NATIVE_INT64) 00307 SET_MATRIX(set_ulong_matrix, uint64_t, DT_DENSE_ULONG, H5T_NATIVE_UINT64) 00308 SET_MATRIX(set_matrix, int16_t, DT_DENSE_SHORT, H5T_NATIVE_INT16) 00309 SET_MATRIX(set_matrix, uint16_t, DT_DENSE_WORD, H5T_NATIVE_UINT16) 00310 SET_MATRIX(set_matrix, float32_t, DT_DENSE_SHORTREAL, H5T_NATIVE_FLOAT) 00311 SET_MATRIX(set_matrix, float64_t, DT_DENSE_REAL, H5T_NATIVE_DOUBLE) 00312 SET_MATRIX(set_longreal_matrix, floatmax_t, DT_DENSE_LONGREAL, H5T_NATIVE_LDOUBLE) 00313 #undef SET_MATRIX 00314 00315 #define SET_SPARSEMATRIX(fname, sg_type, dtype) \ 00316 void CHDF5File::fname(const SGSparseVector<sg_type>* matrix, \ 00317 int32_t num_feat, int32_t num_vec) \ 00318 { \ 00319 if (!(file && matrix)) \ 00320 SG_ERROR("File or matrix invalid.\n"); \ 00321 \ 00322 } 00323 SET_SPARSEMATRIX(set_sparse_matrix, bool, DT_SPARSE_BOOL) 00324 SET_SPARSEMATRIX(set_sparse_matrix, char, DT_SPARSE_CHAR) 00325 SET_SPARSEMATRIX(set_sparse_matrix, uint8_t, DT_SPARSE_BYTE) 00326 SET_SPARSEMATRIX(set_sparse_matrix, int32_t, DT_SPARSE_INT) 00327 SET_SPARSEMATRIX(set_uint_sparsematrix, uint32_t, DT_SPARSE_UINT) 00328 SET_SPARSEMATRIX(set_long_sparsematrix, int64_t, DT_SPARSE_LONG) 00329 SET_SPARSEMATRIX(set_ulong_sparsematrix, uint64_t, DT_SPARSE_ULONG) 00330 SET_SPARSEMATRIX(set_sparse_matrix, int16_t, DT_SPARSE_SHORT) 00331 SET_SPARSEMATRIX(set_sparse_matrix, uint16_t, DT_SPARSE_WORD) 00332 SET_SPARSEMATRIX(set_sparse_matrix, float32_t, DT_SPARSE_SHORTREAL) 00333 SET_SPARSEMATRIX(set_sparse_matrix, float64_t, DT_SPARSE_REAL) 00334 SET_SPARSEMATRIX(set_longreal_sparsematrix, floatmax_t, DT_SPARSE_LONGREAL) 00335 #undef SET_SPARSEMATRIX 00336 00337 #define SET_STRING_LIST(fname, sg_type, dtype) \ 00338 void CHDF5File::fname(const SGString<sg_type>* strings, int32_t num_str) \ 00339 { \ 00340 if (!(file && strings)) \ 00341 SG_ERROR("File or strings invalid.\n"); \ 00342 \ 00343 } 00344 SET_STRING_LIST(set_string_list, bool, DT_STRING_BOOL) 00345 SET_STRING_LIST(set_string_list, char, DT_STRING_CHAR) 00346 SET_STRING_LIST(set_string_list, uint8_t, DT_STRING_BYTE) 00347 SET_STRING_LIST(set_string_list, int32_t, DT_STRING_INT) 00348 SET_STRING_LIST(set_uint_string_list, uint32_t, DT_STRING_UINT) 00349 SET_STRING_LIST(set_long_string_list, int64_t, DT_STRING_LONG) 00350 SET_STRING_LIST(set_ulong_string_list, uint64_t, DT_STRING_ULONG) 00351 SET_STRING_LIST(set_string_list, int16_t, DT_STRING_SHORT) 00352 SET_STRING_LIST(set_string_list, uint16_t, DT_STRING_WORD) 00353 SET_STRING_LIST(set_string_list, float32_t, DT_STRING_SHORTREAL) 00354 SET_STRING_LIST(set_string_list, float64_t, DT_STRING_REAL) 00355 SET_STRING_LIST(set_longreal_string_list, floatmax_t, DT_STRING_LONGREAL) 00356 #undef SET_STRING_LIST 00357 00358 void CHDF5File::get_boolean_type() 00359 { 00360 boolean_type=H5T_NATIVE_UCHAR; 00361 switch (sizeof(bool)) 00362 { 00363 case 1: 00364 boolean_type = H5T_NATIVE_UCHAR; 00365 break; 00366 case 2: 00367 boolean_type = H5T_NATIVE_UINT16; 00368 break; 00369 case 4: 00370 boolean_type = H5T_NATIVE_UINT32; 00371 break; 00372 case 8: 00373 boolean_type = H5T_NATIVE_UINT64; 00374 break; 00375 default: 00376 SG_ERROR("Boolean type not supported on this platform\n"); 00377 } 00378 } 00379 00380 hid_t CHDF5File::get_compatible_type(H5T_class_t t_class, 00381 const TSGDataType* datatype) 00382 { 00383 switch (t_class) 00384 { 00385 case H5T_FLOAT: 00386 case H5T_INTEGER: 00387 switch (datatype->m_ptype) 00388 { 00389 case PT_BOOL: return boolean_type; 00390 case PT_CHAR: return H5T_NATIVE_CHAR; 00391 case PT_INT8: return H5T_NATIVE_INT8; 00392 case PT_UINT8: return H5T_NATIVE_UINT8; 00393 case PT_INT16: return H5T_NATIVE_INT16; 00394 case PT_UINT16: return H5T_NATIVE_UINT16; 00395 case PT_INT32: return H5T_NATIVE_INT32; 00396 case PT_UINT32: return H5T_NATIVE_UINT32; 00397 case PT_INT64: return H5T_NATIVE_INT64; 00398 case PT_UINT64: return H5T_NATIVE_UINT64; 00399 case PT_FLOAT32: return H5T_NATIVE_FLOAT; 00400 case PT_FLOAT64: return H5T_NATIVE_DOUBLE; 00401 case PT_FLOATMAX: return H5T_NATIVE_LDOUBLE; 00402 case PT_SGOBJECT: 00403 SG_ERROR("Implementation error during writing " 00404 "HDF5File!"); 00405 return -1; 00406 } 00407 case H5T_STRING: 00408 SG_ERROR("Strings not supported"); 00409 return -1; 00410 case H5T_VLEN: 00411 SG_ERROR("Variable length containers currently not supported"); 00412 return -1; 00413 case H5T_ARRAY: 00414 SG_ERROR("Array containers currently not supported"); 00415 return -1; 00416 default: 00417 SG_ERROR("Datatype mismatchn"); 00418 return -1; 00419 } 00420 } 00421 00422 void CHDF5File::get_dims(hid_t dataset, int32_t*& dims, int32_t& ndims, int64_t& total_elements) 00423 { 00424 hid_t dataspace = H5Dget_space(dataset); 00425 if (dataspace<0) 00426 SG_ERROR("Error obtaining hdf5 dataspace\n"); 00427 00428 ndims = H5Sget_simple_extent_ndims(dataspace); 00429 total_elements=H5Sget_simple_extent_npoints(dataspace); 00430 hsize_t* dims_out=SG_MALLOC(hsize_t, ndims); 00431 dims=SG_MALLOC(int32_t, ndims); 00432 H5Sget_simple_extent_dims(dataspace, dims_out, NULL); 00433 for (int32_t i=0; i<ndims; i++) 00434 dims[i]=dims_out[i]; 00435 SG_FREE(dims_out); 00436 H5Sclose(dataspace); 00437 } 00438 00439 void CHDF5File::create_group_hierarchy() 00440 { 00441 char* vname=strdup(variable_name); 00442 int32_t vlen=strlen(vname); 00443 for (int32_t i=0; i<vlen; i++) 00444 { 00445 if (i!=0 && vname[i]=='/') 00446 { 00447 vname[i]='\0'; 00448 hid_t g = H5Gopen2(h5file, vname, H5P_DEFAULT); 00449 if (g<0) 00450 { 00451 g=H5Gcreate2(h5file, vname, H5P_DEFAULT, H5P_DEFAULT, 00452 H5P_DEFAULT); 00453 if (g<0) 00454 SG_ERROR("Error creating group '%s'\n", vname); 00455 vname[i]='/'; 00456 } 00457 H5Gclose(g); 00458 } 00459 } 00460 SG_FREE(vname); 00461 } 00462 #endif // HDF5