36 #ifndef VIGRA_HDF5IMPEX_HXX
37 #define VIGRA_HDF5IMPEX_HXX
41 #define H5Gcreate_vers 2
42 #define H5Gopen_vers 2
43 #define H5Dopen_vers 2
44 #define H5Dcreate_vers 2
45 #define H5Acreate_vers 2
49 #if (H5_VERS_MAJOR == 1 && H5_VERS_MINOR <= 6)
51 # define H5Gopen(a, b, c) H5Gopen(a, b)
54 # define H5Gcreate(a, b, c, d, e) H5Gcreate(a, b, 1)
57 # define H5Dopen(a, b, c) H5Dopen(a, b)
60 # define H5Dcreate(a, b, c, d, e, f, g) H5Dcreate(a, b, c, d, f)
63 # define H5Acreate(a, b, c, d, e, f) H5Acreate(a, b, c, d, e)
65 # ifndef H5Pset_obj_track_times
66 # define H5Pset_obj_track_times(a, b) do {} while (0)
74 #include "multi_array.hxx"
75 #include "multi_iterator_coupled.hxx"
76 #include "multi_impex.hxx"
77 #include "utilities.hxx"
100 inline bool isHDF5(
char const * filename)
103 return _access(filename, 0) != -1 && H5Fis_hdf5(filename);
105 return access(filename, F_OK) == 0 && H5Fis_hdf5(filename);
137 typedef herr_t (*Destructor)(hid_t);
141 Destructor destructor_;
172 HDF5Handle(hid_t h, Destructor destructor,
const char * error_message)
174 destructor_(destructor)
177 vigra_fail(error_message);
184 : handle_( h.handle_ ),
185 destructor_(h.destructor_)
196 if(h.handle_ != handle_)
200 destructor_ = h.destructor_;
220 if(handle_ && destructor_)
221 res = (*destructor_)(handle_);
241 operator hid_t()
const
250 return handle_ == h.handle_;
264 return handle_ != h.handle_;
293 enum PixelType { UINT8, UINT16, UINT32, UINT64,
294 INT8, INT16, INT32, INT64,
307 VIGRA_EXPORT
HDF5ImportInfo(
const char* filePath,
const char* pathInFile );
309 VIGRA_EXPORT ~HDF5ImportInfo();
313 VIGRA_EXPORT
const std::string&
getFilePath()
const;
389 VIGRA_EXPORT PixelType
pixelType()
const;
393 std::string m_filename, m_path, m_pixeltype;
394 hssize_t m_dimensions;
402 inline hid_t getH5DataType()
404 std::runtime_error(
"getH5DataType(): invalid type");
408 #define VIGRA_H5_DATATYPE(type, h5type) \
410 inline hid_t getH5DataType<type>() \
413 VIGRA_H5_DATATYPE(
char, H5T_NATIVE_CHAR)
414 VIGRA_H5_DATATYPE(
float, H5T_NATIVE_FLOAT)
415 VIGRA_H5_DATATYPE(
double, H5T_NATIVE_DOUBLE)
416 VIGRA_H5_DATATYPE(
long double, H5T_NATIVE_LDOUBLE)
420 inline hid_t getH5DataType<
char*>()
422 hid_t stringtype = H5Tcopy (H5T_C_S1);
423 H5Tset_size(stringtype, H5T_VARIABLE);
427 inline hid_t getH5DataType<const char*>()
429 hid_t stringtype = H5Tcopy (H5T_C_S1);
430 H5Tset_size(stringtype, H5T_VARIABLE);
433 #undef VIGRA_H5_DATATYPE
435 template <
unsigned int SIZE>
436 struct HDF5TypeBySize;
439 struct HDF5TypeBySize<1>
441 static hid_t signed_type() {
return H5T_NATIVE_INT8; }
442 static hid_t unsigned_type() {
return H5T_NATIVE_UINT8; }
446 struct HDF5TypeBySize<2>
448 static hid_t signed_type() {
return H5T_NATIVE_INT16; }
449 static hid_t unsigned_type() {
return H5T_NATIVE_UINT16; }
453 struct HDF5TypeBySize<4>
455 static hid_t signed_type() {
return H5T_NATIVE_INT32; }
456 static hid_t unsigned_type() {
return H5T_NATIVE_UINT32; }
460 struct HDF5TypeBySize<8>
462 static hid_t signed_type() {
return H5T_NATIVE_INT64; }
463 static hid_t unsigned_type() {
return H5T_NATIVE_UINT64; }
466 #define VIGRA_H5_SIGNED_DATATYPE(type) \
468 inline hid_t getH5DataType<type>() \
469 { return HDF5TypeBySize<sizeof(type)>::signed_type(); }
471 VIGRA_H5_SIGNED_DATATYPE(
signed char)
472 VIGRA_H5_SIGNED_DATATYPE(
signed short)
473 VIGRA_H5_SIGNED_DATATYPE(
signed int)
474 VIGRA_H5_SIGNED_DATATYPE(
signed long)
475 VIGRA_H5_SIGNED_DATATYPE(
signed long long)
477 #undef VIGRA_H5_SIGNED_DATATYPE
479 #define VIGRA_H5_UNSIGNED_DATATYPE(type) \
481 inline hid_t getH5DataType<type>() \
482 { return HDF5TypeBySize<sizeof(type)>::unsigned_type(); }
484 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned char)
485 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned short)
486 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned int)
487 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned long)
488 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned long long)
490 #undef VIGRA_H5_UNSIGNED_DATATYPE
494 inline hid_t getH5DataType<FFTWComplex<float> >()
496 hid_t complex_id = H5Tcreate (H5T_COMPOUND,
sizeof (FFTWComplex<float>));
497 H5Tinsert (complex_id,
"real", 0, H5T_NATIVE_FLOAT);
498 H5Tinsert (complex_id,
"imaginary",
sizeof(
float), H5T_NATIVE_FLOAT);
503 inline hid_t getH5DataType<FFTWComplex<double> >()
505 hid_t complex_id = H5Tcreate (H5T_COMPOUND,
sizeof (FFTWComplex<double>));
506 H5Tinsert (complex_id,
"real", 0, H5T_NATIVE_DOUBLE);
507 H5Tinsert (complex_id,
"imaginary",
sizeof(
double), H5T_NATIVE_DOUBLE);
516 void HDF5_ls_insert(
void*,
const std::string &);
521 VIGRA_EXPORT H5O_type_t HDF5_get_type(hid_t,
const char*);
522 extern "C" VIGRA_EXPORT herr_t HDF5_ls_inserter_callback(hid_t,
const char*,
const H5L_info_t*,
void*);
577 virtual void insert(
const std::string &) = 0;
578 virtual ~ls_closure() {}
581 struct lsOpData :
public ls_closure
583 std::vector<std::string> & objects;
584 lsOpData(std::vector<std::string> & o) : objects(o) {}
585 void insert(
const std::string & x)
587 objects.push_back(x);
591 template<
class Container>
592 struct ls_container_data :
public ls_closure
595 ls_container_data(Container & o) : objects(o) {}
596 void insert(
const std::string & x)
598 objects.insert(std::string(x));
605 friend void HDF5_ls_insert(
void*,
const std::string &);
628 : track_time(track_creation_times)
640 : track_time(track_creation_times)
642 open(filename, mode);
670 std::string errorMessage =
"HDF5File.open(): Could not open or create file '" + filename +
"'.";
671 fileHandle_ =
HDF5Handle(createFile_(filename, mode), &H5Fclose, errorMessage.c_str());
672 cGroupHandle_ =
HDF5Handle(openCreateGroup_(
"/"), &H5Gclose,
"HDF5File.open(): Failed to open root group.");
679 bool success = cGroupHandle_.
close() >= 0 && fileHandle_.
close() >= 0;
680 vigra_postcondition(success,
"HDF5File.close() failed.");
687 std::string message =
"HDF5File::root(): Could not open group '/'.";
688 cGroupHandle_ =
HDF5Handle(H5Gopen(fileHandle_,
"/", H5P_DEFAULT),&H5Gclose,message.c_str());
694 inline void cd(std::string groupName)
705 std::string groupName = currentGroupName_();
708 if(groupName ==
"/"){
712 size_t lastSlash = groupName.find_last_of(
'/');
714 std::string parentGroup (groupName.begin(), groupName.begin()+lastSlash+1);
727 std::string groupName = currentGroupName_();
729 for(
int i = 0; i<levels; i++)
734 if(groupName != currentGroupName_())
746 inline void mkdir(std::string groupName)
748 std::string message =
"HDF5File::mkdir(): Could not create group '" + groupName +
"'.\n";
753 HDF5Handle(openCreateGroup_(groupName.c_str()),&H5Gclose,message.c_str());
760 inline void cd_mk(std::string groupName)
762 std::string message =
"HDF5File::cd_mk(): Could not create group '" + groupName +
"'.";
767 cGroupHandle_ =
HDF5Handle(openCreateGroup_(groupName.c_str()),&H5Gclose,message.c_str());
771 void ls_H5Literate(ls_closure & data)
const
773 H5Literate(cGroupHandle_, H5_INDEX_NAME, H5_ITER_NATIVE, NULL,
774 HDF5_ls_inserter_callback, static_cast<void*>(&data));
782 inline std::vector<std::string>
ls()
const
784 std::vector<std::string> list;
803 template<
class Container>
804 void ls(Container & cont)
const
806 ls_container_data<Container> data(cont);
812 inline std::string
pwd()
const
814 return currentGroupName_();
830 return (H5Lexists(fileHandle_, datasetName.c_str(), H5P_DEFAULT) > 0);
843 std::string errorMessage =
"HDF5File::getDatasetDimensions(): Unable to open dataset '" + datasetName +
"'.";
844 HDF5Handle datasetHandle =
HDF5Handle(getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
846 errorMessage =
"HDF5File::getDatasetDimensions(): Unable to access dataspace.";
847 HDF5Handle dataspaceHandle(H5Dget_space(datasetHandle), &H5Sclose, errorMessage.c_str());
850 return H5Sget_simple_extent_ndims(dataspaceHandle);
872 std::string errorMessage =
"HDF5File::getDatasetShape(): Unable to open dataset '" + datasetName +
"'.";
873 HDF5Handle datasetHandle =
HDF5Handle(getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
875 errorMessage =
"HDF5File::getDatasetShape(): Unable to access dataspace.";
876 HDF5Handle dataspaceHandle(H5Dget_space(datasetHandle), &H5Sclose, errorMessage.c_str());
883 H5Sget_simple_extent_dims(dataspaceHandle, shape.
data(), maxdims.
data());
911 hid_t datatype = H5Dget_type(datasetHandle);
912 H5T_class_t dataclass = H5Tget_class(datatype);
913 size_t datasize = H5Tget_size(datatype);
914 H5T_sign_t datasign = H5Tget_sign(datatype);
916 if(dataclass == H5T_FLOAT)
920 else if(datasize == 8)
923 else if(dataclass == H5T_INTEGER)
925 if(datasign == H5T_SGN_NONE)
929 else if(datasize == 2)
931 else if(datasize == 4)
933 else if(datasize == 8)
940 else if(datasize == 2)
942 else if(datasize == 4)
944 else if(datasize == 8)
955 std::string errorMessage =
"HDF5File::getDatasetHandle(): Unable to open dataset '" + datasetName +
"'.";
963 std::string errorMessage = function_name +
": Group '" + group_name +
"' not found.";
969 vigra_precondition(group_name ==
"/" || H5Lexists(fileHandle_, group_name.c_str(), H5P_DEFAULT) != 0,
970 errorMessage.c_str());
973 return HDF5Handle(openCreateGroup_(group_name), &H5Gclose,
"Internal error");
980 std::string message =
"HDF5File::getAttributeHandle(): Attribute '" + attribute_name +
"' not found.";
982 &H5Aclose, message.c_str());
990 template<
unsigned int N,
class T,
class Str
ide>
992 std::string attribute_name,
998 write_attribute_(object_name, attribute_name, array, detail::getH5DataType<T>(), 1);
1001 template<
unsigned int N,
class T,
int SIZE,
class Str
ide>
1003 std::string attributeName,
1009 write_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), SIZE);
1012 template<
unsigned int N,
class T,
class Str
ide>
1014 std::string attributeName,
1015 const MultiArrayView<N, RGBValue<T>, Stride> & array)
1020 write_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), 3);
1026 inline void writeAttribute(std::string object_name, std::string attribute_name,
char data)
1027 { writeAtomicAttribute(object_name,attribute_name,data); }
1028 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed char data)
1029 { writeAtomicAttribute(datasetName,attributeName,data); }
1030 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed short data)
1031 { writeAtomicAttribute(datasetName,attributeName,data); }
1032 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed int data)
1033 { writeAtomicAttribute(datasetName,attributeName,data); }
1034 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed long data)
1035 { writeAtomicAttribute(datasetName,attributeName,data); }
1036 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed long long data)
1037 { writeAtomicAttribute(datasetName,attributeName,data); }
1038 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned char data)
1039 { writeAtomicAttribute(datasetName,attributeName,data); }
1040 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned short data)
1041 { writeAtomicAttribute(datasetName,attributeName,data); }
1042 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned int data)
1043 { writeAtomicAttribute(datasetName,attributeName,data); }
1044 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned long data)
1045 { writeAtomicAttribute(datasetName,attributeName,data); }
1046 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned long long data)
1047 { writeAtomicAttribute(datasetName,attributeName,data); }
1048 inline void writeAttribute(std::string datasetName, std::string attributeName,
float data)
1049 { writeAtomicAttribute(datasetName,attributeName,data); }
1050 inline void writeAttribute(std::string datasetName, std::string attributeName,
double data)
1051 { writeAtomicAttribute(datasetName,attributeName,data); }
1052 inline void writeAttribute(std::string datasetName, std::string attributeName,
long double data)
1053 { writeAtomicAttribute(datasetName,attributeName,data); }
1054 inline void writeAttribute(std::string datasetName, std::string attributeName,
const char* data)
1055 { writeAtomicAttribute(datasetName,attributeName,data); }
1056 inline void writeAttribute(std::string datasetName, std::string attributeName, std::string
const & data)
1057 { writeAtomicAttribute(datasetName,attributeName,data.c_str()); }
1064 htri_t exists = H5Aexists_by_name(fileHandle_, obj_path.c_str(),
1065 attribute_name.c_str(), H5P_DEFAULT);
1066 vigra_precondition(exists >= 0,
"HDF5File::existsAttribute(): "
1067 "object '" + object_name +
"' "
1077 template<
unsigned int N,
class T,
class Str
ide>
1079 std::string attribute_name,
1085 read_attribute_(object_name, attribute_name, array, detail::getH5DataType<T>(), 1);
1088 template<
unsigned int N,
class T,
int SIZE,
class Str
ide>
1090 std::string attributeName,
1096 read_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), SIZE);
1099 template<
unsigned int N,
class T,
class Str
ide>
1101 std::string attributeName,
1102 MultiArrayView<N, RGBValue<T>, Stride> array)
1107 read_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), 3);
1113 inline void readAttribute(std::string object_name, std::string attribute_name,
char &data)
1114 { readAtomicAttribute(object_name,attribute_name,data); }
1115 inline void readAttribute(std::string datasetName, std::string attributeName,
signed char &data)
1116 { readAtomicAttribute(datasetName,attributeName,data); }
1117 inline void readAttribute(std::string datasetName, std::string attributeName,
signed short &data)
1118 { readAtomicAttribute(datasetName,attributeName,data); }
1119 inline void readAttribute(std::string datasetName, std::string attributeName,
signed int &data)
1120 { readAtomicAttribute(datasetName,attributeName,data); }
1121 inline void readAttribute(std::string datasetName, std::string attributeName,
signed long &data)
1122 { readAtomicAttribute(datasetName,attributeName,data); }
1123 inline void readAttribute(std::string datasetName, std::string attributeName,
signed long long &data)
1124 { readAtomicAttribute(datasetName,attributeName,data); }
1125 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned char &data)
1126 { readAtomicAttribute(datasetName,attributeName,data); }
1127 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned short &data)
1128 { readAtomicAttribute(datasetName,attributeName,data); }
1129 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned int &data)
1130 { readAtomicAttribute(datasetName,attributeName,data); }
1131 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned long &data)
1132 { readAtomicAttribute(datasetName,attributeName,data); }
1133 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned long long &data)
1134 { readAtomicAttribute(datasetName,attributeName,data); }
1135 inline void readAttribute(std::string datasetName, std::string attributeName,
float &data)
1136 { readAtomicAttribute(datasetName,attributeName,data); }
1137 inline void readAttribute(std::string datasetName, std::string attributeName,
double &data)
1138 { readAtomicAttribute(datasetName,attributeName,data); }
1139 inline void readAttribute(std::string datasetName, std::string attributeName,
long double &data)
1140 { readAtomicAttribute(datasetName,attributeName,data); }
1141 inline void readAttribute(std::string datasetName, std::string attributeName, std::string &data)
1142 { readAtomicAttribute(datasetName,attributeName,data); }
1170 template<
unsigned int N,
class T,
class Str
ide>
1171 inline void write(std::string datasetName,
1173 int iChunkSize = 0,
int compression = 0)
1179 for(
unsigned int i = 0; i < N; i++){
1180 chunkSize[i] = iChunkSize;
1182 write_(datasetName, array, detail::getH5DataType<T>(), 1, chunkSize, compression);
1202 template<
unsigned int N,
class T,
class Str
ide>
1203 inline void write(std::string datasetName,
1210 write_(datasetName, array, detail::getH5DataType<T>(), 1, chunkSize, compression);
1224 template<
unsigned int N,
class T,
class Str
ide>
1232 writeBlock_(datasetName, blockOffset, array, detail::getH5DataType<T>(), 1);
1236 template<
unsigned int N,
class T,
int SIZE,
class Str
ide>
1237 inline void write(std::string datasetName,
1239 int iChunkSize = 0,
int compression = 0)
1245 for(
int i = 0; i < N; i++){
1246 chunkSize[i] = iChunkSize;
1248 write_(datasetName, array, detail::getH5DataType<T>(), SIZE, chunkSize, compression);
1251 template<
unsigned int N,
class T,
int SIZE,
class Str
ide>
1252 inline void write(std::string datasetName,
1253 const MultiArrayView<N, TinyVector<T, SIZE>, Stride> & array,
1254 typename MultiArrayShape<N>::type chunkSize,
int compression = 0)
1259 write_(datasetName, array, detail::getH5DataType<T>(), SIZE, chunkSize, compression);
1273 void write(
const std::string & datasetName,
1275 int compression = 0)
1280 write(datasetName, m_array, compression);
1283 template<
unsigned int N,
class T,
int SIZE,
class Str
ide>
1284 inline void writeBlock(std::string datasetName,
1291 writeBlock_(datasetName, blockOffset, array, detail::getH5DataType<T>(), SIZE);
1295 template<
unsigned int N,
class T,
class Str
ide>
1296 inline void write(std::string datasetName,
1297 const MultiArrayView<N, RGBValue<T>, Stride> & array,
1298 int iChunkSize = 0,
int compression = 0)
1303 typename MultiArrayShape<N>::type chunkSize;
1304 for(
int i = 0; i < N; i++){
1305 chunkSize[i] = iChunkSize;
1307 write_(datasetName, array, detail::getH5DataType<T>(), 3, chunkSize, compression);
1310 template<
unsigned int N,
class T,
class Str
ide>
1311 inline void write(std::string datasetName,
1312 const MultiArrayView<N, RGBValue<T>, Stride> & array,
1313 typename MultiArrayShape<N>::type chunkSize,
int compression = 0)
1318 write_(datasetName, array, detail::getH5DataType<T>(), 3, chunkSize, compression);
1321 template<
unsigned int N,
class T,
class Str
ide>
1322 inline void writeBlock(std::string datasetName,
1323 typename MultiArrayShape<N>::type blockOffset,
1324 const MultiArrayView<N, RGBValue<T>, Stride> & array)
1329 writeBlock_(datasetName, blockOffset, array, detail::getH5DataType<T>(), 3);
1335 inline void write(std::string datasetName,
char data) { writeAtomic(datasetName,data); }
1336 inline void write(std::string datasetName,
signed char data) { writeAtomic(datasetName,data); }
1337 inline void write(std::string datasetName,
signed short data) { writeAtomic(datasetName,data); }
1338 inline void write(std::string datasetName,
signed int data) { writeAtomic(datasetName,data); }
1339 inline void write(std::string datasetName,
signed long data) { writeAtomic(datasetName,data); }
1340 inline void write(std::string datasetName,
signed long long data) { writeAtomic(datasetName,data); }
1341 inline void write(std::string datasetName,
unsigned char data) { writeAtomic(datasetName,data); }
1342 inline void write(std::string datasetName,
unsigned short data) { writeAtomic(datasetName,data); }
1343 inline void write(std::string datasetName,
unsigned int data) { writeAtomic(datasetName,data); }
1344 inline void write(std::string datasetName,
unsigned long data) { writeAtomic(datasetName,data); }
1345 inline void write(std::string datasetName,
unsigned long long data) { writeAtomic(datasetName,data); }
1346 inline void write(std::string datasetName,
float data) { writeAtomic(datasetName,data); }
1347 inline void write(std::string datasetName,
double data) { writeAtomic(datasetName,data); }
1348 inline void write(std::string datasetName,
long double data) { writeAtomic(datasetName,data); }
1349 inline void write(std::string datasetName,
const char* data) { writeAtomic(datasetName,data); }
1350 inline void write(std::string datasetName, std::string
const & data) { writeAtomic(datasetName,data.c_str()); }
1363 template<
unsigned int N,
class T,
class Str
ide>
1369 read_(datasetName, array, detail::getH5DataType<T>(), 1);
1381 template<
unsigned int N,
class T,
class Alloc>
1392 "HDF5File::readAndResize(): Array dimension disagrees with dataset dimension.");
1396 for(
int k=0; k < (int)dimshape.
size(); ++k)
1400 read_(datasetName, array, detail::getH5DataType<T>(), 1);
1413 read(datasetName, m_array);
1432 "HDF5File::readAndResize(): Array dimension disagrees with Dataset dimension must equal one for vigra::ArrayVector.");
1440 read_(datasetName, m_array, detail::getH5DataType<T>(), 1);
1458 template<
unsigned int N,
class T,
class Str
ide>
1467 readBlock_(datasetName, blockOffset, blockShape, array, detail::getH5DataType<T>(), 1);
1471 template<
unsigned int N,
class T,
int SIZE,
class Str
ide>
1477 read_(datasetName, array, detail::getH5DataType<T>(), SIZE);
1481 template<
unsigned int N,
class T,
int SIZE,
class Alloc>
1482 inline void readAndResize(std::string datasetName, MultiArray<N, TinyVector<T, SIZE>, Alloc> & array)
1492 SIZE == dimshape[0],
1493 "HDF5File::readAndResize(): Array dimension disagrees with dataset dimension.");
1496 typename MultiArrayShape<N>::type shape;
1497 for(
int k=1; k < (int)dimshape.size(); ++k)
1499 array.reshape(shape);
1501 read_(datasetName, array, detail::getH5DataType<T>(), SIZE);
1504 template<
unsigned int N,
class T,
int SIZE,
class Str
ide>
1505 inline void readBlock(std::string datasetName,
1506 typename MultiArrayShape<N>::type blockOffset,
1507 typename MultiArrayShape<N>::type blockShape,
1508 MultiArrayView<N, TinyVector<T, SIZE>, Stride> array)
1513 readBlock_(datasetName, blockOffset, blockShape, array, detail::getH5DataType<T>(), SIZE);
1517 template<
unsigned int N,
class T,
class Str
ide>
1518 inline void read(std::string datasetName, MultiArrayView<N, RGBValue<T>, Stride> array)
1523 read_(datasetName, array, detail::getH5DataType<T>(), 3);
1527 template<
unsigned int N,
class T,
class Alloc>
1528 inline void readAndResize(std::string datasetName, MultiArray<N, RGBValue<T>, Alloc> & array)
1539 "HDF5File::readAndResize(): Array dimension disagrees with dataset dimension.");
1542 typename MultiArrayShape<N>::type shape;
1543 for(
int k=1; k < (int)dimshape.size(); ++k)
1545 array.reshape(shape);
1547 read_(datasetName, array, detail::getH5DataType<T>(), 3);
1550 template<
unsigned int N,
class T,
class Str
ide>
1551 inline void readBlock(std::string datasetName,
1552 typename MultiArrayShape<N>::type blockOffset,
1553 typename MultiArrayShape<N>::type blockShape,
1554 MultiArrayView<N, RGBValue<T>, Stride> array)
1559 readBlock_(datasetName, blockOffset, blockShape, array, detail::getH5DataType<T>(), 3);
1565 inline void read(std::string datasetName,
char &data) { readAtomic(datasetName,data); }
1566 inline void read(std::string datasetName,
signed char &data) { readAtomic(datasetName,data); }
1567 inline void read(std::string datasetName,
signed short &data) { readAtomic(datasetName,data); }
1568 inline void read(std::string datasetName,
signed int &data) { readAtomic(datasetName,data); }
1569 inline void read(std::string datasetName,
signed long &data) { readAtomic(datasetName,data); }
1570 inline void read(std::string datasetName,
signed long long &data) { readAtomic(datasetName,data); }
1571 inline void read(std::string datasetName,
unsigned char &data) { readAtomic(datasetName,data); }
1572 inline void read(std::string datasetName,
unsigned short &data) { readAtomic(datasetName,data); }
1573 inline void read(std::string datasetName,
unsigned int &data) { readAtomic(datasetName,data); }
1574 inline void read(std::string datasetName,
unsigned long &data) { readAtomic(datasetName,data); }
1575 inline void read(std::string datasetName,
unsigned long long &data) { readAtomic(datasetName,data); }
1576 inline void read(std::string datasetName,
float &data) { readAtomic(datasetName,data); }
1577 inline void read(std::string datasetName,
double &data) { readAtomic(datasetName,data); }
1578 inline void read(std::string datasetName,
long double &data) { readAtomic(datasetName,data); }
1579 inline void read(std::string datasetName, std::string &data) { readAtomic(datasetName,data); }
1605 template<
unsigned int N,
class T>
1610 int compressionParameter = 0)
1616 for(
int i = 0; i < N; i++){
1617 chunkSize[i] = iChunkSize;
1619 createDataset<N,T>(datasetName, shape, init, chunkSize, compressionParameter);
1622 template<
unsigned int N,
class T>
1627 int compressionParameter = 0)
1632 std::string groupname = SplitString(datasetName).first();
1633 std::string setname = SplitString(datasetName).last();
1635 hid_t parent = openCreateGroup_(groupname);
1638 deleteDataset_(parent, setname);
1645 hsize_t shape_inv[N];
1646 for(
unsigned int k=0; k<N; ++k)
1647 shape_inv[N-1-k] = shape[k];
1650 dataspaceHandle =
HDF5Handle(H5Screate_simple(N, shape_inv, NULL),
1651 &H5Sclose,
"HDF5File::createDataset(): unable to create dataspace for scalar data.");
1654 HDF5Handle plist ( H5Pcreate(H5P_DATASET_CREATE), &H5Pclose,
"HDF5File::createDataset(): unable to create property list." );
1655 H5Pset_fill_value(plist,detail::getH5DataType<T>(), &init);
1658 H5Pset_obj_track_times(plist, track_time);
1662 if(chunks.size() > 0)
1665 H5Pset_chunk (plist, chunks.size(), chunks.begin());
1669 if(compressionParameter > 0)
1671 H5Pset_deflate(plist, compressionParameter);
1675 HDF5Handle datasetHandle ( H5Dcreate(parent, setname.c_str(), detail::getH5DataType<T>(), dataspaceHandle, H5P_DEFAULT, plist, H5P_DEFAULT),
1676 &H5Dclose,
"HDF5File::createDataset(): unable to create dataset.");
1677 if(parent != cGroupHandle_)
1685 H5Fflush(fileHandle_, H5F_SCOPE_GLOBAL);
1698 class SplitString:
public std::string {
1700 SplitString(std::string &sstring): std::string(sstring) {};
1703 std::string first(
char delimiter =
'/')
1705 size_t last = find_last_of(delimiter);
1706 if(last == std::string::npos)
1709 return std::string(begin(), begin()+last+1);
1713 std::string last(
char delimiter =
'/')
1715 size_t last = find_last_of(delimiter);
1716 if(last == std::string::npos)
1717 return std::string(*
this);
1718 return std::string(begin()+last+1, end());
1722 template <
class Shape>
1723 ArrayVector<hsize_t>
1724 defineChunks(Shape
const & chunks, Shape
const & shape,
int numBands,
int compression = 0)
1728 ArrayVector<hsize_t> res(chunks.begin(), chunks.end());
1730 res.insert(res.begin(), numBands);
1733 else if(compression > 0)
1738 ArrayVector<hsize_t> res(shape.begin(), shape.end());
1739 hsize_t chunk_length = (hsize_t)std::pow(300000.0, 1.0 / shape.size());
1740 for(
unsigned int k=0; k < shape.size(); ++k)
1741 if(res[k] > chunk_length)
1742 res[k] = chunk_length;
1744 res.insert(res.begin(), numBands);
1749 return ArrayVector<hsize_t>();
1763 if(path.length() == 0 || path ==
"."){
1764 return currentGroupName_();
1769 if(relativePath_(path)){
1770 std::string cname = currentGroupName_();
1772 str = currentGroupName_()+path;
1774 str = currentGroupName_()+
"/"+path;
1780 std::string::size_type startpos = 0;
1781 while(str.find(std::string(
"./"), startpos) != std::string::npos){
1782 std::string::size_type pos = str.find(std::string(
"./"), startpos);
1785 if(str.substr(pos-1,3) !=
"../"){
1787 str = str.substr(0,pos) + str.substr(pos+2,str.length()-pos-2);
1793 while(str.find(std::string(
"..")) != std::string::npos){
1794 std::string::size_type pos = str.find(std::string(
".."));
1797 std::string::size_type end = str.find(
"/",pos);
1798 if(end != std::string::npos){
1808 std::string::size_type prev_slash = str.rfind(
"/",pos);
1810 vigra_invariant(prev_slash != 0 && prev_slash != std::string::npos,
1811 "Error parsing path: "+str);
1813 std::string::size_type begin = str.rfind(
"/",prev_slash-1);
1816 str = str.substr(0,begin+1) + str.substr(end,str.length()-end);
1826 inline bool relativePath_(std::string & path)
const
1828 std::string::size_type pos = path.find(
'/') ;
1837 inline std::string currentGroupName_()
const
1839 int len = H5Iget_name(cGroupHandle_,NULL,1000);
1840 ArrayVector<char> name (len+1,0);
1841 H5Iget_name(cGroupHandle_,name.begin(),len+1);
1843 return std::string(name.begin());
1848 inline std::string fileName_()
const
1850 int len = H5Fget_name(fileHandle_,NULL,1000);
1851 ArrayVector<char> name (len+1,0);
1852 H5Fget_name(fileHandle_,name.begin(),len+1);
1854 return std::string(name.begin());
1859 inline hid_t createFile_(std::string filePath,
OpenMode mode = Open)
1863 pFile = fopen ( filePath.c_str(),
"r" );
1867 if ( pFile == NULL )
1869 fileId = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
1871 else if(mode == Open)
1874 fileId = H5Fopen(filePath.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
1876 else if(mode == OpenReadOnly) {
1878 fileId = H5Fopen(filePath.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
1883 std::remove(filePath.c_str());
1884 fileId = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
1891 inline hid_t openCreateGroup_(std::string groupName)
1897 hid_t parent = H5Gopen(fileHandle_,
"/", H5P_DEFAULT);
1898 if(groupName ==
"/")
1904 groupName = std::string(groupName.begin()+1, groupName.end());
1907 if( groupName.size() != 0 && *groupName.rbegin() !=
'/')
1909 groupName = groupName +
'/';
1913 std::string::size_type begin = 0, end = groupName.find(
'/');
1914 while (end != std::string::npos)
1916 std::string group(groupName.begin()+begin, groupName.begin()+end);
1917 hid_t prevParent = parent;
1919 if(H5LTfind_dataset(parent, group.c_str()) == 0)
1921 parent = H5Gcreate(prevParent, group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1923 parent = H5Gopen(prevParent, group.c_str(), H5P_DEFAULT);
1925 H5Gclose(prevParent);
1932 end = groupName.find(
'/', begin);
1941 inline void deleteDataset_(hid_t parent, std::string datasetName)
1944 if(H5LTfind_dataset(parent, datasetName.c_str()))
1947 #if (H5_VERS_MAJOR == 1 && H5_VERS_MINOR <= 6)
1948 if(H5Gunlink(parent, datasetName.c_str()) < 0)
1950 vigra_postcondition(
false,
"HDF5File::deleteDataset_(): Unable to delete existing data.");
1953 if(H5Ldelete(parent, datasetName.c_str(), H5P_DEFAULT ) < 0)
1955 vigra_postcondition(
false,
"HDF5File::deleteDataset_(): Unable to delete existing data.");
1963 inline hid_t getDatasetHandle_(std::string datasetName)
1968 std::string groupname = SplitString(datasetName).first();
1969 std::string setname = SplitString(datasetName).last();
1971 if(H5Lexists(fileHandle_, datasetName.c_str(), H5P_DEFAULT) <= 0)
1973 std::cerr <<
"HDF5File::getDatasetHandle_(): Dataset '" << datasetName <<
"' does not exist.\n";
1978 HDF5Handle groupHandle(openCreateGroup_(groupname), &H5Gclose,
"HDF5File::getDatasetHandle_(): Internal error");
1980 return H5Dopen(groupHandle, setname.c_str(), H5P_DEFAULT);
1985 H5O_type_t get_object_type_(std::string name)
1988 std::string group_name = SplitString(name).first();
1989 std::string object_name = SplitString(name).last();
1990 if (!object_name.size())
1991 return H5O_TYPE_GROUP;
1993 htri_t exists = H5Lexists(fileHandle_, name.c_str(), H5P_DEFAULT);
1994 vigra_precondition(exists > 0,
"HDF5File::get_object_type_(): "
1995 "object \"" + name +
"\" "
1998 HDF5Handle group_handle(openCreateGroup_(group_name), &H5Gclose,
"Internal error");
1999 return HDF5_get_type(group_handle, name.c_str());
2004 template<
unsigned int N,
class T,
class Str
ide>
2005 void write_attribute_(std::string name,
2006 const std::string & attribute_name,
2007 const MultiArrayView<N, T, Stride> & array,
2008 const hid_t datatype,
2009 const int numBandsOfType);
2017 inline void writeAtomicAttribute(std::string datasetName, std::string attributeName,
const T data)
2022 typename MultiArrayShape<1>::type chunkSize;
2024 MultiArray<1,T> array(MultiArrayShape<1>::type(1));
2026 write_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), 1);
2031 template<
unsigned int N,
class T,
class Str
ide>
2032 void read_attribute_(std::string datasetName,
2033 std::string attributeName,
2034 MultiArrayView<N, T, Stride> array,
2035 const hid_t datatype,
const int numBandsOfType);
2043 inline void readAtomicAttribute(std::string datasetName, std::string attributeName, T & data)
2048 MultiArray<1,T> array(MultiArrayShape<1>::type(1));
2049 read_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), 1);
2053 inline void readAtomicAttribute(std::string datasetName, std::string attributeName, std::string & data)
2058 MultiArray<1,const char *> array(MultiArrayShape<1>::type(1));
2059 read_attribute_(datasetName, attributeName, array, detail::getH5DataType<const char *>(), 1);
2060 data = std::string(array[0]);
2065 template<
unsigned int N,
class T,
class Str
ide>
2066 void write_(std::string &datasetName,
2067 const MultiArrayView<N, T, Stride> & array,
2068 const hid_t datatype,
2069 const int numBandsOfType,
2070 typename MultiArrayShape<N>::type &chunkSize,
2071 int compressionParameter = 0);
2082 inline void writeAtomic(std::string datasetName,
const T data)
2087 typename MultiArrayShape<1>::type chunkSize;
2089 MultiArray<1,T> array(MultiArrayShape<1>::type(1));
2091 write_(datasetName, array, detail::getH5DataType<T>(), 1, chunkSize,0);
2096 template<
unsigned int N,
class T,
class Str
ide>
2097 void read_(std::string datasetName,
2098 MultiArrayView<N, T, Stride> array,
2099 const hid_t datatype,
const int numBandsOfType);
2110 inline void readAtomic(std::string datasetName, T & data)
2115 MultiArray<1,T> array(MultiArrayShape<1>::type(1));
2116 read_(datasetName, array, detail::getH5DataType<T>(), 1);
2120 inline void readAtomic(std::string datasetName, std::string & data)
2125 MultiArray<1,const char *> array(MultiArrayShape<1>::type(1));
2126 read_(datasetName, array, detail::getH5DataType<const char *>(), 1);
2127 data = std::string(array[0]);
2132 template<
unsigned int N,
class T,
class Str
ide>
2133 void writeBlock_(std::string datasetName,
2134 typename MultiArrayShape<N>::type &blockOffset,
2135 const MultiArrayView<N, T, Stride> & array,
2136 const hid_t datatype,
2137 const int numBandsOfType);
2143 template<
unsigned int N,
class T,
class Str
ide>
2144 void readBlock_(std::string datasetName,
2145 typename MultiArrayShape<N>::type &blockOffset,
2146 typename MultiArrayShape<N>::type &blockShape,
2147 MultiArrayView<N, T, Stride> &array,
2148 const hid_t datatype,
const int numBandsOfType);
2153 template<
unsigned int N,
class T,
class Str
ide>
2154 void HDF5File::write_(std::string &datasetName,
2155 const MultiArrayView<N, T, Stride> & array,
2156 const hid_t datatype,
2157 const int numBandsOfType,
2158 typename MultiArrayShape<N>::type &chunkSize,
2159 int compressionParameter)
2161 std::string groupname = SplitString(datasetName).first();
2162 std::string setname = SplitString(datasetName).last();
2165 ArrayVector<hsize_t> shape(array.shape().begin(), array.shape().end());
2168 if(numBandsOfType > 1)
2169 shape.push_back(numBandsOfType);
2171 HDF5Handle dataspace(H5Screate_simple(shape.size(), shape.begin(), NULL), &H5Sclose,
2172 "HDF5File::write(): Can not create dataspace.");
2175 std::string errorMessage (
"HDF5File::write(): can not create group '" + groupname +
"'.");
2176 HDF5Handle groupHandle(openCreateGroup_(groupname), &H5Gclose, errorMessage.c_str());
2179 deleteDataset_(groupHandle, setname.c_str());
2182 HDF5Handle plist(H5Pcreate(H5P_DATASET_CREATE), &H5Pclose,
2183 "HDF5File::write(): unable to create property list." );
2186 H5Pset_obj_track_times(plist, track_time);
2189 ArrayVector<hsize_t> chunks(defineChunks(chunkSize, array.shape(), numBandsOfType, compressionParameter));
2190 if(chunks.size() > 0)
2193 H5Pset_chunk (plist, chunks.size(), chunks.begin());
2197 if(compressionParameter > 0)
2199 H5Pset_deflate(plist, compressionParameter);
2203 HDF5Handle datasetHandle(H5Dcreate(groupHandle, setname.c_str(), datatype, dataspace,H5P_DEFAULT, plist, H5P_DEFAULT),
2204 &H5Dclose,
"HDF5File::write(): Can not create dataset.");
2207 if(array.isUnstrided())
2210 status = H5Dwrite(datasetHandle, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, array.data());
2220 int offset = numBandsOfType > 1 ? 1 : 0;
2222 if(chunks.size() > 0)
2230 ArrayVector<hsize_t>(shape.size(), 1).swap(chunks);
2231 chunks[0] = numBandsOfType;
2233 for(
unsigned int k=0; k<N; ++k)
2235 chunks[k+offset] = array.shape(k);
2236 prod *= array.shape(k);
2242 ArrayVector<hsize_t> null(shape.size(), 0),
2243 start(shape.size(), 0),
2244 count(shape.size(), 1);
2246 count[N-1-offset] = numBandsOfType;
2248 typedef typename MultiArrayShape<N>::type Shape;
2249 Shape chunkCount, chunkMaxShape;
2250 for(
unsigned int k=offset; k<chunks.size(); ++k)
2252 chunkMaxShape[k-offset] = chunks[k];
2257 chunkEnd = chunkIter.getEndIterator();
2258 for(; chunkIter != chunkEnd; ++chunkIter)
2260 Shape chunkStart(chunkIter.point() * chunkMaxShape),
2261 chunkStop(min(chunkStart + chunkMaxShape, array.shape()));
2262 MultiArray<N, T> buffer(array.subarray(chunkStart, chunkStop));
2264 for(
unsigned int k=0; k<N; ++k)
2266 start[N-1-k] = chunkStart[k];
2267 count[N-1-k] = buffer.shape(k);
2272 count[N] = numBandsOfType;
2274 HDF5Handle filespace(H5Dget_space(datasetHandle),
2275 &H5Sclose,
"HDF5File::write(): unable to create hyperslabs.");
2276 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start.data(), NULL, count.data(), NULL);
2280 HDF5Handle dataspace(H5Screate_simple(count.size(), count.data(), NULL),
2281 &H5Sclose,
"HDF5File::write(): unable to create hyperslabs.");
2282 status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, null.data(), NULL, count.data(), NULL);
2286 status = H5Dwrite(datasetHandle, datatype, dataspace, filespace, H5P_DEFAULT, buffer.data());
2291 vigra_postcondition(status >= 0,
2292 "HDF5File::write(): write to dataset '" + datasetName +
"' via H5Dwrite() failed.");
2297 template<
unsigned int N,
class T,
class Str
ide>
2298 void HDF5File::writeBlock_(std::string datasetName,
2299 typename MultiArrayShape<N>::type &blockOffset,
2300 const MultiArrayView<N, T, Stride> & array,
2301 const hid_t datatype,
2302 const int numBandsOfType)
2305 std::string errorMessage =
"HDF5File::writeBlock(): Error opening dataset '" + datasetName +
"'.";
2306 HDF5Handle datasetHandle (getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
2309 hsize_t boffset [N];
2313 for(
int i = 0; i < N; i++){
2314 boffset[i] = blockOffset[N-1-i];
2315 bshape[i] = array.size(N-1-i);
2320 HDF5Handle memspace_handle (H5Screate_simple(N,bshape,NULL),&H5Sclose,
"Unable to get origin dataspace");
2323 HDF5Handle dataspaceHandle (H5Dget_space(datasetHandle),&H5Sclose,
"Unable to create target dataspace");
2324 H5Sselect_hyperslab(dataspaceHandle, H5S_SELECT_SET, boffset, bones, bones, bshape);
2327 if(array.isUnstrided())
2330 status = H5Dwrite( datasetHandle, datatype, memspace_handle, dataspaceHandle, H5P_DEFAULT, array.data());
2335 MultiArray<N, T> buffer(array);
2336 status = H5Dwrite( datasetHandle, datatype, memspace_handle, dataspaceHandle, H5P_DEFAULT, buffer.data());
2338 vigra_postcondition(status >= 0,
2339 "HDF5File::writeBlock(): write to dataset '" + datasetName +
"' via H5Dwrite() failed.");
2344 template<
unsigned int N,
class T,
class Str
ide>
2345 void HDF5File::write_attribute_(std::string name,
2346 const std::string & attribute_name,
2347 const MultiArrayView<N, T, Stride> & array,
2348 const hid_t datatype,
2349 const int numBandsOfType)
2352 ArrayVector<hsize_t> shape(array.shape().begin(), array.shape().end());
2354 if(numBandsOfType > 1)
2355 shape.push_back(numBandsOfType);
2357 HDF5Handle dataspace(H5Screate_simple(shape.size(),
2358 shape.begin(), NULL),
2359 &H5Sclose,
"HDF5File::writeAttribute(): Can not"
2360 " create dataspace.");
2362 std::string errorMessage (
"HDF5File::writeAttribute(): can not find "
2363 "object '" + name +
"'.");
2365 H5O_type_t h5_type = get_object_type_(name);
2366 bool is_group = h5_type == H5O_TYPE_GROUP;
2367 if (!is_group && h5_type != H5O_TYPE_DATASET)
2368 vigra_precondition(0,
"HDF5File::writeAttribute(): object \""
2369 + name +
"\" is neither a group nor a "
2372 HDF5Handle object_handle(is_group
2373 ? openCreateGroup_(name)
2374 : getDatasetHandle_(name),
2378 errorMessage.c_str());
2381 HDF5Handle attributeHandle(exists
2382 ? H5Aopen(object_handle,
2383 attribute_name.c_str(),
2385 : H5Acreate(object_handle,
2386 attribute_name.c_str(), datatype,
2387 dataspace, H5P_DEFAULT,
2390 "HDF5File::writeAttribute(): Can not create"
2393 if(array.isUnstrided())
2396 status = H5Awrite(attributeHandle, datatype, array.data());
2402 MultiArray<N, T> buffer(array);
2403 status = H5Awrite(attributeHandle, datatype, buffer.data());
2405 vigra_postcondition(status >= 0,
2406 "HDF5File::writeAttribute(): write to attribute '" + attribute_name +
"' via H5Awrite() failed.");
2411 template<
unsigned int N,
class T,
class Str
ide>
2412 void HDF5File::read_(std::string datasetName,
2413 MultiArrayView<N, T, Stride> array,
2414 const hid_t datatype,
const int numBandsOfType)
2419 std::string errorMessage (
"HDF5File::read(): Unable to open dataset '" + datasetName +
"'.");
2420 HDF5Handle datasetHandle(getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
2424 int offset = (numBandsOfType > 1)
2429 "HDF5File::read(): Array dimension disagrees with dataset dimension.");
2431 typename MultiArrayShape<N>::type shape;
2432 for(
int k=offset; k < (int)dimshape.size(); ++k)
2435 vigra_precondition(shape == array.shape(),
2436 "HDF5File::read(): Array shape disagrees with dataset shape.");
2438 vigra_precondition(dimshape[0] == static_cast<hsize_t>(numBandsOfType),
2439 "HDF5File::read(): Band count doesn't match destination array compound type.");
2442 if(array.isUnstrided())
2445 status = H5Dread(datasetHandle, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, array.data() );
2451 ArrayVector<hsize_t> null(dimshape.size(), 0),
2452 chunks(dimshape.size(), 1),
2453 start(dimshape.size(), 0),
2454 count(dimshape.size(), 1);
2456 HDF5Handle properties(H5Dget_create_plist(datasetHandle),
2457 &H5Pclose,
"HDF5File::read(): failed to get property list");
2458 if(H5D_CHUNKED == H5Pget_layout(properties))
2461 H5Pget_chunk(properties, chunks.size(), chunks.data());
2467 chunks[0] = numBandsOfType;
2469 for(
unsigned int k=0; k<N; ++k)
2471 chunks[k+offset] = array.shape(k);
2472 prod *= array.shape(k);
2478 count[N-1-offset] = numBandsOfType;
2480 typedef typename MultiArrayShape<N>::type Shape;
2481 Shape chunkCount, chunkMaxShape;
2482 for(
unsigned int k=offset; k<chunks.size(); ++k)
2484 chunkMaxShape[k-offset] = chunks[k];
2489 chunkEnd = chunkIter.getEndIterator();
2490 for(; chunkIter != chunkEnd; ++chunkIter)
2492 Shape chunkStart(chunkIter.point() * chunkMaxShape),
2493 chunkStop(min(chunkStart + chunkMaxShape, array.shape()));
2494 MultiArray<N, T> buffer(chunkStop - chunkStart);
2496 for(
unsigned int k=0; k<N; ++k)
2498 start[N-1-k] = chunkStart[k];
2499 count[N-1-k] = buffer.shape(k);
2504 count[N] = numBandsOfType;
2506 HDF5Handle filespace(H5Dget_space(datasetHandle),
2507 &H5Sclose,
"HDF5File::read(): unable to create hyperslabs.");
2508 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start.data(), NULL, count.data(), NULL);
2512 HDF5Handle dataspace(H5Screate_simple(count.size(), count.data(), NULL),
2513 &H5Sclose,
"HDF5File::read(): unable to create hyperslabs.");
2514 status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, null.data(), NULL, count.data(), NULL);
2518 status = H5Dread(datasetHandle, datatype, dataspace, filespace, H5P_DEFAULT, buffer.data());
2522 array.subarray(chunkStart, chunkStop) = buffer;
2525 vigra_postcondition(status >= 0,
2526 "HDF5File::read(): read from dataset '" + datasetName +
"' via H5Dread() failed.");
2531 template<
unsigned int N,
class T,
class Str
ide>
2532 void HDF5File::readBlock_(std::string datasetName,
2533 typename MultiArrayShape<N>::type &blockOffset,
2534 typename MultiArrayShape<N>::type &blockShape,
2535 MultiArrayView<N, T, Stride> &array,
2536 const hid_t datatype,
const int numBandsOfType)
2542 std::string errorMessage (
"HDF5File::readBlock(): Unable to open dataset '" + datasetName +
"'.");
2543 HDF5Handle datasetHandle (getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
2545 int offset = (numBandsOfType > 1)
2550 "HDF5File::readBlock(): Array dimension disagrees with data dimension.");
2552 vigra_precondition(blockShape == array.shape(),
2553 "HDF5File::readBlock(): Array shape disagrees with block size.");
2556 hsize_t boffset [N];
2560 for(
int i = 0; i < N; i++){
2562 boffset[i] = blockOffset[N-1-i];
2564 bshape[i] = blockShape[N-1-i];
2570 HDF5Handle memspace_handle(H5Screate_simple(N,bshape,NULL),&H5Sclose,
2571 "Unable to create target dataspace");
2574 HDF5Handle dataspaceHandle(H5Dget_space(datasetHandle),&H5Sclose,
2575 "Unable to get dataspace");
2576 H5Sselect_hyperslab(dataspaceHandle, H5S_SELECT_SET, boffset, bones, bones, bshape);
2579 if(array.isUnstrided())
2582 status = H5Dread( datasetHandle, datatype, memspace_handle, dataspaceHandle, H5P_DEFAULT, array.data());
2587 MultiArray<N, T> buffer(array.shape());
2588 status = H5Dread( datasetHandle, datatype, memspace_handle, dataspaceHandle, H5P_DEFAULT, buffer.data());
2593 vigra_postcondition(status >= 0,
2594 "HDF5File::readBlock(): read from dataset '" + datasetName +
"' via H5Dread() failed.");
2599 template<
unsigned int N,
class T,
class Str
ide>
2600 void HDF5File::read_attribute_(std::string datasetName,
2601 std::string attributeName,
2602 MultiArrayView<N, T, Stride> array,
2603 const hid_t datatype,
const int numBandsOfType)
2607 std::string message =
"HDF5File::readAttribute(): could not get handle for attribute '"+attributeName+
"'' of object '"+dataset_path+
"'.";
2608 HDF5Handle attr_handle (H5Aopen_by_name(fileHandle_,dataset_path.c_str(),attributeName.c_str(),H5P_DEFAULT,H5P_DEFAULT),&H5Aclose, message.c_str());
2611 message =
"HDF5File::readAttribute(): could not get dataspace for attribute '"+attributeName+
"'' of object '"+dataset_path+
"'.";
2612 HDF5Handle attr_dataspace_handle (H5Aget_space(attr_handle),&H5Sclose,message.c_str());
2615 int raw_dims = H5Sget_simple_extent_ndims(attr_dataspace_handle);
2616 int dims = std::max(raw_dims, 1);
2617 ArrayVector<hsize_t> dimshape(dims);
2619 H5Sget_simple_extent_dims(attr_dataspace_handle, dimshape.data(), NULL);
2626 int offset = (numBandsOfType > 1)
2629 message =
"HDF5File::readAttribute(): Array dimension disagrees with dataset dimension.";
2633 for(
int k=offset; k < (int)dimshape.size(); ++k)
2634 vigra_precondition(array.shape()[k-offset] == (
MultiArrayIndex)dimshape[k],
2635 "HDF5File::readAttribute(): Array shape disagrees with dataset shape");
2638 if(array.isUnstrided())
2641 status = H5Aread( attr_handle, datatype, array.data());
2647 MultiArray<N, T> buffer(array.shape());
2648 status = H5Aread( attr_handle, datatype, buffer.data() );
2653 vigra_postcondition(status >= 0,
2654 "HDF5File::readAttribute(): read from attribute '" + attributeName +
"' via H5Aread() failed.");
2694 doxygen_overloaded_function(template <...>
void readHDF5)
2696 template<
unsigned int N,
class T,
class Str
ideTag>
2697 inline void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, T, StrideTag> array)
2702 template<
unsigned int N,
class T,
class Str
ideTag>
2703 void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, T, StrideTag> array,
const hid_t datatype,
const int numBandsOfType)
2705 HDF5File file(info.getFilePath(), HDF5File::OpenReadOnly);
2706 file.read(info.getPathInFile(), array);
2710 inline hid_t openGroup(hid_t parent, std::string group_name)
2713 size_t last_slash = group_name.find_last_of(
'/');
2714 if (last_slash == std::string::npos || last_slash != group_name.size() - 1)
2715 group_name = group_name +
'/';
2716 std::string::size_type begin = 0, end = group_name.find(
'/');
2718 while (end != std::string::npos)
2720 std::string group(group_name.begin()+begin, group_name.begin()+end);
2721 hid_t prev_parent = parent;
2722 parent = H5Gopen(prev_parent, group.c_str(), H5P_DEFAULT);
2724 if(ii != 0) H5Gclose(prev_parent);
2725 if(parent < 0)
return parent;
2728 end = group_name.find(
'/', begin);
2733 inline hid_t createGroup(hid_t parent, std::string group_name)
2735 if(group_name.size() == 0 ||*group_name.rbegin() !=
'/')
2736 group_name = group_name +
'/';
2737 if(group_name ==
"/")
2738 return H5Gopen(parent, group_name.c_str(), H5P_DEFAULT);
2740 std::string::size_type begin = 0, end = group_name.find(
'/');
2742 while (end != std::string::npos)
2744 std::string group(group_name.begin()+begin, group_name.begin()+end);
2745 hid_t prev_parent = parent;
2747 if(H5LTfind_dataset(parent, group.c_str()) == 0)
2749 parent = H5Gcreate(prev_parent, group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
2751 parent = H5Gopen(prev_parent, group.c_str(), H5P_DEFAULT);
2754 if(ii != 0) H5Gclose(prev_parent);
2755 if(parent < 0)
return parent;
2758 end = group_name.find(
'/', begin);
2763 inline void deleteDataset(hid_t parent, std::string dataset_name)
2766 if(H5LTfind_dataset(parent, dataset_name.c_str()))
2769 #if (H5_VERS_MAJOR == 1 && H5_VERS_MINOR <= 6)
2770 if(H5Gunlink(parent, dataset_name.c_str()) < 0)
2772 vigra_postcondition(
false,
"writeToHDF5File(): Unable to delete existing data.");
2775 if(H5Ldelete(parent, dataset_name.c_str(), H5P_DEFAULT ) < 0)
2777 vigra_postcondition(
false,
"createDataset(): Unable to delete existing data.");
2783 inline hid_t createFile(std::string filePath,
bool append_ =
true)
2786 pFile = fopen ( filePath.c_str(),
"r" );
2788 if ( pFile == NULL )
2790 file_id = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
2795 file_id = H5Fopen(filePath.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
2800 std::remove(filePath.c_str());
2801 file_id = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
2806 template<
unsigned int N,
class T,
class Tag>
2807 void createDataset(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, T, Tag> & array,
const hid_t datatype,
const int numBandsOfType, HDF5Handle & file_handle, HDF5Handle & dataset_handle)
2809 std::string path_name(pathInFile), group_name, data_set_name, message;
2810 std::string::size_type delimiter = path_name.rfind(
'/');
2813 file_handle = HDF5Handle(createFile(filePath), &H5Fclose,
2814 "createDataset(): unable to open output file.");
2817 if(delimiter == std::string::npos)
2820 data_set_name = path_name;
2824 group_name = std::string(path_name.begin(), path_name.begin()+delimiter);
2825 data_set_name = std::string(path_name.begin()+delimiter+1, path_name.end());
2829 HDF5Handle group(createGroup(file_handle, group_name), &H5Gclose,
2830 "createDataset(): Unable to create and open group. generic v");
2833 deleteDataset(group, data_set_name);
2837 HDF5Handle dataspace_handle;
2838 if(numBandsOfType > 1) {
2840 hsize_t shape_inv[N+1];
2841 for(
unsigned int k=0; k<N; ++k) {
2842 shape_inv[N-1-k] = array.shape(k);
2845 shape_inv[N] = numBandsOfType;
2848 dataspace_handle = HDF5Handle(H5Screate_simple(N+1, shape_inv, NULL),
2849 &H5Sclose,
"createDataset(): unable to create dataspace for non-scalar data.");
2852 hsize_t shape_inv[N];
2853 for(
unsigned int k=0; k<N; ++k)
2854 shape_inv[N-1-k] = array.shape(k);
2857 dataspace_handle = HDF5Handle(H5Screate_simple(N, shape_inv, NULL),
2858 &H5Sclose,
"createDataset(): unable to create dataspace for scalar data.");
2862 dataset_handle = HDF5Handle(H5Dcreate(group,
2863 data_set_name.c_str(),
2866 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT),
2867 &H5Dclose,
"createDataset(): unable to create dataset.");
2908 doxygen_overloaded_function(template <...>
void writeHDF5)
2910 template<
unsigned int N,
class T,
class Str
ideTag>
2911 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, T, StrideTag> & array)
2914 writeHDF5(filePath, pathInFile, array, 0, 0);
2917 template<
unsigned int N,
class T,
class Str
ideTag>
2918 void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, T, StrideTag> & array,
const hid_t datatype,
const int numBandsOfType)
2920 HDF5File file(filePath, HDF5File::Open);
2921 file.write(pathInFile, array);
2936 void operator()(std::string
const & in)
2938 size = in.size() > size ?
2946 #if (H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 8) || DOXYGEN
2953 template<
size_t N,
class T,
class C>
2958 if(H5Aexists(loc, name) > 0)
2959 H5Adelete(loc, name);
2962 array.
shape().end());
2964 dataspace_handle(H5Screate_simple(N, shape.data(), NULL),
2966 "writeToHDF5File(): unable to create dataspace.");
2970 detail::getH5DataType<T>(),
2972 H5P_DEFAULT ,H5P_DEFAULT ),
2974 "writeHDF5Attr: unable to create Attribute");
2978 for(
int ii = 0; ii < array.
size(); ++ii)
2979 buffer.push_back(array[ii]);
2980 H5Awrite(attr, detail::getH5DataType<T>(), buffer.
data());
2989 template<
size_t N,
class C>
2994 if(H5Aexists(loc, name) > 0)
2995 H5Adelete(loc, name);
2998 array.
shape().end());
3000 dataspace_handle(H5Screate_simple(N, shape.data(), NULL),
3002 "writeToHDF5File(): unable to create dataspace.");
3006 "writeToHDF5File(): unable to create type.");
3008 detail::MaxSizeFnc max_size;
3009 max_size = std::for_each(array.
data(),array.
data()+ array.
size(), max_size);
3010 H5Tset_size (atype, max_size.size);
3016 H5P_DEFAULT ,H5P_DEFAULT ),
3018 "writeHDF5Attr: unable to create Attribute");
3020 std::string buf =
"";
3021 for(
int ii = 0; ii < array.
size(); ++ii)
3023 buf = buf + array[ii]
3024 + std::string(max_size.size - array[ii].
size(),
' ');
3026 H5Awrite(attr, atype, buf.c_str());
3054 std::string pathInFile,
3057 std::string path_name(pathInFile), group_name, data_set_name, message, attr_name;
3058 std::string::size_type delimiter = path_name.rfind(
'/');
3061 HDF5Handle file_id(createFile(filePath), &H5Fclose,
3062 "writeToHDF5File(): unable to open output file.");
3065 if(delimiter == std::string::npos)
3068 data_set_name = path_name;
3073 group_name = std::string(path_name.begin(), path_name.begin()+delimiter);
3074 data_set_name = std::string(path_name.begin()+delimiter+1, path_name.end());
3076 delimiter = data_set_name.rfind(
'.');
3077 if(delimiter == std::string::npos)
3079 attr_name = path_name;
3080 data_set_name =
"/";
3084 attr_name = std::string(data_set_name.begin()+delimiter+1, data_set_name.end());
3085 data_set_name = std::string(data_set_name.begin(), data_set_name.begin()+delimiter);
3088 HDF5Handle group(openGroup(file_id, group_name), &H5Gclose,
3089 "writeToHDF5File(): Unable to create and open group. attr ver");
3091 if(data_set_name !=
"/")
3093 HDF5Handle dset(H5Dopen(group, data_set_name.c_str(), H5P_DEFAULT), &H5Dclose,
3094 "writeHDF5Attr():unable to open dataset");
3109 #endif // VIGRA_HDF5IMPEX_HXX
void read(const std::string &datasetName, ArrayVectorView< T > array)
Read data into an array vector. If the first character of datasetName is a "/", the path will be inte...
Definition: hdf5impex.hxx:1408
HDF5Handle()
Default constructor. Creates a NULL handle.
Definition: hdf5impex.hxx:148
void write(const std::string &datasetName, const ArrayVectorView< T > &array, int compression=0)
Write array vectors.
Definition: hdf5impex.hxx:1273
bool cd_up(int levels)
Change the current group to its parent group. Returns true if successful, false otherwise. If unsuccessful, the group will not change.
Definition: hdf5impex.hxx:725
void createDataset(std::string datasetName, typename MultiArrayShape< N >::type shape, T init=T(), int iChunkSize=0, int compressionParameter=0)
Create a new dataset. This function can be used to create a dataset filled with a default value...
Definition: hdf5impex.hxx:1606
bool operator==(HDF5Handle const &h) const
Equality comparison of the contained handle.
Definition: hdf5impex.hxx:248
HDF5File(std::string filename, OpenMode mode, int track_creation_times=0)
Open or create an HDF5File object.
Definition: hdf5impex.hxx:639
Wrapper for hid_t objects.
Definition: hdf5impex.hxx:134
MultiArrayIndex numDimensions() const
const difference_type & shape() const
Definition: multi_array.hxx:1551
void readAttribute(std::string object_name, std::string attribute_name, MultiArrayView< N, T, Stride > array)
Read MultiArray Attributes. In contrast to datasets, subarray access is not available.
Definition: hdf5impex.hxx:1078
void cd_mk(std::string groupName)
Change the current group; create it if necessary. If the first character is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group.
Definition: hdf5impex.hxx:760
Definition: array_vector.hxx:76
hssize_t getDatasetDimensions(std::string datasetName)
Get the number of dimensions of a certain dataset If the first character is a "/", the path will be interpreted as absolute path, otherwise it will be interpreted as path relative to the current group.
Definition: hdf5impex.hxx:837
const_iterator begin() const
Definition: array_vector.hxx:223
pointer data() const
Definition: multi_array.hxx:1792
HDF5ImportInfo(const char *filePath, const char *pathInFile)
HDF5Handle(hid_t h, Destructor destructor, const char *error_message)
Create a wrapper for a hid_t object.
Definition: hdf5impex.hxx:172
std::string get_absolute_path(std::string path) const
takes any path and converts it into an absolute path in the current file.
Definition: hdf5impex.hxx:1761
Main MultiArray class containing the memory management.
Definition: multi_array.hxx:2357
std::string getDatasetType(std::string const &datasetName)
Definition: hdf5impex.hxx:907
void reshape(const difference_type &shape)
Definition: multi_array.hxx:2738
void mkdir(std::string groupName)
Create a new group. If the first character is a "/", the path will be interpreted as absolute path...
Definition: hdf5impex.hxx:746
bool existsAttribute(std::string object_name, std::string attribute_name)
Test if attribute exists.
Definition: hdf5impex.hxx:1061
const std::string & getFilePath() const
std::ptrdiff_t MultiArrayIndex
Definition: multi_shape.hxx:55
void writeHDF5Attr(hid_t loc, const char *name, MultiArrayView< N, T, C > const &array)
Definition: hdf5impex.hxx:2954
bool operator==(hid_t h) const
Equality comparison of the contained handle.
Definition: hdf5impex.hxx:255
const std::string & getPathInFile() const
void ls(Container &cont) const
List the contents of the current group into a container-like object via insert(). ...
Definition: hdf5impex.hxx:804
void write(std::string datasetName, const MultiArrayView< N, T, Stride > &array, typename MultiArrayShape< N >::type chunkSize, int compression=0)
Write multi arrays. Chunks can be activated by providing a MultiArrayShape as chunkSize. chunkSize must have equal dimension as array.
Definition: hdf5impex.hxx:1203
Argument object for the function readHDF5().
Definition: hdf5impex.hxx:290
bool isHDF5(char const *filename)
Check if given filename refers to a HDF5 file.
Definition: hdf5impex.hxx:100
bool operator!=(hid_t h) const
Inequality comparison of the contained handle.
Definition: hdf5impex.hxx:269
bool operator!=(HDF5Handle const &h) const
Inequality comparison of the contained handle.
Definition: hdf5impex.hxx:262
difference_type_1 size() const
Definition: multi_array.hxx:1544
HDF5Handle getDatasetHandle(std::string const &datasetName)
Obtain the HDF5 handle of a dataset.
Definition: hdf5impex.hxx:953
std::string filename() const
Get the name of the associated file.
Definition: hdf5impex.hxx:819
HDF5Handle & operator=(HDF5Handle const &h)
Assignment. Calls close() for the LHS handle and hands over ownership of the RHS handle (analogous to...
Definition: hdf5impex.hxx:194
~HDF5File()
The destructor flushes and closes the file.
Definition: hdf5impex.hxx:647
NumericTraits< V >::Promote prod(TinyVectorBase< V, SIZE, D1, D2 > const &l)
product of the vector's elements
Definition: tinyvector.hxx:1895
void readAndResize(std::string datasetName, MultiArray< N, T, Alloc > &array)
Read data into a MultiArray. Resize MultiArray to the correct size. If the first character of dataset...
Definition: hdf5impex.hxx:1382
void readHDF5(...)
Read the data specified by the given vigra::HDF5ImportInfo object and write the into the given 'array...
void readAndResize(std::string datasetName, ArrayVector< T > &array)
Read data into an array vector. Resize the array vector to the correct size. If the first character o...
Definition: hdf5impex.hxx:1421
~HDF5Handle()
Destructor. Calls close() for the contained handle.
Definition: hdf5impex.hxx:209
void read(std::string datasetName, char &data)
Read a single value. Specialization of the read function for simple datatypes.
Definition: hdf5impex.hxx:1565
void open(std::string filename, OpenMode mode)
Open or create the given file in the given mode and set the group to "/". If another file is currentl...
Definition: hdf5impex.hxx:666
PixelType pixelType() const
OpenMode
Set how a file is opened.
Definition: hdf5impex.hxx:614
void readAttribute(std::string object_name, std::string attribute_name, char &data)
Read a single value. Specialization of the read function for simple datatypes.
Definition: hdf5impex.hxx:1113
void writeBlock(std::string datasetName, typename MultiArrayShape< N >::type blockOffset, const MultiArrayView< N, T, Stride > &array)
Write a multi array into a larger volume. blockOffset determines the position, where array is written...
Definition: hdf5impex.hxx:1225
void flushToDisk()
Immediately write all data to disk.
Definition: hdf5impex.hxx:1683
HDF5Handle(HDF5Handle const &h)
Copy constructor. Hands over ownership of the RHS handle (analogous to VIGRA_UNIQUE_PTR).
Definition: hdf5impex.hxx:183
Class for fixed size vectors.This class contains an array of size SIZE of the specified VALUETYPE...
Definition: accessor.hxx:940
void writeHDF5(...)
Store array data in an HDF5 file.
MultiArrayIndex shapeOfDimension(const int dim) const
HDF5Handle getAttributeHandle(std::string dataset_name, std::string attribute_name)
Obtain the HDF5 handle of a attribute.
Definition: hdf5impex.hxx:978
HDF5Handle getGroupHandle(std::string group_name, std::string function_name="HDF5File::getGroupHandle()")
Obtain the HDF5 handle of a group.
Definition: hdf5impex.hxx:961
std::string pwd() const
Get the path of the current group.
Definition: hdf5impex.hxx:812
bool existsDataset(std::string datasetName)
Check if given datasetName exists.
Definition: hdf5impex.hxx:826
void read(std::string datasetName, MultiArrayView< N, T, Stride > array)
Read data into a multi array. If the first character of datasetName is a "/", the path will be interp...
Definition: hdf5impex.hxx:1364
void write(std::string datasetName, char data)
Write a single value. Specialization of the write function for simple datatypes.
Definition: hdf5impex.hxx:1335
const char * getPixelType() const
void writeAttribute(std::string object_name, std::string attribute_name, char data)
Write a single value. Specialization of the write function for simple datatypes.
Definition: hdf5impex.hxx:1026
void writeAttribute(std::string object_name, std::string attribute_name, const MultiArrayView< N, T, Stride > &array)
Write MultiArray Attributes. In contrast to datasets, subarray access, chunks and compression are not...
Definition: hdf5impex.hxx:991
herr_t close()
Explicitly call the stored function (if one has been stored within this object) for the contained han...
Definition: hdf5impex.hxx:217
CoupledIteratorType< N >::type createCoupledIterator(TinyVector< MultiArrayIndex, N > const &shape)
Definition: multi_iterator_coupled.hxx:1052
void write(std::string datasetName, const MultiArrayView< N, T, Stride > &array, int iChunkSize=0, int compression=0)
Write multi arrays.
Definition: hdf5impex.hxx:1171
image import and export functions
void close()
Close the current file.
Definition: hdf5impex.hxx:677
bool cd_up()
Change the current group to its parent group. Returns true if successful, false otherwise. If unsuccessful, the group will not change.
Definition: hdf5impex.hxx:703
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:655
ArrayVector< hsize_t > getDatasetShape(std::string datasetName)
Get the shape of each dimension of a certain dataset.
Definition: hdf5impex.hxx:866
const_iterator end() const
Definition: array_vector.hxx:237
const_pointer data() const
Definition: array_vector.hxx:209
ArrayVector< hsize_t > const & shape() const
Definition: hdf5impex.hxx:339
size_type size() const
Definition: array_vector.hxx:330
void readBlock(std::string datasetName, typename MultiArrayShape< N >::type blockOffset, typename MultiArrayShape< N >::type blockShape, MultiArrayView< N, T, Stride > array)
Read a block of data into a multi array. This function allows to read a small block out of a larger v...
Definition: hdf5impex.hxx:1459
int ceil(FixedPoint< IntBits, FracBits > v)
rounding up.
Definition: fixedpoint.hxx:675
hid_t getDatasetHandle() const
TinyVector< V, SIZE > reverse(TinyVector< V, SIZE > const &t)
reversed copy
Definition: tinyvector.hxx:2037
HDF5File(int track_creation_times=0)
Default constructor.
Definition: hdf5impex.hxx:627
hid_t getH5FileHandle() const
void root()
Change current group to "/".
Definition: hdf5impex.hxx:685
void cd(std::string groupName)
Change the current group. Both absolute and relative group names are allowed.
Definition: hdf5impex.hxx:694
Access to HDF5 files.
Definition: hdf5impex.hxx:562
std::vector< std::string > ls() const
List the contents of the current group. The function returns a vector of strings holding the entries ...
Definition: hdf5impex.hxx:782