00001
00002
00003
00004
00005
00006
00007
00008
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, int8_t, (CT_VECTOR, ST_NONE, PT_INT8))
00109 GET_VECTOR(get_vector, uint8_t, (CT_VECTOR, ST_NONE, PT_UINT8))
00110 GET_VECTOR(get_vector, char, (CT_VECTOR, ST_NONE, PT_CHAR))
00111 GET_VECTOR(get_vector, int32_t, (CT_VECTOR, ST_NONE, PT_INT32))
00112 GET_VECTOR(get_vector, uint32_t, (CT_VECTOR, ST_NONE, PT_UINT32))
00113 GET_VECTOR(get_vector, float32_t, (CT_VECTOR, ST_NONE, PT_FLOAT32))
00114 GET_VECTOR(get_vector, float64_t, (CT_VECTOR, ST_NONE, PT_FLOAT64))
00115 GET_VECTOR(get_vector, floatmax_t, (CT_VECTOR, ST_NONE, PT_FLOATMAX))
00116 GET_VECTOR(get_vector, int16_t, (CT_VECTOR, ST_NONE, PT_INT16))
00117 GET_VECTOR(get_vector, uint16_t, (CT_VECTOR, ST_NONE, PT_INT16))
00118 GET_VECTOR(get_vector, int64_t, (CT_VECTOR, ST_NONE, PT_INT64))
00119 GET_VECTOR(get_vector, uint64_t, (CT_VECTOR, ST_NONE, PT_UINT64))
00120 #undef GET_VECTOR
00121
00122 #define GET_MATRIX(fname, sg_type, datatype) \
00123 void CHDF5File::fname(sg_type*& matrix, int32_t& num_feat, int32_t& num_vec) \
00124 { \
00125 if (!h5file) \
00126 SG_ERROR("File invalid.\n"); \
00127 \
00128 int32_t* dims; \
00129 int32_t ndims; \
00130 int64_t nelements; \
00131 hid_t dataset = H5Dopen2(h5file, variable_name, H5P_DEFAULT); \
00132 if (dataset<0) \
00133 SG_ERROR("Error opening data set\n"); \
00134 hid_t dtype = H5Dget_type(dataset); \
00135 H5T_class_t t_class=H5Tget_class(dtype); \
00136 TSGDataType t datatype; hid_t h5_type=get_compatible_type(t_class, &t); \
00137 if (h5_type==-1) \
00138 { \
00139 H5Dclose(dataset); \
00140 SG_INFO("No compatible datatype found\n"); \
00141 } \
00142 get_dims(dataset, dims, ndims, nelements); \
00143 if (ndims!=2) \
00144 SG_ERROR("Error not a 2-dimensional matrix\n"); \
00145 matrix=SG_MALLOC(sg_type, nelements); \
00146 num_feat=dims[0]; \
00147 num_vec=dims[1]; \
00148 herr_t status = H5Dread(dataset, h5_type, H5S_ALL, \
00149 H5S_ALL, H5P_DEFAULT, matrix); \
00150 H5Dclose(dataset); \
00151 H5Tclose(dtype); \
00152 SG_FREE(dims); \
00153 if (status<0) \
00154 { \
00155 SG_FREE(matrix); \
00156 SG_ERROR("Error reading dataset\n"); \
00157 } \
00158 }
00159
00160 GET_MATRIX(get_matrix, bool, (CT_MATRIX, ST_NONE, PT_BOOL))
00161 GET_MATRIX(get_matrix, char, (CT_MATRIX, ST_NONE, PT_CHAR))
00162 GET_MATRIX(get_matrix, uint8_t, (CT_MATRIX, ST_NONE, PT_UINT8))
00163 GET_MATRIX(get_matrix, int32_t, (CT_MATRIX, ST_NONE, PT_INT32))
00164 GET_MATRIX(get_uint_matrix, uint32_t, (CT_MATRIX, ST_NONE, PT_INT32))
00165 GET_MATRIX(get_long_matrix, int64_t, (CT_MATRIX, ST_NONE, PT_INT64))
00166 GET_MATRIX(get_ulong_matrix, uint64_t, (CT_MATRIX, ST_NONE, PT_INT64))
00167 GET_MATRIX(get_matrix, int16_t, (CT_MATRIX, ST_NONE, PT_INT16))
00168 GET_MATRIX(get_matrix, uint16_t, (CT_MATRIX, ST_NONE, PT_INT16))
00169 GET_MATRIX(get_matrix, float32_t, (CT_MATRIX, ST_NONE, PT_FLOAT32))
00170 GET_MATRIX(get_matrix, float64_t, (CT_MATRIX, ST_NONE, PT_FLOAT64))
00171 GET_MATRIX(get_longreal_matrix, floatmax_t, (CT_MATRIX, ST_NONE, PT_FLOATMAX))
00172 #undef GET_MATRIX
00173
00174 void CHDF5File::get_ndarray(uint8_t*& array, int32_t*& dims, int32_t& num_dims)
00175 {
00176 }
00177
00178 void CHDF5File::get_ndarray(char*& array, int32_t*& dims, int32_t& num_dims)
00179 {
00180 }
00181
00182 void CHDF5File::get_ndarray(int32_t*& array, int32_t*& dims, int32_t& num_dims)
00183 {
00184 }
00185
00186 void CHDF5File::get_ndarray(float32_t*& array, int32_t*& dims, int32_t& num_dims)
00187 {
00188 }
00189
00190 void CHDF5File::get_ndarray(float64_t*& array, int32_t*& dims, int32_t& num_dims)
00191 {
00192 }
00193
00194 void CHDF5File::get_ndarray(int16_t*& array, int32_t*& dims, int32_t& num_dims)
00195 {
00196 }
00197
00198 void CHDF5File::get_ndarray(uint16_t*& array, int32_t*& dims, int32_t& num_dims)
00199 {
00200 }
00201
00202 #define GET_SPARSEMATRIX(fname, sg_type, datatype) \
00203 void CHDF5File::fname(SGSparseVector<sg_type>*& matrix, int32_t& num_feat, int32_t& num_vec) \
00204 { \
00205 if (!(file)) \
00206 SG_ERROR("File invalid.\n"); \
00207 }
00208 GET_SPARSEMATRIX(get_sparse_matrix, bool, DT_SPARSE_BOOL)
00209 GET_SPARSEMATRIX(get_sparse_matrix, char, DT_SPARSE_CHAR)
00210 GET_SPARSEMATRIX(get_sparse_matrix, uint8_t, DT_SPARSE_BYTE)
00211 GET_SPARSEMATRIX(get_sparse_matrix, int32_t, DT_SPARSE_INT)
00212 GET_SPARSEMATRIX(get_uint_sparsematrix, uint32_t, DT_SPARSE_UINT)
00213 GET_SPARSEMATRIX(get_long_sparsematrix, int64_t, DT_SPARSE_LONG)
00214 GET_SPARSEMATRIX(get_ulong_sparsematrix, uint64_t, DT_SPARSE_ULONG)
00215 GET_SPARSEMATRIX(get_sparse_matrix, int16_t, DT_SPARSE_SHORT)
00216 GET_SPARSEMATRIX(get_sparse_matrix, uint16_t, DT_SPARSE_WORD)
00217 GET_SPARSEMATRIX(get_sparse_matrix, float32_t, DT_SPARSE_SHORTREAL)
00218 GET_SPARSEMATRIX(get_sparse_matrix, float64_t, DT_SPARSE_REAL)
00219 GET_SPARSEMATRIX(get_longreal_sparsematrix, floatmax_t, DT_SPARSE_LONGREAL)
00220 #undef GET_SPARSEMATRIX
00221
00222
00223 #define GET_STRING_LIST(fname, sg_type, datatype) \
00224 void CHDF5File::fname(SGString<sg_type>*& strings, int32_t& num_str, int32_t& max_string_len) \
00225 { \
00226 }
00227
00228 GET_STRING_LIST(get_string_list, bool, DT_STRING_BOOL)
00229 GET_STRING_LIST(get_string_list, char, DT_STRING_CHAR)
00230 GET_STRING_LIST(get_string_list, uint8_t, DT_STRING_BYTE)
00231 GET_STRING_LIST(get_string_list, int32_t, DT_STRING_INT)
00232 GET_STRING_LIST(get_uint_string_list, uint32_t, DT_STRING_UINT)
00233 GET_STRING_LIST(get_long_string_list, int64_t, DT_STRING_LONG)
00234 GET_STRING_LIST(get_ulong_string_list, uint64_t, DT_STRING_ULONG)
00235 GET_STRING_LIST(get_string_list, int16_t, DT_STRING_SHORT)
00236 GET_STRING_LIST(get_string_list, uint16_t, DT_STRING_WORD)
00237 GET_STRING_LIST(get_string_list, float32_t, DT_STRING_SHORTREAL)
00238 GET_STRING_LIST(get_string_list, float64_t, DT_STRING_REAL)
00239 GET_STRING_LIST(get_longreal_string_list, floatmax_t, DT_STRING_LONGREAL)
00240 #undef GET_STRING_LIST
00241
00244 #define SET_VECTOR(fname, sg_type, dtype, h5type) \
00245 void CHDF5File::fname(const sg_type* vec, int32_t len) \
00246 { \
00247 if (h5file<0 || !vec) \
00248 SG_ERROR("File or vector invalid.\n"); \
00249 \
00250 create_group_hierarchy(); \
00251 \
00252 hsize_t dims=(hsize_t) len; \
00253 hid_t dataspace, dataset, status; \
00254 dataspace=H5Screate_simple(1, &dims, NULL); \
00255 if (dataspace<0) \
00256 SG_ERROR("Could not create hdf5 dataspace\n"); \
00257 dataset=H5Dcreate2(h5file, variable_name, h5type, dataspace, H5P_DEFAULT,\
00258 H5P_DEFAULT, H5P_DEFAULT); \
00259 if (dataset<0) \
00260 { \
00261 SG_ERROR("Could not create hdf5 dataset - does" \
00262 " dataset '%s' already exist?\n", variable_name); \
00263 } \
00264 status=H5Dwrite(dataset, h5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, vec); \
00265 if (status<0) \
00266 SG_ERROR("Failed to write hdf5 dataset\n"); \
00267 H5Dclose(dataset); \
00268 H5Sclose(dataspace); \
00269 }
00270 SET_VECTOR(set_vector, bool, DT_VECTOR_BOOL, boolean_type)
00271 SET_VECTOR(set_vector, int8_t, DT_VECTOR_BYTE, H5T_NATIVE_INT8)
00272 SET_VECTOR(set_vector, uint8_t, DT_VECTOR_BYTE, H5T_NATIVE_UINT8)
00273 SET_VECTOR(set_vector, char, DT_VECTOR_CHAR, H5T_NATIVE_CHAR)
00274 SET_VECTOR(set_vector, int32_t, DT_VECTOR_INT, H5T_NATIVE_INT32)
00275 SET_VECTOR(set_vector, uint32_t, DT_VECTOR_UINT, H5T_NATIVE_UINT32)
00276 SET_VECTOR(set_vector, float32_t, DT_VECTOR_SHORTREAL, H5T_NATIVE_FLOAT)
00277 SET_VECTOR(set_vector, float64_t, DT_VECTOR_REAL, H5T_NATIVE_DOUBLE)
00278 SET_VECTOR(set_vector, floatmax_t, DT_VECTOR_LONGREAL, H5T_NATIVE_LDOUBLE)
00279 SET_VECTOR(set_vector, int16_t, DT_VECTOR_SHORT, H5T_NATIVE_INT16)
00280 SET_VECTOR(set_vector, uint16_t, DT_VECTOR_WORD, H5T_NATIVE_UINT16)
00281 SET_VECTOR(set_vector, int64_t, DT_VECTOR_LONG, H5T_NATIVE_LLONG)
00282 SET_VECTOR(set_vector, uint64_t, DT_VECTOR_ULONG, H5T_NATIVE_ULLONG)
00283 #undef SET_VECTOR
00284
00285 #define SET_MATRIX(fname, sg_type, dtype, h5type) \
00286 void CHDF5File::fname(const sg_type* matrix, int32_t num_feat, int32_t num_vec) \
00287 { \
00288 if (h5file<0 || !matrix) \
00289 SG_ERROR("File or matrix invalid.\n"); \
00290 \
00291 create_group_hierarchy(); \
00292 \
00293 hsize_t dims[2]={(hsize_t) num_feat, (hsize_t) num_vec}; \
00294 hid_t dataspace, dataset, status; \
00295 dataspace=H5Screate_simple(2, dims, NULL); \
00296 if (dataspace<0) \
00297 SG_ERROR("Could not create hdf5 dataspace\n"); \
00298 dataset=H5Dcreate2(h5file, variable_name, h5type, dataspace, H5P_DEFAULT, \
00299 H5P_DEFAULT, H5P_DEFAULT); \
00300 if (dataset<0) \
00301 { \
00302 SG_ERROR("Could not create hdf5 dataset - does" \
00303 " dataset '%s' already exist?\n", variable_name); \
00304 } \
00305 status=H5Dwrite(dataset, h5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, matrix); \
00306 if (status<0) \
00307 SG_ERROR("Failed to write hdf5 dataset\n"); \
00308 H5Dclose(dataset); \
00309 H5Sclose(dataspace); \
00310 }
00311 SET_MATRIX(set_matrix, bool, DT_DENSE_BOOL, boolean_type)
00312 SET_MATRIX(set_matrix, char, DT_DENSE_CHAR, H5T_NATIVE_CHAR)
00313 SET_MATRIX(set_matrix, uint8_t, DT_DENSE_BYTE, H5T_NATIVE_UINT8)
00314 SET_MATRIX(set_matrix, int32_t, DT_DENSE_INT, H5T_NATIVE_INT32)
00315 SET_MATRIX(set_uint_matrix, uint32_t, DT_DENSE_UINT, H5T_NATIVE_UINT32)
00316 SET_MATRIX(set_long_matrix, int64_t, DT_DENSE_LONG, H5T_NATIVE_INT64)
00317 SET_MATRIX(set_ulong_matrix, uint64_t, DT_DENSE_ULONG, H5T_NATIVE_UINT64)
00318 SET_MATRIX(set_matrix, int16_t, DT_DENSE_SHORT, H5T_NATIVE_INT16)
00319 SET_MATRIX(set_matrix, uint16_t, DT_DENSE_WORD, H5T_NATIVE_UINT16)
00320 SET_MATRIX(set_matrix, float32_t, DT_DENSE_SHORTREAL, H5T_NATIVE_FLOAT)
00321 SET_MATRIX(set_matrix, float64_t, DT_DENSE_REAL, H5T_NATIVE_DOUBLE)
00322 SET_MATRIX(set_longreal_matrix, floatmax_t, DT_DENSE_LONGREAL, H5T_NATIVE_LDOUBLE)
00323 #undef SET_MATRIX
00324
00325 #define SET_SPARSEMATRIX(fname, sg_type, dtype) \
00326 void CHDF5File::fname(const SGSparseVector<sg_type>* matrix, \
00327 int32_t num_feat, int32_t num_vec) \
00328 { \
00329 if (!(file && matrix)) \
00330 SG_ERROR("File or matrix invalid.\n"); \
00331 \
00332 }
00333 SET_SPARSEMATRIX(set_sparse_matrix, bool, DT_SPARSE_BOOL)
00334 SET_SPARSEMATRIX(set_sparse_matrix, char, DT_SPARSE_CHAR)
00335 SET_SPARSEMATRIX(set_sparse_matrix, uint8_t, DT_SPARSE_BYTE)
00336 SET_SPARSEMATRIX(set_sparse_matrix, int32_t, DT_SPARSE_INT)
00337 SET_SPARSEMATRIX(set_uint_sparsematrix, uint32_t, DT_SPARSE_UINT)
00338 SET_SPARSEMATRIX(set_long_sparsematrix, int64_t, DT_SPARSE_LONG)
00339 SET_SPARSEMATRIX(set_ulong_sparsematrix, uint64_t, DT_SPARSE_ULONG)
00340 SET_SPARSEMATRIX(set_sparse_matrix, int16_t, DT_SPARSE_SHORT)
00341 SET_SPARSEMATRIX(set_sparse_matrix, uint16_t, DT_SPARSE_WORD)
00342 SET_SPARSEMATRIX(set_sparse_matrix, float32_t, DT_SPARSE_SHORTREAL)
00343 SET_SPARSEMATRIX(set_sparse_matrix, float64_t, DT_SPARSE_REAL)
00344 SET_SPARSEMATRIX(set_longreal_sparsematrix, floatmax_t, DT_SPARSE_LONGREAL)
00345 #undef SET_SPARSEMATRIX
00346
00347 #define SET_STRING_LIST(fname, sg_type, dtype) \
00348 void CHDF5File::fname(const SGString<sg_type>* strings, int32_t num_str) \
00349 { \
00350 if (!(file && strings)) \
00351 SG_ERROR("File or strings invalid.\n"); \
00352 \
00353 }
00354 SET_STRING_LIST(set_string_list, bool, DT_STRING_BOOL)
00355 SET_STRING_LIST(set_string_list, char, DT_STRING_CHAR)
00356 SET_STRING_LIST(set_string_list, uint8_t, DT_STRING_BYTE)
00357 SET_STRING_LIST(set_string_list, int32_t, DT_STRING_INT)
00358 SET_STRING_LIST(set_uint_string_list, uint32_t, DT_STRING_UINT)
00359 SET_STRING_LIST(set_long_string_list, int64_t, DT_STRING_LONG)
00360 SET_STRING_LIST(set_ulong_string_list, uint64_t, DT_STRING_ULONG)
00361 SET_STRING_LIST(set_string_list, int16_t, DT_STRING_SHORT)
00362 SET_STRING_LIST(set_string_list, uint16_t, DT_STRING_WORD)
00363 SET_STRING_LIST(set_string_list, float32_t, DT_STRING_SHORTREAL)
00364 SET_STRING_LIST(set_string_list, float64_t, DT_STRING_REAL)
00365 SET_STRING_LIST(set_longreal_string_list, floatmax_t, DT_STRING_LONGREAL)
00366 #undef SET_STRING_LIST
00367
00368 void CHDF5File::get_boolean_type()
00369 {
00370 boolean_type=H5T_NATIVE_UCHAR;
00371 switch (sizeof(bool))
00372 {
00373 case 1:
00374 boolean_type = H5T_NATIVE_UCHAR;
00375 break;
00376 case 2:
00377 boolean_type = H5T_NATIVE_UINT16;
00378 break;
00379 case 4:
00380 boolean_type = H5T_NATIVE_UINT32;
00381 break;
00382 case 8:
00383 boolean_type = H5T_NATIVE_UINT64;
00384 break;
00385 default:
00386 SG_ERROR("Boolean type not supported on this platform\n");
00387 }
00388 }
00389
00390 hid_t CHDF5File::get_compatible_type(H5T_class_t t_class,
00391 const TSGDataType* datatype)
00392 {
00393 switch (t_class)
00394 {
00395 case H5T_FLOAT:
00396 case H5T_INTEGER:
00397 switch (datatype->m_ptype)
00398 {
00399 case PT_BOOL: return boolean_type;
00400 case PT_CHAR: return H5T_NATIVE_CHAR;
00401 case PT_INT8: return H5T_NATIVE_INT8;
00402 case PT_UINT8: return H5T_NATIVE_UINT8;
00403 case PT_INT16: return H5T_NATIVE_INT16;
00404 case PT_UINT16: return H5T_NATIVE_UINT16;
00405 case PT_INT32: return H5T_NATIVE_INT32;
00406 case PT_UINT32: return H5T_NATIVE_UINT32;
00407 case PT_INT64: return H5T_NATIVE_INT64;
00408 case PT_UINT64: return H5T_NATIVE_UINT64;
00409 case PT_FLOAT32: return H5T_NATIVE_FLOAT;
00410 case PT_FLOAT64: return H5T_NATIVE_DOUBLE;
00411 case PT_FLOATMAX: return H5T_NATIVE_LDOUBLE;
00412 case PT_SGOBJECT:
00413 SG_ERROR("Implementation error during writing "
00414 "HDF5File!");
00415 return -1;
00416 }
00417 case H5T_STRING:
00418 SG_ERROR("Strings not supported");
00419 return -1;
00420 case H5T_VLEN:
00421 SG_ERROR("Variable length containers currently not supported");
00422 return -1;
00423 case H5T_ARRAY:
00424 SG_ERROR("Array containers currently not supported");
00425 return -1;
00426 default:
00427 SG_ERROR("Datatype mismatchn");
00428 return -1;
00429 }
00430 }
00431
00432 void CHDF5File::get_dims(hid_t dataset, int32_t*& dims, int32_t& ndims, int64_t& total_elements)
00433 {
00434 hid_t dataspace = H5Dget_space(dataset);
00435 if (dataspace<0)
00436 SG_ERROR("Error obtaining hdf5 dataspace\n");
00437
00438 ndims = H5Sget_simple_extent_ndims(dataspace);
00439 total_elements=H5Sget_simple_extent_npoints(dataspace);
00440 hsize_t* dims_out=SG_MALLOC(hsize_t, ndims);
00441 dims=SG_MALLOC(int32_t, ndims);
00442 H5Sget_simple_extent_dims(dataspace, dims_out, NULL);
00443 for (int32_t i=0; i<ndims; i++)
00444 dims[i]=dims_out[i];
00445 SG_FREE(dims_out);
00446 H5Sclose(dataspace);
00447 }
00448
00449 void CHDF5File::create_group_hierarchy()
00450 {
00451 char* vname=strdup(variable_name);
00452 int32_t vlen=strlen(vname);
00453 for (int32_t i=0; i<vlen; i++)
00454 {
00455 if (i!=0 && vname[i]=='/')
00456 {
00457 vname[i]='\0';
00458 hid_t g = H5Gopen2(h5file, vname, H5P_DEFAULT);
00459 if (g<0)
00460 {
00461 g=H5Gcreate2(h5file, vname, H5P_DEFAULT, H5P_DEFAULT,
00462 H5P_DEFAULT);
00463 if (g<0)
00464 SG_ERROR("Error creating group '%s'\n", vname);
00465 vname[i]='/';
00466 }
00467 H5Gclose(g);
00468 }
00469 }
00470 SG_FREE(vname);
00471 }
00472 #endif // HDF5