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_impex.hxx"
76 #include "utilities.hxx"
119 typedef herr_t (*Destructor)(hid_t);
123 Destructor destructor_;
154 HDF5Handle(hid_t h, Destructor destructor,
const char * error_message)
156 destructor_(destructor)
159 vigra_fail(error_message);
166 : handle_( h.handle_ ),
167 destructor_(h.destructor_)
178 if(h.handle_ != handle_)
182 destructor_ = h.destructor_;
202 if(handle_ && destructor_)
203 res = (*destructor_)(handle_);
223 operator hid_t()
const
232 return handle_ == h.handle_;
246 return handle_ != h.handle_;
276 enum PixelType { UINT8, UINT16, UINT32, UINT64,
277 INT8, INT16, INT32, INT64,
290 VIGRA_EXPORT
HDF5ImportInfo(
const char* filePath,
const char* pathInFile );
292 VIGRA_EXPORT ~HDF5ImportInfo();
296 VIGRA_EXPORT
const std::string&
getFilePath()
const;
369 VIGRA_EXPORT PixelType
pixelType()
const;
373 std::string m_filename, m_path, m_pixeltype;
374 hssize_t m_dimensions;
382 inline hid_t getH5DataType()
384 std::runtime_error(
"getH5DataType(): invalid type");
388 #define VIGRA_H5_DATATYPE(type, h5type) \
390 inline hid_t getH5DataType<type>() \
393 VIGRA_H5_DATATYPE(
char, H5T_NATIVE_CHAR)
394 VIGRA_H5_DATATYPE(
float, H5T_NATIVE_FLOAT)
395 VIGRA_H5_DATATYPE(
double, H5T_NATIVE_DOUBLE)
396 VIGRA_H5_DATATYPE(
long double, H5T_NATIVE_LDOUBLE)
400 inline hid_t getH5DataType<
char*>()
402 hid_t stringtype = H5Tcopy (H5T_C_S1);
403 H5Tset_size(stringtype, H5T_VARIABLE);
407 inline hid_t getH5DataType<const char*>()
409 hid_t stringtype = H5Tcopy (H5T_C_S1);
410 H5Tset_size(stringtype, H5T_VARIABLE);
413 #undef VIGRA_H5_DATATYPE
415 #define VIGRA_H5_SIGNED_DATATYPE(type) \
417 inline hid_t getH5DataType<type>() \
418 { static hid_t types[] = {0, H5T_NATIVE_INT8, H5T_NATIVE_INT16, 0, H5T_NATIVE_INT32, 0,0,0,H5T_NATIVE_INT64}; \
419 return types[sizeof(type)];}
421 VIGRA_H5_SIGNED_DATATYPE(
signed char)
422 VIGRA_H5_SIGNED_DATATYPE(
signed short)
423 VIGRA_H5_SIGNED_DATATYPE(
signed int)
424 VIGRA_H5_SIGNED_DATATYPE(
signed long)
425 VIGRA_H5_SIGNED_DATATYPE(
signed long long)
427 #undef VIGRA_H5_SIGNED_DATATYPE
429 #define VIGRA_H5_UNSIGNED_DATATYPE(type) \
431 inline hid_t getH5DataType<type>() \
432 { static hid_t types[] = {0, H5T_NATIVE_UINT8, H5T_NATIVE_UINT16, 0, H5T_NATIVE_UINT32, 0,0,0,H5T_NATIVE_UINT64}; \
433 return types[sizeof(type)];}
435 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned char)
436 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned short)
437 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned int)
438 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned long)
439 VIGRA_H5_UNSIGNED_DATATYPE(
unsigned long long)
441 #undef VIGRA_H5_UNSIGNED_DATATYPE
445 inline hid_t getH5DataType<FFTWComplex<float> >()
447 hid_t complex_id = H5Tcreate (H5T_COMPOUND,
sizeof (FFTWComplex<float>));
448 H5Tinsert (complex_id,
"real", 0, H5T_NATIVE_FLOAT);
449 H5Tinsert (complex_id,
"imaginary",
sizeof(
float), H5T_NATIVE_FLOAT);
454 inline hid_t getH5DataType<FFTWComplex<double> >()
456 hid_t complex_id = H5Tcreate (H5T_COMPOUND,
sizeof (FFTWComplex<double>));
457 H5Tinsert (complex_id,
"real", 0, H5T_NATIVE_DOUBLE);
458 H5Tinsert (complex_id,
"imaginary",
sizeof(
double), H5T_NATIVE_DOUBLE);
467 void HDF5_ls_insert(
void*,
const std::string &);
472 VIGRA_EXPORT H5O_type_t HDF5_get_type(hid_t,
const char*);
473 extern "C" VIGRA_EXPORT herr_t HDF5_ls_inserter_callback(hid_t,
const char*,
const H5L_info_t*,
void*);
528 virtual void insert(
const std::string &) = 0;
529 virtual ~ls_closure() {}
532 struct lsOpData :
public ls_closure
534 std::vector<std::string> & objects;
535 lsOpData(std::vector<std::string> & o) : objects(o) {}
536 void insert(
const std::string & x)
538 objects.push_back(x);
542 template<
class Container>
543 struct ls_container_data :
public ls_closure
546 ls_container_data(Container & o) : objects(o) {}
547 void insert(
const std::string & x)
549 objects.insert(std::string(x));
556 friend void HDF5_ls_insert(
void*,
const std::string &);
579 : track_time(track_creation_times)
591 : track_time(track_creation_times)
593 open(filename, mode);
621 std::string errorMessage =
"HDF5File.open(): Could not open or create file '" + filename +
"'.";
622 fileHandle_ =
HDF5Handle(createFile_(filename, mode), &H5Fclose, errorMessage.c_str());
623 cGroupHandle_ =
HDF5Handle(openCreateGroup_(
"/"), &H5Gclose,
"HDF5File.open(): Failed to open root group.");
630 bool success = cGroupHandle_.
close() >= 0 && fileHandle_.
close() >= 0;
631 vigra_postcondition(success,
"HDF5File.close() failed.");
638 std::string message =
"HDF5File::root(): Could not open group '/'.";
639 cGroupHandle_ =
HDF5Handle(H5Gopen(fileHandle_,
"/", H5P_DEFAULT),&H5Gclose,message.c_str());
645 inline void cd(std::string groupName)
647 std::string message =
"HDF5File::cd(): Could not open group '" + groupName +
"'.\n";
654 cGroupHandle_ =
HDF5Handle(openCreateGroup_(
"/"),&H5Gclose,message.c_str());
658 vigra_precondition(H5Lexists(fileHandle_, groupName.c_str(), H5P_DEFAULT) != 0, message);
659 cGroupHandle_ =
HDF5Handle(openCreateGroup_(groupName),&H5Gclose,message.c_str());
669 std::string groupName = currentGroupName_();
672 if(groupName ==
"/"){
676 size_t lastSlash = groupName.find_last_of(
'/');
678 std::string parentGroup (groupName.begin(), groupName.begin()+lastSlash+1);
691 std::string groupName = currentGroupName_();
693 for(
int i = 0; i<levels; i++)
698 if(groupName != currentGroupName_())
710 inline void mkdir(std::string groupName)
712 std::string message =
"HDF5File::mkdir(): Could not create group '" + groupName +
"'.\n";
717 HDF5Handle(openCreateGroup_(groupName.c_str()),&H5Gclose,message.c_str());
724 inline void cd_mk(std::string groupName)
726 std::string message =
"HDF5File::cd_mk(): Could not create group '" + groupName +
"'.";
731 cGroupHandle_ =
HDF5Handle(openCreateGroup_(groupName.c_str()),&H5Gclose,message.c_str());
735 void ls_H5Literate(ls_closure & data)
const
737 H5Literate(cGroupHandle_, H5_INDEX_NAME, H5_ITER_NATIVE, NULL,
738 HDF5_ls_inserter_callback, static_cast<void*>(&data));
746 inline std::vector<std::string>
ls()
const
748 std::vector<std::string> list;
767 template<
class Container>
768 void ls(Container & cont)
const
770 ls_container_data<Container> data(cont);
776 inline std::string
pwd()
const
778 return currentGroupName_();
798 std::string errorMessage =
"HDF5File::getDatasetDimensions(): Unable to open dataset '" + datasetName +
"'.";
799 HDF5Handle datasetHandle =
HDF5Handle(getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
801 errorMessage =
"HDF5File::getDatasetDimensions(): Unable to access dataspace.";
802 HDF5Handle dataspaceHandle(H5Dget_space(datasetHandle), &H5Sclose, errorMessage.c_str());
805 return H5Sget_simple_extent_ndims(dataspaceHandle);
827 std::string errorMessage =
"HDF5File::getDatasetShape(): Unable to open dataset '" + datasetName +
"'.";
828 HDF5Handle datasetHandle =
HDF5Handle(getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
830 errorMessage =
"HDF5File::getDatasetShape(): Unable to access dataspace.";
831 HDF5Handle dataspaceHandle(H5Dget_space(datasetHandle), &H5Sclose, errorMessage.c_str());
838 H5Sget_simple_extent_dims(dataspaceHandle, shape.
data(), maxdims.
data());
841 std::reverse(shape.
begin(), shape.
end());
849 std::string errorMessage =
"HDF5File::getDatasetHandle(): Unable to open dataset '" + dataset_name +
"'.";
850 return HDF5Handle(getDatasetHandle_(dataset_name), &H5Dclose, errorMessage.c_str());
857 std::string errorMessage =
"HDF5File::getGroupHandle(): Group '" + group_name +
"' not found.";
863 vigra_precondition(H5Lexists(fileHandle_, group_name.c_str(), H5P_DEFAULT) == 1,
864 errorMessage.c_str());
867 return HDF5Handle(openCreateGroup_(group_name), &H5Gclose,
"Internal error");
874 std::string message =
"HDF5File::getAttributeHandle(): Attribute '" + attribute_name +
"' not found.";
876 &H5Aclose, message.c_str());
884 template<
unsigned int N,
class T>
890 write_attribute_(object_name, attribute_name, array, detail::getH5DataType<T>(), 1);
893 template<
unsigned int N,
class T,
int SIZE>
899 write_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), SIZE);
902 template<
unsigned int N,
class T>
903 inline void writeAttribute(std::string datasetName, std::string attributeName,
const MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> & array)
908 write_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), 3);
914 inline void writeAttribute(std::string object_name, std::string attribute_name,
char data)
915 { writeAtomicAttribute(object_name,attribute_name,data); }
916 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed char data)
917 { writeAtomicAttribute(datasetName,attributeName,data); }
918 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed short data)
919 { writeAtomicAttribute(datasetName,attributeName,data); }
920 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed int data)
921 { writeAtomicAttribute(datasetName,attributeName,data); }
922 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed long data)
923 { writeAtomicAttribute(datasetName,attributeName,data); }
924 inline void writeAttribute(std::string datasetName, std::string attributeName,
signed long long data)
925 { writeAtomicAttribute(datasetName,attributeName,data); }
926 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned char data)
927 { writeAtomicAttribute(datasetName,attributeName,data); }
928 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned short data)
929 { writeAtomicAttribute(datasetName,attributeName,data); }
930 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned int data)
931 { writeAtomicAttribute(datasetName,attributeName,data); }
932 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned long data)
933 { writeAtomicAttribute(datasetName,attributeName,data); }
934 inline void writeAttribute(std::string datasetName, std::string attributeName,
unsigned long long data)
935 { writeAtomicAttribute(datasetName,attributeName,data); }
936 inline void writeAttribute(std::string datasetName, std::string attributeName,
float data)
937 { writeAtomicAttribute(datasetName,attributeName,data); }
938 inline void writeAttribute(std::string datasetName, std::string attributeName,
double data)
939 { writeAtomicAttribute(datasetName,attributeName,data); }
940 inline void writeAttribute(std::string datasetName, std::string attributeName,
long double data)
941 { writeAtomicAttribute(datasetName,attributeName,data); }
942 inline void writeAttribute(std::string datasetName, std::string attributeName,
const char* data)
943 { writeAtomicAttribute(datasetName,attributeName,data); }
944 inline void writeAttribute(std::string datasetName, std::string attributeName, std::string
const & data)
945 { writeAtomicAttribute(datasetName,attributeName,data.c_str()); }
952 htri_t exists = H5Aexists_by_name(fileHandle_, obj_path.c_str(),
953 attribute_name.c_str(), H5P_DEFAULT);
954 vigra_precondition(exists >= 0,
"HDF5File::existsAttribute(): "
955 "object '" + object_name +
"' "
965 template<
unsigned int N,
class T>
971 read_attribute_(object_name, attribute_name, array, detail::getH5DataType<T>(), 1);
974 template<
unsigned int N,
class T,
int SIZE>
980 read_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), SIZE);
983 template<
unsigned int N,
class T>
984 inline void readAttribute(std::string datasetName, std::string attributeName,
const MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> & array)
989 read_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), 3);
995 inline void readAttribute(std::string object_name, std::string attribute_name,
char &data)
996 { readAtomicAttribute(object_name,attribute_name,data); }
997 inline void readAttribute(std::string datasetName, std::string attributeName,
signed char &data)
998 { readAtomicAttribute(datasetName,attributeName,data); }
999 inline void readAttribute(std::string datasetName, std::string attributeName,
signed short &data)
1000 { readAtomicAttribute(datasetName,attributeName,data); }
1001 inline void readAttribute(std::string datasetName, std::string attributeName,
signed int &data)
1002 { readAtomicAttribute(datasetName,attributeName,data); }
1003 inline void readAttribute(std::string datasetName, std::string attributeName,
signed long &data)
1004 { readAtomicAttribute(datasetName,attributeName,data); }
1005 inline void readAttribute(std::string datasetName, std::string attributeName,
signed long long &data)
1006 { readAtomicAttribute(datasetName,attributeName,data); }
1007 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned char &data)
1008 { readAtomicAttribute(datasetName,attributeName,data); }
1009 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned short &data)
1010 { readAtomicAttribute(datasetName,attributeName,data); }
1011 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned int &data)
1012 { readAtomicAttribute(datasetName,attributeName,data); }
1013 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned long &data)
1014 { readAtomicAttribute(datasetName,attributeName,data); }
1015 inline void readAttribute(std::string datasetName, std::string attributeName,
unsigned long long &data)
1016 { readAtomicAttribute(datasetName,attributeName,data); }
1017 inline void readAttribute(std::string datasetName, std::string attributeName,
float &data)
1018 { readAtomicAttribute(datasetName,attributeName,data); }
1019 inline void readAttribute(std::string datasetName, std::string attributeName,
double &data)
1020 { readAtomicAttribute(datasetName,attributeName,data); }
1021 inline void readAttribute(std::string datasetName, std::string attributeName,
long double &data)
1022 { readAtomicAttribute(datasetName,attributeName,data); }
1023 inline void readAttribute(std::string datasetName, std::string attributeName, std::string &data)
1024 { readAtomicAttribute(datasetName,attributeName,data); }
1048 template<
unsigned int N,
class T>
1055 for(
unsigned int i = 0; i < N; i++){
1056 chunkSize[i] = iChunkSize;
1058 write_(datasetName, array, detail::getH5DataType<T>(), 1, chunkSize, compression);
1078 template<
unsigned int N,
class T>
1084 write_(datasetName, array, detail::getH5DataType<T>(), 1, chunkSize, compression);
1106 template<
unsigned int N,
class T>
1112 writeBlock_(datasetName, blockOffset, array, detail::getH5DataType<T>(), 1);
1116 template<
unsigned int N,
class T,
int SIZE>
1123 for(
int i = 0; i < N; i++){
1124 chunkSize[i] = iChunkSize;
1126 write_(datasetName, array, detail::getH5DataType<T>(), SIZE, chunkSize, compression);
1129 template<
unsigned int N,
class T,
int SIZE>
1130 inline void write(std::string datasetName,
const MultiArrayView<N, TinyVector<T, SIZE>, UnstridedArrayTag> & array,
typename MultiArrayShape<N>::type chunkSize,
int compression = 0)
1135 write_(datasetName, array, detail::getH5DataType<T>(), SIZE, chunkSize, compression);
1149 void write(
const std::string & datasetName,
1151 int compression = 0)
1156 write(datasetName, m_array, compression);
1159 template<
unsigned int N,
class T,
int SIZE>
1165 writeBlock_(datasetName, blockOffset, array, detail::getH5DataType<T>(), SIZE);
1169 template<
unsigned int N,
class T>
1170 inline void write(std::string datasetName,
const MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> & array,
int iChunkSize = 0,
int compression = 0)
1175 typename MultiArrayShape<N>::type chunkSize;
1176 for(
int i = 0; i < N; i++){
1177 chunkSize[i] = iChunkSize;
1179 write_(datasetName, array, detail::getH5DataType<T>(), 3, chunkSize, compression);
1182 template<
unsigned int N,
class T>
1183 inline void write(std::string datasetName,
const MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> & array,
typename MultiArrayShape<N>::type chunkSize,
int compression = 0)
1188 write_(datasetName, array, detail::getH5DataType<T>(), 3, chunkSize, compression);
1191 template<
unsigned int N,
class T>
1192 inline void writeBlock(std::string datasetName,
typename MultiArrayShape<N>::type blockOffset,
const MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> & array)
1197 writeBlock_(datasetName, blockOffset, array, detail::getH5DataType<T>(), 3);
1203 inline void write(std::string datasetName,
char data) { writeAtomic(datasetName,data); }
1204 inline void write(std::string datasetName,
signed char data) { writeAtomic(datasetName,data); }
1205 inline void write(std::string datasetName,
signed short data) { writeAtomic(datasetName,data); }
1206 inline void write(std::string datasetName,
signed int data) { writeAtomic(datasetName,data); }
1207 inline void write(std::string datasetName,
signed long data) { writeAtomic(datasetName,data); }
1208 inline void write(std::string datasetName,
signed long long data) { writeAtomic(datasetName,data); }
1209 inline void write(std::string datasetName,
unsigned char data) { writeAtomic(datasetName,data); }
1210 inline void write(std::string datasetName,
unsigned short data) { writeAtomic(datasetName,data); }
1211 inline void write(std::string datasetName,
unsigned int data) { writeAtomic(datasetName,data); }
1212 inline void write(std::string datasetName,
unsigned long data) { writeAtomic(datasetName,data); }
1213 inline void write(std::string datasetName,
unsigned long long data) { writeAtomic(datasetName,data); }
1214 inline void write(std::string datasetName,
float data) { writeAtomic(datasetName,data); }
1215 inline void write(std::string datasetName,
double data) { writeAtomic(datasetName,data); }
1216 inline void write(std::string datasetName,
long double data) { writeAtomic(datasetName,data); }
1217 inline void write(std::string datasetName,
const char* data) { writeAtomic(datasetName,data); }
1218 inline void write(std::string datasetName, std::string
const & data) { writeAtomic(datasetName,data.c_str()); }
1231 template<
unsigned int N,
class T>
1237 read_(datasetName, array, detail::getH5DataType<T>(), 1);
1249 template<
unsigned int N,
class T>
1260 "HDF5File::readAndResize(): Array dimension disagrees with dataset dimension.");
1264 for(
int k=0; k < (int)dimshape.
size(); ++k)
1268 read_(datasetName, array, detail::getH5DataType<T>(), 1);
1281 read(datasetName, m_array);
1300 "HDF5File::readAndResize(): Array dimension disagrees with Dataset dimension must equal one for vigra::ArrayVector.");
1308 read_(datasetName, m_array, detail::getH5DataType<T>(), 1);
1326 template<
unsigned int N,
class T>
1332 readBlock_(datasetName, blockOffset, blockShape, array, detail::getH5DataType<T>(), 1);
1336 template<
unsigned int N,
class T,
int SIZE>
1342 read_(datasetName, array, detail::getH5DataType<T>(), SIZE);
1346 template<
unsigned int N,
class T,
int SIZE>
1347 inline void readAndResize(std::string datasetName, MultiArray<N, TinyVector<T, SIZE> > & array)
1357 SIZE == dimshape[0],
1358 "HDF5File::readAndResize(): Array dimension disagrees with dataset dimension.");
1361 typename MultiArrayShape<N>::type shape;
1362 for(
int k=1; k < (int)dimshape.size(); ++k)
1364 array.reshape(shape);
1366 read_(datasetName, array, detail::getH5DataType<T>(), SIZE);
1369 template<
unsigned int N,
class T,
int SIZE>
1370 inline void readBlock(std::string datasetName,
typename MultiArrayShape<N>::type blockOffset,
typename MultiArrayShape<N>::type blockShape, MultiArrayView<N, TinyVector<T, SIZE>, UnstridedArrayTag> & array)
1375 readBlock_(datasetName, blockOffset, blockShape, array, detail::getH5DataType<T>(), SIZE);
1379 template<
unsigned int N,
class T>
1380 inline void read(std::string datasetName, MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> & array)
1385 read_(datasetName, array, detail::getH5DataType<T>(), 3);
1389 template<
unsigned int N,
class T>
1390 inline void readAndResize(std::string datasetName, MultiArray<N, RGBValue<T> > & array)
1401 "HDF5File::readAndResize(): Array dimension disagrees with dataset dimension.");
1404 typename MultiArrayShape<N>::type shape;
1405 for(
int k=1; k < (int)dimshape.size(); ++k)
1407 array.reshape(shape);
1409 read_(datasetName, array, detail::getH5DataType<T>(), 3);
1412 template<
unsigned int N,
class T>
1413 inline void readBlock(std::string datasetName,
typename MultiArrayShape<N>::type blockOffset,
typename MultiArrayShape<N>::type blockShape, MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> & array)
1418 readBlock_(datasetName, blockOffset, blockShape, array, detail::getH5DataType<T>(), 3);
1424 inline void read(std::string datasetName,
char &data) { readAtomic(datasetName,data); }
1425 inline void read(std::string datasetName,
signed char &data) { readAtomic(datasetName,data); }
1426 inline void read(std::string datasetName,
signed short &data) { readAtomic(datasetName,data); }
1427 inline void read(std::string datasetName,
signed int &data) { readAtomic(datasetName,data); }
1428 inline void read(std::string datasetName,
signed long &data) { readAtomic(datasetName,data); }
1429 inline void read(std::string datasetName,
signed long long &data) { readAtomic(datasetName,data); }
1430 inline void read(std::string datasetName,
unsigned char &data) { readAtomic(datasetName,data); }
1431 inline void read(std::string datasetName,
unsigned short &data) { readAtomic(datasetName,data); }
1432 inline void read(std::string datasetName,
unsigned int &data) { readAtomic(datasetName,data); }
1433 inline void read(std::string datasetName,
unsigned long &data) { readAtomic(datasetName,data); }
1434 inline void read(std::string datasetName,
unsigned long long &data) { readAtomic(datasetName,data); }
1435 inline void read(std::string datasetName,
float &data) { readAtomic(datasetName,data); }
1436 inline void read(std::string datasetName,
double &data) { readAtomic(datasetName,data); }
1437 inline void read(std::string datasetName,
long double &data) { readAtomic(datasetName,data); }
1438 inline void read(std::string datasetName, std::string &data) { readAtomic(datasetName,data); }
1464 template<
unsigned int N,
class T>
1469 int compressionParameter = 0)
1475 for(
int i = 0; i < N; i++){
1476 chunkSize[i] = iChunkSize;
1478 createDataset<N,T>(datasetName, shape, init, chunkSize, compressionParameter);
1481 template<
unsigned int N,
class T>
1486 int compressionParameter = 0)
1491 std::string groupname = SplitString(datasetName).first();
1492 std::string setname = SplitString(datasetName).last();
1494 hid_t parent = openCreateGroup_(groupname);
1497 deleteDataset_(parent, setname);
1504 hsize_t shape_inv[N];
1505 for(
unsigned int k=0; k<N; ++k)
1506 shape_inv[N-1-k] = shape[k];
1509 dataspaceHandle =
HDF5Handle(H5Screate_simple(N, shape_inv, NULL),
1510 &H5Sclose,
"HDF5File::createDataset(): unable to create dataspace for scalar data.");
1513 HDF5Handle plist ( H5Pcreate(H5P_DATASET_CREATE), &H5Pclose,
"HDF5File::createDataset(): unable to create property list." );
1514 H5Pset_fill_value(plist,detail::getH5DataType<T>(), &init);
1517 H5Pset_obj_track_times(plist, track_time);
1520 if(chunkSize[0] > 0)
1523 for(
int i = 0; i<N; i++)
1525 cSize[i] = chunkSize[N-1-i];
1527 H5Pset_chunk (plist, N, cSize);
1531 if(compressionParameter > 0)
1533 H5Pset_deflate(plist, compressionParameter);
1537 HDF5Handle datasetHandle ( H5Dcreate(parent, setname.c_str(), detail::getH5DataType<T>(), dataspaceHandle, H5P_DEFAULT, plist, H5P_DEFAULT),
1538 &H5Dclose,
"HDF5File::createDataset(): unable to create dataset.");
1539 if(parent != cGroupHandle_)
1547 H5Fflush(fileHandle_, H5F_SCOPE_GLOBAL);
1560 class SplitString:
public std::string {
1562 SplitString(std::string &sstring): std::string(sstring) {};
1565 std::string first(
char delimiter =
'/')
1567 size_t last = find_last_of(delimiter);
1568 if(last == std::string::npos)
1571 return std::string(begin(), begin()+last+1);
1575 std::string last(
char delimiter =
'/')
1577 size_t last = find_last_of(delimiter);
1578 if(last == std::string::npos)
1579 return std::string(*
this);
1580 return std::string(begin()+last+1, end());
1594 if(path.length() == 0 || path ==
"."){
1595 return currentGroupName_();
1600 if(relativePath_(path)){
1601 std::string cname = currentGroupName_();
1603 str = currentGroupName_()+path;
1605 str = currentGroupName_()+
"/"+path;
1611 std::string::size_type startpos = 0;
1612 while(str.find(std::string(
"./"), startpos) != std::string::npos){
1613 std::string::size_type pos = str.find(std::string(
"./"), startpos);
1616 if(str.substr(pos-1,3) !=
"../"){
1618 str = str.substr(0,pos) + str.substr(pos+2,str.length()-pos-2);
1624 while(str.find(std::string(
"..")) != std::string::npos){
1625 std::string::size_type pos = str.find(std::string(
".."));
1628 std::string::size_type end = str.find(
"/",pos);
1629 if(end != std::string::npos){
1639 std::string::size_type prev_slash = str.rfind(
"/",pos);
1641 vigra_invariant(prev_slash != 0 && prev_slash != std::string::npos,
1642 "Error parsing path: "+str);
1644 std::string::size_type begin = str.rfind(
"/",prev_slash-1);
1647 str = str.substr(0,begin+1) + str.substr(end,str.length()-end);
1657 inline bool relativePath_(std::string & path)
const
1659 std::string::size_type pos = path.find(
'/') ;
1668 inline std::string currentGroupName_()
const
1670 int len = H5Iget_name(cGroupHandle_,NULL,1000);
1671 ArrayVector<char> name (len+1,0);
1672 H5Iget_name(cGroupHandle_,name.begin(),len+1);
1674 return std::string(name.begin());
1679 inline std::string fileName_()
const
1681 int len = H5Fget_name(fileHandle_,NULL,1000);
1682 ArrayVector<char> name (len+1,0);
1683 H5Fget_name(fileHandle_,name.begin(),len+1);
1685 return std::string(name.begin());
1690 inline hid_t createFile_(std::string filePath,
OpenMode mode = Open)
1694 pFile = fopen ( filePath.c_str(),
"r" );
1698 if ( pFile == NULL )
1700 fileId = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
1702 else if(mode == Open)
1705 fileId = H5Fopen(filePath.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
1707 else if(mode == OpenReadOnly) {
1709 fileId = H5Fopen(filePath.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
1714 std::remove(filePath.c_str());
1715 fileId = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
1722 inline hid_t openCreateGroup_(std::string groupName)
1728 hid_t parent = H5Gopen(fileHandle_,
"/", H5P_DEFAULT);
1729 if(groupName ==
"/")
1735 groupName = std::string(groupName.begin()+1, groupName.end());
1738 if( groupName.size() != 0 && *groupName.rbegin() !=
'/')
1740 groupName = groupName +
'/';
1744 std::string::size_type begin = 0, end = groupName.find(
'/');
1745 while (end != std::string::npos)
1747 std::string group(groupName.begin()+begin, groupName.begin()+end);
1748 hid_t prevParent = parent;
1750 if(H5LTfind_dataset(parent, group.c_str()) == 0)
1752 parent = H5Gcreate(prevParent, group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1754 parent = H5Gopen(prevParent, group.c_str(), H5P_DEFAULT);
1756 H5Gclose(prevParent);
1763 end = groupName.find(
'/', begin);
1772 inline void deleteDataset_(hid_t parent, std::string datasetName)
1775 if(H5LTfind_dataset(parent, datasetName.c_str()))
1778 #if (H5_VERS_MAJOR == 1 && H5_VERS_MINOR <= 6)
1779 if(H5Gunlink(parent, datasetName.c_str()) < 0)
1781 vigra_postcondition(
false,
"HDF5File::deleteDataset_(): Unable to delete existing data.");
1784 if(H5Ldelete(parent, datasetName.c_str(), H5P_DEFAULT ) < 0)
1786 vigra_postcondition(
false,
"HDF5File::deleteDataset_(): Unable to delete existing data.");
1794 inline hid_t getDatasetHandle_(std::string datasetName)
1799 std::string groupname = SplitString(datasetName).first();
1800 std::string setname = SplitString(datasetName).last();
1802 if(H5Lexists(fileHandle_, datasetName.c_str(), H5P_DEFAULT) <= 0)
1804 std::cerr <<
"HDF5File::getDatasetHandle_(): Dataset '" << datasetName <<
"' does not exist.\n";
1809 HDF5Handle groupHandle(openCreateGroup_(groupname), &H5Gclose,
"Internal error");
1811 return H5Dopen(groupHandle, setname.c_str(), H5P_DEFAULT);
1816 H5O_type_t get_object_type_(std::string name)
1819 std::string group_name = SplitString(name).first();
1820 std::string object_name = SplitString(name).last();
1821 if (!object_name.size())
1822 return H5O_TYPE_GROUP;
1824 htri_t exists = H5Lexists(fileHandle_, name.c_str(), H5P_DEFAULT);
1825 vigra_precondition(exists > 0,
"HDF5File::get_object_type_(): "
1826 "object \"" + name +
"\" "
1829 HDF5Handle group_handle(openCreateGroup_(group_name), &H5Gclose,
"Internal error");
1830 return HDF5_get_type(group_handle, name.c_str());
1835 template<
unsigned int N,
class T>
1836 void write_attribute_(std::string name,
const std::string & attribute_name,
1837 const MultiArrayView<N, T, UnstridedArrayTag> & array,
1838 const hid_t datatype,
1839 const int numBandsOfType)
1842 ArrayVector<hsize_t> shape(array.shape().begin(), array.shape().end());
1843 std::reverse(shape.
begin(), shape.
end());
1844 if(numBandsOfType > 1)
1845 shape.push_back(numBandsOfType);
1847 HDF5Handle dataspace(H5Screate_simple(shape.
size(),
1848 shape.
begin(), NULL),
1849 &H5Sclose,
"HDF5File::writeAttribute(): Can not"
1850 " create dataspace.");
1852 std::string errorMessage (
"HDF5File::writeAttribute(): can not find "
1853 "object '" + name +
"'.");
1855 H5O_type_t h5_type = get_object_type_(name);
1856 bool is_group = h5_type == H5O_TYPE_GROUP;
1857 if (!is_group && h5_type != H5O_TYPE_DATASET)
1858 vigra_precondition(0,
"HDF5File::writeAttribute(): object \""
1859 + name +
"\" is neither a group nor a "
1862 HDF5Handle object_handle(is_group
1863 ? openCreateGroup_(name)
1864 : getDatasetHandle_(name),
1868 errorMessage.c_str());
1871 HDF5Handle attributeHandle(exists
1872 ? H5Aopen(object_handle,
1873 attribute_name.c_str(),
1875 : H5Acreate(object_handle,
1876 attribute_name.c_str(), datatype,
1877 dataspace, H5P_DEFAULT,
1880 "HDF5File::writeAttribute(): Can not create"
1884 H5Awrite(attributeHandle, datatype, array.data());
1893 inline void writeAtomicAttribute(std::string datasetName, std::string attributeName,
const T data)
1898 typename MultiArrayShape<1>::type chunkSize;
1900 MultiArray<1,T> array(MultiArrayShape<1>::type(1));
1902 write_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), 1);
1907 template<
unsigned int N,
class T>
1908 inline void read_attribute_(std::string datasetName, std::string attributeName, MultiArrayView<N, T, UnstridedArrayTag> array,
const hid_t datatype,
const int numBandsOfType)
1912 std::string message =
"Error: could not get handle for attribute '"+attributeName+
"'' of object '"+dataset_path+
"'.";
1913 HDF5Handle attr_handle (H5Aopen_by_name(fileHandle_,dataset_path.c_str(),attributeName.c_str(),H5P_DEFAULT,H5P_DEFAULT),&H5Aclose, message.c_str());
1916 message =
"Error: could not get dataspace for attribute '"+attributeName+
"'' of object '"+dataset_path+
"'.";
1917 HDF5Handle attr_dataspace_handle (H5Aget_space(attr_handle),&H5Sclose,message.c_str());
1920 int dims = H5Sget_simple_extent_ndims(attr_dataspace_handle);
1921 ArrayVector<hsize_t> dimshape(dims);
1922 H5Sget_simple_extent_dims(attr_dataspace_handle, dimshape.data(), NULL);
1925 std::reverse(dimshape.begin(), dimshape.end());
1927 int offset = (numBandsOfType > 1)
1930 message =
"Error: Array dimension disagrees with dataset dimension.";
1934 typename MultiArrayShape<N>::type shape;
1935 for(
int k=offset; k < (int)dimshape.size(); ++k)
1938 message =
"Error: Array shape disagrees with dataset shape";
1939 vigra_precondition(shape == array.shape(), message);
1942 H5Aread( attr_handle, datatype, array.data());
1951 inline void readAtomicAttribute(std::string datasetName, std::string attributeName, T & data)
1956 MultiArray<1,T> array(MultiArrayShape<1>::type(1));
1957 read_attribute_(datasetName, attributeName, array, detail::getH5DataType<T>(), 1);
1961 inline void readAtomicAttribute(std::string datasetName, std::string attributeName, std::string & data)
1966 MultiArray<1,const char *> array(MultiArrayShape<1>::type(1));
1967 read_attribute_(datasetName, attributeName, array, detail::getH5DataType<const char *>(), 1);
1968 data = std::string(array[0]);
1973 template<
unsigned int N,
class T>
1974 inline void write_(std::string &datasetName,
1975 const MultiArrayView<N, T, UnstridedArrayTag> & array,
1976 const hid_t datatype,
1977 const int numBandsOfType,
1978 typename MultiArrayShape<N>::type &chunkSize,
1979 int compressionParameter = 0)
1981 std::string groupname = SplitString(datasetName).first();
1982 std::string setname = SplitString(datasetName).last();
1985 ArrayVector<hsize_t> shape(array.shape().begin(), array.shape().end());
1986 std::reverse(shape.begin(), shape.end());
1988 if(numBandsOfType > 1)
1989 shape.push_back(numBandsOfType);
1991 HDF5Handle dataspace(H5Screate_simple(shape.size(), shape.begin(), NULL), &H5Sclose,
1992 "HDF5File::write(): Can not create dataspace.");
1995 std::string errorMessage (
"HDF5File::write(): can not create group '" + groupname +
"'.");
1996 HDF5Handle groupHandle(openCreateGroup_(groupname), &H5Gclose, errorMessage.c_str());
1999 deleteDataset_(groupHandle, setname.c_str());
2002 HDF5Handle plist(H5Pcreate(H5P_DATASET_CREATE), &H5Pclose,
2003 "HDF5File::write(): unable to create property list." );
2006 H5Pset_obj_track_times(plist, track_time);
2009 if(chunkSize[0] > 0)
2011 ArrayVector<hsize_t> cSize(chunkSize.begin(), chunkSize.end());
2012 std::reverse(cSize.begin(), cSize.end());
2013 if(numBandsOfType > 1)
2014 cSize.push_back(numBandsOfType);
2016 H5Pset_chunk (plist, cSize.size(), cSize.begin());
2020 if(compressionParameter > 0)
2022 H5Pset_deflate(plist, compressionParameter);
2026 HDF5Handle datasetHandle(H5Dcreate(groupHandle, setname.c_str(), datatype, dataspace,H5P_DEFAULT, plist, H5P_DEFAULT),
2027 &H5Dclose,
"HDF5File::write(): Can not create dataset.");
2030 herr_t write_status = H5Dwrite(datasetHandle, datatype, H5S_ALL,
2031 H5S_ALL, H5P_DEFAULT, array.data());
2032 vigra_precondition(write_status >= 0,
"HDF5File::write_(): write to "
2033 "dataset \"" + datasetName +
"\" "
2046 inline void writeAtomic(std::string datasetName,
const T data)
2051 typename MultiArrayShape<1>::type chunkSize;
2053 MultiArray<1,T> array(MultiArrayShape<1>::type(1));
2055 write_(datasetName, array, detail::getH5DataType<T>(), 1, chunkSize,0);
2060 template<
unsigned int N,
class T>
2061 inline void read_(std::string datasetName,
2062 MultiArrayView<N, T, UnstridedArrayTag> array,
2063 const hid_t datatype,
const int numBandsOfType)
2068 std::string errorMessage (
"HDF5File::read(): Unable to open dataset '" + datasetName +
"'.");
2069 HDF5Handle datasetHandle(getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
2071 int offset = (numBandsOfType > 1)
2076 "HDF5File::read(): Array dimension disagrees with dataset dimension.");
2078 typename MultiArrayShape<N>::type shape;
2079 for(
int k=offset; k < (int)dimshape.size(); ++k)
2082 vigra_precondition(shape == array.shape(),
2083 "HDF5File::read(): Array shape disagrees with dataset shape.");
2085 vigra_precondition(dimshape[0] == static_cast<hsize_t>(numBandsOfType),
2086 "HDF5File::read(): Band count doesn't match destination array compound type.");
2089 H5Dread( datasetHandle, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, array.data() );
2101 inline void readAtomic(std::string datasetName, T & data)
2106 MultiArray<1,T> array(MultiArrayShape<1>::type(1));
2107 read_(datasetName, array, detail::getH5DataType<T>(), 1);
2111 inline void readAtomic(std::string datasetName, std::string & data)
2116 MultiArray<1,const char *> array(MultiArrayShape<1>::type(1));
2117 read_(datasetName, array, detail::getH5DataType<const char *>(), 1);
2118 data = std::string(array[0]);
2123 template<
unsigned int N,
class T>
2124 inline void writeBlock_(std::string datasetName,
typename MultiArrayShape<N>::type &blockOffset,
const MultiArrayView<N, T, UnstridedArrayTag> & array,
const hid_t datatype,
const int numBandsOfType)
2127 std::string errorMessage =
"HDF5File::writeBlock(): Error opening dataset '" + datasetName +
"'.";
2128 HDF5Handle datasetHandle (getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
2131 hsize_t boffset [N];
2135 for(
int i = 0; i < N; i++){
2136 boffset[i] = blockOffset[N-1-i];
2137 bshape[i] = array.size(N-1-i);
2142 HDF5Handle memspace_handle (H5Screate_simple(N,bshape,NULL),&H5Sclose,
"Unable to get origin dataspace");
2145 HDF5Handle dataspaceHandle (H5Dget_space(datasetHandle),&H5Sclose,
"Unable to create target dataspace");
2146 H5Sselect_hyperslab(dataspaceHandle, H5S_SELECT_SET, boffset, bones, bones, bshape);
2149 H5Dwrite( datasetHandle, datatype, memspace_handle, dataspaceHandle, H5P_DEFAULT, array.data());
2154 template<
unsigned int N,
class T>
2155 inline void readBlock_(std::string datasetName,
typename MultiArrayShape<N>::type &blockOffset,
typename MultiArrayShape<N>::type &blockShape, MultiArrayView<N, T, UnstridedArrayTag> &array,
const hid_t datatype,
const int numBandsOfType)
2161 std::string errorMessage (
"HDF5File::readBlock(): Unable to open dataset '" + datasetName +
"'.");
2162 HDF5Handle datasetHandle (getDatasetHandle_(datasetName), &H5Dclose, errorMessage.c_str());
2164 int offset = (numBandsOfType > 1)
2169 "readHDF5_block(): Array dimension disagrees with data dimension.");
2171 vigra_precondition(blockShape == array.shape(),
2172 "readHDF5_block(): Array shape disagrees with block size.");
2175 hsize_t boffset [N];
2179 for(
int i = 0; i < N; i++){
2181 boffset[i] = blockOffset[N-1-i];
2183 bshape[i] = blockShape[N-1-i];
2189 HDF5Handle memspace_handle(H5Screate_simple(N,bshape,NULL),&H5Sclose,
2190 "Unable to create target dataspace");
2193 HDF5Handle dataspaceHandle(H5Dget_space(datasetHandle),&H5Sclose,
2194 "Unable to get dataspace");
2195 H5Sselect_hyperslab(dataspaceHandle, H5S_SELECT_SET, boffset, bones, bones, bshape);
2198 H5Dread( datasetHandle, datatype, memspace_handle, dataspaceHandle, H5P_DEFAULT, array.data() );
2205 template <
class Shape>
2207 selectHyperslabs(HDF5Handle & mid1, HDF5Handle & mid2, Shape
const & shape,
int & counter,
const int elements,
const int numBandsOfType)
2210 hsize_t shapeHDF5[2];
2212 shapeHDF5[1] = elements;
2213 hsize_t startHDF5[2];
2215 startHDF5[1] = counter * numBandsOfType * shape[0];
2216 hsize_t strideHDF5[2];
2219 hsize_t countHDF5[2];
2221 countHDF5[1] = numBandsOfType * shape[0];
2222 hsize_t blockHDF5[2];
2225 mid1 = HDF5Handle(H5Screate_simple(2, shapeHDF5, NULL),
2226 &H5Sclose,
"unable to create hyperslabs.");
2227 H5Sselect_hyperslab(mid1, H5S_SELECT_SET, startHDF5, strideHDF5, countHDF5, blockHDF5);
2229 hsize_t shapeData[2];
2231 shapeData[1] = numBandsOfType * shape[0];
2232 hsize_t startData[2];
2235 hsize_t strideData[2];
2238 hsize_t countData[2];
2240 countData[1] = numBandsOfType * shape[0];
2241 hsize_t blockData[2];
2244 mid2 = HDF5Handle(H5Screate_simple(2, shapeData, NULL),
2245 &H5Sclose,
"unable to create hyperslabs.");
2246 H5Sselect_hyperslab(mid2, H5S_SELECT_SET, startData, strideData, countData, blockData);
2249 template <
class DestIterator,
class Shape,
class T>
2251 readHDF5Impl(DestIterator d, Shape
const & shape,
const hid_t dataset_id,
const hid_t datatype, ArrayVector<T> & buffer,
int & counter,
const int elements,
const int numBandsOfType, MetaInt<0>)
2253 HDF5Handle mid1, mid2;
2256 selectHyperslabs(mid1, mid2, shape, counter, elements, numBandsOfType);
2259 herr_t read_status = H5Dread(dataset_id, datatype, mid2, mid1, H5P_DEFAULT, buffer.data());
2260 vigra_precondition(read_status >= 0,
"readHDF5Impl(): read from dataset failed.");
2266 DestIterator dend = d + shape[0];
2268 for(; d < dend; ++d, k++)
2275 template <
class DestIterator,
class Shape,
class T,
int N>
2277 readHDF5Impl(DestIterator d, Shape
const & shape,
const hid_t dataset_id,
const hid_t datatype, ArrayVector<T> & buffer,
int & counter,
const int elements,
const int numBandsOfType, MetaInt<N>)
2279 DestIterator dend = d + shape[N];
2280 for(; d < dend; ++d)
2282 readHDF5Impl(d.begin(), shape, dataset_id, datatype, buffer, counter, elements, numBandsOfType, MetaInt<N-1>());
2323 doxygen_overloaded_function(template <...>
void readHDF5)
2326 template<
unsigned int N,
class T>
2327 inline void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, T, UnstridedArrayTag> array)
2329 readHDF5(info, array, detail::getH5DataType<T>(), 1);
2333 template<
unsigned int N,
class T,
int SIZE>
2334 inline void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, TinyVector<T, SIZE>, UnstridedArrayTag> array)
2336 readHDF5(info, array, detail::getH5DataType<T>(), SIZE);
2340 template<
unsigned int N,
class T>
2341 inline void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> array)
2343 readHDF5(info, array, detail::getH5DataType<T>(), 3);
2347 template<
unsigned int N,
class T>
2348 inline void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, FFTWComplex<T>, UnstridedArrayTag> array)
2350 readHDF5(info, array, detail::getH5DataType<T>(), 2);
2354 template<
unsigned int N,
class T>
2355 void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, T, UnstridedArrayTag> array,
const hid_t datatype,
const int numBandsOfType)
2357 int offset = (numBandsOfType > 1);
2360 vigra_precondition(( (N + offset ) == info.numDimensions()),
2361 "readHDF5(): Array dimension disagrees with HDF5ImportInfo.numDimensions().");
2363 typename MultiArrayShape<N>::type shape;
2364 for(
int k=offset; k<info.numDimensions(); ++k) {
2365 shape[k-offset] = info.shapeOfDimension(k);
2368 vigra_precondition(shape == array.shape(),
2369 "readHDF5(): Array shape disagrees with HDF5ImportInfo.");
2372 H5Dread( info.getDatasetHandle(), datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, array.data() );
2376 template<
unsigned int N,
class T>
2377 inline void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, T, StridedArrayTag> array)
2379 readHDF5(info, array, detail::getH5DataType<T>(), 1);
2383 template<
unsigned int N,
class T,
int SIZE>
2384 inline void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, TinyVector<T, SIZE>, StridedArrayTag> array)
2386 readHDF5(info, array, detail::getH5DataType<T>(), SIZE);
2390 template<
unsigned int N,
class T>
2391 inline void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, RGBValue<T>, StridedArrayTag> array)
2393 readHDF5(info, array, detail::getH5DataType<T>(), 3);
2397 template<
unsigned int N,
class T>
2398 void readHDF5(
const HDF5ImportInfo &info, MultiArrayView<N, T, StridedArrayTag> array,
const hid_t datatype,
const int numBandsOfType)
2400 int offset = (numBandsOfType > 1);
2403 vigra_precondition(( (N + offset ) == info.numDimensions()),
2404 "readHDF5(): Array dimension disagrees with HDF5ImportInfo.numDimensions().");
2406 typename MultiArrayShape<N>::type shape;
2407 for(
int k=offset; k<info.numDimensions(); ++k) {
2408 shape[k-offset] = info.shapeOfDimension(k);
2411 vigra_precondition(shape == array.shape(),
2412 "readHDF5(): Array shape disagrees with HDF5ImportInfo.");
2416 int elements = numBandsOfType;
2417 for(
unsigned int i=0;i<N;++i)
2418 elements *= shape[i];
2419 ArrayVector<T> buffer(shape[0]);
2420 detail::readHDF5Impl(array.traverser_begin(), shape, info.getDatasetHandle(), datatype, buffer, counter, elements, numBandsOfType, vigra::MetaInt<N-1>());
2423 inline hid_t openGroup(hid_t parent, std::string group_name)
2426 size_t last_slash = group_name.find_last_of(
'/');
2427 if (last_slash == std::string::npos || last_slash != group_name.size() - 1)
2428 group_name = group_name +
'/';
2429 std::string::size_type begin = 0, end = group_name.find(
'/');
2431 while (end != std::string::npos)
2433 std::string group(group_name.begin()+begin, group_name.begin()+end);
2434 hid_t prev_parent = parent;
2435 parent = H5Gopen(prev_parent, group.c_str(), H5P_DEFAULT);
2437 if(ii != 0) H5Gclose(prev_parent);
2438 if(parent < 0)
return parent;
2441 end = group_name.find(
'/', begin);
2446 inline hid_t createGroup(hid_t parent, std::string group_name)
2448 if(group_name.size() == 0 ||*group_name.rbegin() !=
'/')
2449 group_name = group_name +
'/';
2450 if(group_name ==
"/")
2451 return H5Gopen(parent, group_name.c_str(), H5P_DEFAULT);
2453 std::string::size_type begin = 0, end = group_name.find(
'/');
2455 while (end != std::string::npos)
2457 std::string group(group_name.begin()+begin, group_name.begin()+end);
2458 hid_t prev_parent = parent;
2460 if(H5LTfind_dataset(parent, group.c_str()) == 0)
2462 parent = H5Gcreate(prev_parent, group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
2464 parent = H5Gopen(prev_parent, group.c_str(), H5P_DEFAULT);
2467 if(ii != 0) H5Gclose(prev_parent);
2468 if(parent < 0)
return parent;
2471 end = group_name.find(
'/', begin);
2476 inline void deleteDataset(hid_t parent, std::string dataset_name)
2479 if(H5LTfind_dataset(parent, dataset_name.c_str()))
2482 #if (H5_VERS_MAJOR == 1 && H5_VERS_MINOR <= 6)
2483 if(H5Gunlink(parent, dataset_name.c_str()) < 0)
2485 vigra_postcondition(
false,
"writeToHDF5File(): Unable to delete existing data.");
2488 if(H5Ldelete(parent, dataset_name.c_str(), H5P_DEFAULT ) < 0)
2490 vigra_postcondition(
false,
"createDataset(): Unable to delete existing data.");
2496 inline hid_t createFile(std::string filePath,
bool append_ =
true)
2499 pFile = fopen ( filePath.c_str(),
"r" );
2501 if ( pFile == NULL )
2503 file_id = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
2508 file_id = H5Fopen(filePath.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
2513 std::remove(filePath.c_str());
2514 file_id = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
2519 template<
unsigned int N,
class T,
class Tag>
2520 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)
2522 std::string path_name(pathInFile), group_name, data_set_name, message;
2523 std::string::size_type delimiter = path_name.rfind(
'/');
2526 file_handle = HDF5Handle(createFile(filePath), &H5Fclose,
2527 "createDataset(): unable to open output file.");
2530 if(delimiter == std::string::npos)
2533 data_set_name = path_name;
2537 group_name = std::string(path_name.begin(), path_name.begin()+delimiter);
2538 data_set_name = std::string(path_name.begin()+delimiter+1, path_name.end());
2542 HDF5Handle group(createGroup(file_handle, group_name), &H5Gclose,
2543 "createDataset(): Unable to create and open group. generic v");
2546 deleteDataset(group, data_set_name);
2550 HDF5Handle dataspace_handle;
2551 if(numBandsOfType > 1) {
2553 hsize_t shape_inv[N+1];
2554 for(
unsigned int k=0; k<N; ++k) {
2555 shape_inv[N-1-k] = array.shape(k);
2558 shape_inv[N] = numBandsOfType;
2561 dataspace_handle = HDF5Handle(H5Screate_simple(N+1, shape_inv, NULL),
2562 &H5Sclose,
"createDataset(): unable to create dataspace for non-scalar data.");
2565 hsize_t shape_inv[N];
2566 for(
unsigned int k=0; k<N; ++k)
2567 shape_inv[N-1-k] = array.shape(k);
2570 dataspace_handle = HDF5Handle(H5Screate_simple(N, shape_inv, NULL),
2571 &H5Sclose,
"createDataset(): unable to create dataspace for scalar data.");
2575 dataset_handle = HDF5Handle(H5Dcreate(group,
2576 data_set_name.c_str(),
2579 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT),
2580 &H5Dclose,
"createDataset(): unable to create dataset.");
2587 template <
class DestIterator,
class Shape,
class T>
2589 writeHDF5Impl(DestIterator d, Shape
const & shape,
const hid_t dataset_id,
const hid_t datatype, ArrayVector<T> & buffer,
int & counter,
const int elements,
const int numBandsOfType, MetaInt<0>)
2591 DestIterator dend = d + (
typename DestIterator::difference_type)shape[0];
2594 for(; d < dend; ++d, k++)
2600 HDF5Handle mid1, mid2;
2603 selectHyperslabs(mid1, mid2, shape, counter, elements, numBandsOfType);
2606 H5Dwrite(dataset_id, datatype, mid2, mid1, H5P_DEFAULT, buffer.data());
2611 template <
class DestIterator,
class Shape,
class T,
int N>
2613 writeHDF5Impl(DestIterator d, Shape
const & shape,
const hid_t dataset_id,
const hid_t datatype, ArrayVector<T> & buffer,
int & counter,
const int elements,
const int numBandsOfType, MetaInt<N>)
2615 DestIterator dend = d + (
typename DestIterator::difference_type)shape[N];
2616 for(; d < dend; ++d)
2618 writeHDF5Impl(d.begin(), shape, dataset_id, datatype, buffer, counter, elements, numBandsOfType, MetaInt<N-1>());
2659 doxygen_overloaded_function(template <...>
void writeHDF5)
2662 template<
unsigned int N,
class T>
2663 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, T, UnstridedArrayTag> & array)
2665 writeHDF5(filePath, pathInFile, array, detail::getH5DataType<T>(), 1);
2669 template<
unsigned int N,
class T,
int SIZE>
2670 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, TinyVector<T, SIZE>, UnstridedArrayTag> & array)
2672 writeHDF5(filePath, pathInFile, array, detail::getH5DataType<T>(), SIZE);
2676 template<
unsigned int N,
class T>
2677 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, RGBValue<T>, UnstridedArrayTag> & array)
2679 writeHDF5(filePath, pathInFile, array, detail::getH5DataType<T>(), 3);
2683 template<
unsigned int N,
class T>
2684 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, FFTWComplex<T>, UnstridedArrayTag> & array)
2686 writeHDF5(filePath, pathInFile, array, detail::getH5DataType<T>(), 2);
2690 template<
unsigned int N,
class T>
2691 void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, T, UnstridedArrayTag> & array,
const hid_t datatype,
const int numBandsOfType)
2693 HDF5Handle file_handle;
2694 HDF5Handle dataset_handle;
2695 createDataset(filePath, pathInFile, array, datatype, numBandsOfType, file_handle, dataset_handle);
2698 H5Dwrite( dataset_handle, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, array.data());
2700 H5Fflush(file_handle, H5F_SCOPE_GLOBAL);
2705 template<
unsigned int N,
class T>
2706 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, T, StridedArrayTag> & array)
2708 writeHDF5(filePath, pathInFile, array, detail::getH5DataType<T>(), 1);
2712 template<
unsigned int N,
class T,
int SIZE>
2713 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, TinyVector<T, SIZE>, StridedArrayTag> & array)
2715 writeHDF5(filePath, pathInFile, array, detail::getH5DataType<T>(), SIZE);
2719 template<
unsigned int N,
class T>
2720 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, RGBValue<T>, StridedArrayTag> & array)
2722 writeHDF5(filePath, pathInFile, array, detail::getH5DataType<T>(), 3);
2726 template<
unsigned int N,
class T>
2727 inline void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, FFTWComplex<T>, StridedArrayTag> & array)
2729 writeHDF5(filePath, pathInFile, array, detail::getH5DataType<T>(), 2);
2733 template<
unsigned int N,
class T>
2734 void writeHDF5(
const char* filePath,
const char* pathInFile,
const MultiArrayView<N, T, StridedArrayTag> & array,
const hid_t datatype,
const int numBandsOfType)
2736 HDF5Handle file_handle;
2737 HDF5Handle dataset_handle;
2738 createDataset(filePath, pathInFile, array, datatype, numBandsOfType, file_handle, dataset_handle);
2742 int elements = numBandsOfType;
2743 for(
unsigned int k=0; k<N; ++k)
2745 shape[k] = array.shape(k);
2746 stride[k] = array.stride(k);
2747 elements *= (int)shape[k];
2751 ArrayVector<T> buffer((
int)array.shape(0));
2752 detail::writeHDF5Impl(array.traverser_begin(), shape, dataset_handle, datatype, buffer, counter, elements, numBandsOfType, vigra::MetaInt<N-1>());
2754 H5Fflush(file_handle, H5F_SCOPE_GLOBAL);
2768 void operator()(std::string
const & in)
2770 size = in.size() > size ?
2778 #if (H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 8) || DOXYGEN
2785 template<
size_t N,
class T,
class C>
2790 if(H5Aexists(loc, name) > 0)
2791 H5Adelete(loc, name);
2794 array.
shape().end());
2796 dataspace_handle(H5Screate_simple(N, shape.data(), NULL),
2798 "writeToHDF5File(): unable to create dataspace.");
2802 detail::getH5DataType<T>(),
2804 H5P_DEFAULT ,H5P_DEFAULT ),
2806 "writeHDF5Attr: unable to create Attribute");
2810 for(
int ii = 0; ii < array.
size(); ++ii)
2811 buffer.push_back(array[ii]);
2812 H5Awrite(attr, detail::getH5DataType<T>(), buffer.
data());
2821 template<
size_t N,
class C>
2826 if(H5Aexists(loc, name) > 0)
2827 H5Adelete(loc, name);
2830 array.
shape().end());
2832 dataspace_handle(H5Screate_simple(N, shape.data(), NULL),
2834 "writeToHDF5File(): unable to create dataspace.");
2838 "writeToHDF5File(): unable to create type.");
2840 detail::MaxSizeFnc max_size;
2841 max_size = std::for_each(array.
data(),array.
data()+ array.
size(), max_size);
2842 H5Tset_size (atype, max_size.size);
2848 H5P_DEFAULT ,H5P_DEFAULT ),
2850 "writeHDF5Attr: unable to create Attribute");
2852 std::string buf =
"";
2853 for(
int ii = 0; ii < array.
size(); ++ii)
2855 buf = buf + array[ii]
2856 + std::string(max_size.size - array[ii].
size(),
' ');
2858 H5Awrite(attr, atype, buf.c_str());
2886 std::string pathInFile,
2889 std::string path_name(pathInFile), group_name, data_set_name, message, attr_name;
2890 std::string::size_type delimiter = path_name.rfind(
'/');
2893 HDF5Handle file_id(createFile(filePath), &H5Fclose,
2894 "writeToHDF5File(): unable to open output file.");
2897 if(delimiter == std::string::npos)
2900 data_set_name = path_name;
2905 group_name = std::string(path_name.begin(), path_name.begin()+delimiter);
2906 data_set_name = std::string(path_name.begin()+delimiter+1, path_name.end());
2908 delimiter = data_set_name.rfind(
'.');
2909 if(delimiter == std::string::npos)
2911 attr_name = path_name;
2912 data_set_name =
"/";
2916 attr_name = std::string(data_set_name.begin()+delimiter+1, data_set_name.end());
2917 data_set_name = std::string(data_set_name.begin(), data_set_name.begin()+delimiter);
2920 HDF5Handle group(openGroup(file_id, group_name), &H5Gclose,
2921 "writeToHDF5File(): Unable to create and open group. attr ver");
2923 if(data_set_name !=
"/")
2925 HDF5Handle dset(H5Dopen(group, data_set_name.c_str(), H5P_DEFAULT), &H5Dclose,
2926 "writeHDF5Attr():unable to open dataset");
2941 #endif // VIGRA_HDF5IMPEX_HXX
HDF5Handle()
Default constructor. Creates a NULL handle.
Definition: hdf5impex.hxx:130
void write(const std::string &datasetName, const ArrayVectorView< T > &array, int compression=0)
Write array vectors.
Definition: hdf5impex.hxx:1149
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:689
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:1465
bool operator==(HDF5Handle const &h) const
Equality comparison of the contained handle.
Definition: hdf5impex.hxx:230
HDF5File(std::string filename, OpenMode mode, int track_creation_times=0)
Open or create an HDF5File object.
Definition: hdf5impex.hxx:590
Wrapper for hid_t objects.
Definition: hdf5impex.hxx:116
HDF5Handle getDatasetHandle(std::string dataset_name)
Obtain the HDF5 handle of a dataset.
Definition: hdf5impex.hxx:847
void readBlock(std::string datasetName, typename MultiArrayShape< N >::type blockOffset, typename MultiArrayShape< N >::type blockShape, MultiArrayView< N, T, UnstridedArrayTag > &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:1327
MultiArrayIndex numDimensions() const
void write(std::string datasetName, const MultiArrayView< N, T, UnstridedArrayTag > &array, int iChunkSize=0, int compression=0)
Write multi arrays.
Definition: hdf5impex.hxx:1049
const difference_type & shape() const
Definition: multi_array.hxx:1602
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:724
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:792
const_iterator begin() const
Definition: array_vector.hxx:223
void write(std::string datasetName, const MultiArrayView< N, T, UnstridedArrayTag > &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:1079
pointer data() const
Definition: multi_array.hxx:1829
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:154
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:1592
Main MultiArray class containing the memory management.
Definition: multi_array.hxx:595
void reshape(const difference_type &shape)
Definition: multi_array.hxx:2756
iterator end()
Definition: tinyvector.hxx:727
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:710
void readAndResize(std::string datasetName, MultiArray< N, T > &array)
Read data into a MultiArray. Resize MultiArray to the correct size. If the first character of dataset...
Definition: hdf5impex.hxx:1250
bool existsAttribute(std::string object_name, std::string attribute_name)
Test if attribute exists.
Definition: hdf5impex.hxx:949
const std::string & getFilePath() const
std::ptrdiff_t MultiArrayIndex
Definition: multi_iterator.hxx:348
void writeHDF5Attr(hid_t loc, const char *name, MultiArrayView< N, T, C > const &array)
Definition: hdf5impex.hxx:2786
bool operator==(hid_t h) const
Equality comparison of the contained handle.
Definition: hdf5impex.hxx:237
const std::string & getPathInFile() const
void writeBlock(std::string datasetName, typename MultiArrayShape< N >::type blockOffset, const MultiArrayView< N, T, UnstridedArrayTag > &array)
Write a multi array into a larger volume. blockOffset determines the position, where array is written...
Definition: hdf5impex.hxx:1107
void ls(Container &cont) const
List the contents of the current group into a container-like object via insert(). ...
Definition: hdf5impex.hxx:768
Argument object for the function readHDF5().
Definition: hdf5impex.hxx:273
bool operator!=(hid_t h) const
Inequality comparison of the contained handle.
Definition: hdf5impex.hxx:251
bool operator!=(HDF5Handle const &h) const
Inequality comparison of the contained handle.
Definition: hdf5impex.hxx:244
difference_type_1 size() const
Definition: multi_array.hxx:1595
std::string filename() const
Get the name of the associated file.
Definition: hdf5impex.hxx:783
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:176
~HDF5File()
The destructor flushes and closes the file.
Definition: hdf5impex.hxx:598
iterator begin()
Definition: tinyvector.hxx:724
size_type size() const
Definition: tinyvector.hxx:739
HDF5Handle getGroupHandle(std::string group_name)
Obtain the HDF5 handle of a group.
Definition: hdf5impex.hxx:855
void readHDF5(...)
Read the data specified by the given vigra::HDF5ImportInfo object and write the into the given 'array...
void writeAttribute(std::string object_name, std::string attribute_name, const MultiArrayView< N, T, UnstridedArrayTag > &array)
Write MultiArray Attributes. In contrast to datasets, subarray access, chunks and compression are not...
Definition: hdf5impex.hxx:885
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:1289
~HDF5Handle()
Destructor. Calls close() for the contained handle.
Definition: hdf5impex.hxx:191
void read(std::string datasetName, char &data)
Read a single value. Specialization of the read function for simple datatypes.
Definition: hdf5impex.hxx:1424
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:617
PixelType pixelType() const
OpenMode
Set how a file is opened.
Definition: hdf5impex.hxx:565
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:995
void flushToDisk()
Immediately write all data to disk.
Definition: hdf5impex.hxx:1545
HDF5Handle(HDF5Handle const &h)
Copy constructor. Hands over ownership of the RHS handle (analogous to VIGRA_UNIQUE_PTR).
Definition: hdf5impex.hxx:165
Definition: metaprogramming.hxx:117
Class for fixed size vectors.This class contains an array of size SIZE of the specified VALUETYPE...
Definition: accessor.hxx:939
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:872
std::string pwd() const
Get the path of the current group.
Definition: hdf5impex.hxx:776
void write(std::string datasetName, char data)
Write a single value. Specialization of the write function for simple datatypes.
Definition: hdf5impex.hxx:1203
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:914
herr_t close()
Explicitly call the stored function (if one has been stored within this object) for the contained han...
Definition: hdf5impex.hxx:199
image import and export functions
void close()
Close the current file.
Definition: hdf5impex.hxx:628
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:667
ArrayVector< hsize_t > getDatasetShape(std::string datasetName)
Get the shape of each dimension of a certain dataset.
Definition: hdf5impex.hxx:821
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:322
size_type size() const
Definition: array_vector.hxx:330
hid_t getDatasetHandle() const
HDF5File(int track_creation_times=0)
Default constructor.
Definition: hdf5impex.hxx:578
hid_t getH5FileHandle() const
void read(std::string datasetName, MultiArrayView< N, T, UnstridedArrayTag > &array)
Read data into a multi array. If the first character of datasetName is a "/", the path will be interp...
Definition: hdf5impex.hxx:1232
void root()
Change current group to "/".
Definition: hdf5impex.hxx:636
void cd(std::string groupName)
Change the current group. Both absolute and relative group names are allowed.
Definition: hdf5impex.hxx:645
Access to HDF5 files.
Definition: hdf5impex.hxx:513
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:1276
void readAttribute(std::string object_name, std::string attribute_name, const MultiArrayView< N, T, UnstridedArrayTag > &array)
Read MultiArray Attributes. In contrast to datasets, subarray access is not available.
Definition: hdf5impex.hxx:966
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:746