HDF5Reader Class Reference
#include <hdf5reader.h>
List of all members.
Detailed Description
HDF5Reader
Definition at line 13 of file hdf5reader.h.
Constructor & Destructor Documentation
HDF5Reader::HDF5Reader |
( |
|
) |
|
HDF5Reader::~HDF5Reader |
( |
|
) |
|
Member Function Documentation
void HDF5Reader::close |
( |
|
) |
|
void HDF5Reader::closeId |
( |
hid_t |
id |
) |
[protected] |
Definition at line 159 of file hdf5reader.cpp.
00160 {
00161 switch(H5Iget_type(id))
00162 {
00163 case H5I_ATTR:
00164 H5Aclose(id);
00165 break;
00166 case H5I_GROUP:
00167 H5Gclose(id);
00168 break;
00169 case H5I_DATASET:
00170 H5Dclose(id);
00171 break;
00172 default:
00173 throw new Exception("HDF5Read::openId Data type not recognized");
00174 }
00175
00176 }
std::string HDF5Reader::getAttribute |
( |
std::string |
datasetName, |
|
|
std::string |
attributeName | |
|
) |
| | |
VecIndex HDF5Reader::getDataSetDim |
( |
std::string |
path |
) |
|
Definition at line 218 of file hdf5reader.cpp.
00219 {
00220 if (m_file == -1)
00221 throw new Exception("HDF5Reader::getDataSetDim: Open the file first");
00222 VecIndex resp;
00223 int rank;
00224 H5LTget_dataset_ndims(m_file,path.c_str(),&rank);
00225 resp.resize(rank);
00226
00227 hsize_t dims[rank];
00228 H5T_class_t class_id;
00229 size_t type_size;
00230 H5LTget_dataset_info(m_file,path.c_str(),dims,&class_id,&type_size);
00231
00232 for (int i=0;i<rank;i++)
00233 resp[i]=(Index) dims[i];
00234 return resp;
00235 }
std::string HDF5Reader::getDataSetTriangulation |
( |
std::string |
dataset |
) |
|
Definition at line 17 of file hdf5reader.cpp.
00018 {
00019 char strTria[1000];
00020 if (H5LTget_attribute_string(m_file, datasetName.c_str(), "Triangulation", strTria) < 0)
00021 throw new Exception("Dataset %s not found\n", datasetName.c_str());
00022 else
00023 return strTria;
00024 }
std::vector< std::string > HDF5Reader::getFieldList |
( |
|
) |
|
Definition at line 49 of file hdf5reader.cpp.
00050 {
00051 std::vector<std::string> stringList;
00052
00053 hid_t group_id = H5Gopen1(m_file,"/DataSets");
00054
00055
00056 H5G_info_t group_info;
00057 H5Gget_info( group_id, &group_info );
00058
00059 char name[1000];
00060 for (hsize_t i=0;i<group_info.nlinks;i++)
00061 {
00062 H5Lget_name_by_idx(group_id,".",H5_INDEX_NAME,H5_ITER_INC,i,name,1000,H5P_DEFAULT);
00063 stringList.push_back(name);
00064 }
00065 return stringList;
00066 }
std::string HDF5Reader::getFileName |
( |
|
) |
[inline] |
std::vector< std::string > HDF5Reader::getMeshList |
( |
|
) |
|
Definition at line 27 of file hdf5reader.cpp.
00028 {
00029 std::vector<std::string> stringList;
00030
00031 hid_t group_id = H5Gopen1(m_file,"/Triangulations");
00032
00033
00034 H5G_info_t group_info;
00035 H5Gget_info( group_id, &group_info );
00036
00037 char name[1000];
00038 for (hsize_t i=0;i<group_info.nlinks;i++)
00039 {
00040 H5Lget_name_by_idx(group_id,".",H5_INDEX_NAME,H5_ITER_INC,i,name,1000,H5P_DEFAULT);
00041 stringList.push_back(name);
00042 }
00043 return stringList;
00044 }
std::vector< std::string > HDF5Reader::ls |
( |
std::string |
path |
) |
|
Definition at line 69 of file hdf5reader.cpp.
00070 {
00071 std::vector<std::string> stringList;
00072
00073 hid_t group_id = H5Gopen1(m_file,path.c_str());
00074
00075
00076 H5G_info_t group_info;
00077 H5Gget_info( group_id, &group_info );
00078
00079 char name[1000];
00080 for (hsize_t i=0;i<group_info.nlinks;i++)
00081 {
00082 H5Lget_name_by_idx(group_id,".",H5_INDEX_NAME,H5_ITER_INC,i,name,1000,H5P_DEFAULT);
00083 stringList.push_back(name);
00084 }
00085 return stringList;
00086
00087 }
void HDF5Reader::open |
( |
std::string |
strFileName |
) |
|
Definition at line 95 of file hdf5reader.cpp.
00096 {
00097 close();
00098 _fileName=strFileName;
00099 m_file = H5Fopen(strFileName.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
00100 if (m_file < 0)
00101 throw new Exception("File name \"%s\" not found",strFileName.c_str());
00102 }
hid_t HDF5Reader::openGroup |
( |
std::string |
groupName |
) |
[protected] |
Definition at line 123 of file hdf5reader.cpp.
00124 {
00125 hid_t grp = H5Gopen1(m_file,groupName.c_str());
00126 if (grp <= 0)
00127 throw new Exception("HDF5OrthoReader::openGroup Fail to open group %s",groupName.c_str());
00128 return grp;
00129 }
hid_t HDF5Reader::openId |
( |
hid_t |
rootId, |
|
|
std::string |
path, |
|
|
hsize_t |
type | |
|
) |
| | [protected] |
Definition at line 132 of file hdf5reader.cpp.
00133 {
00134 hid_t result;
00135 switch(type)
00136 {
00137 case H5I_ATTR:
00138 result= H5Aopen(rootId,path.c_str(),H5P_DEFAULT);
00139 break;
00140 case H5I_GROUP:
00141 result= H5Gopen1(rootId,path.c_str());
00142 break;
00143 case H5I_DATASET:
00144 result= H5Dopen1(rootId,path.c_str());
00145 break;
00146 case H5I_BADID:
00147 throw new Exception("HDF5OrthoRead::openId Invalid object at \"%s\" not recognized",path.c_str());
00148 default:
00149 throw new Exception("HDF5OrthoRead::openId Data type \"%s %d\" in path \"%s\" not recognized",printType(type).c_str(),type,path.c_str());
00150 result=-1;
00151 }
00152 if (result <= 0)
00153 throw new Exception("HDF5OrthoRead::openId Can't open %s",path.c_str());
00154 return result;
00155
00156 }
std::string HDF5Reader::printType |
( |
hsize_t |
type |
) |
[protected] |
Definition at line 156 of file hdf5orthoreader.cpp.
00157 {
00158 switch(type)
00159 {
00160 case H5I_ATTR:
00161 return "ATTRIBUTE";
00162 break;
00163 case H5I_GROUP:
00164 return "GROUP";
00165 break;
00166 case H5I_DATASET:
00167 return "DATASET";
00168 break;
00169 case H5I_FILE:
00170 return "FILE";
00171 break;
00172 case H5I_DATASPACE:
00173 return "DATASPACE";
00174 break;
00175 case H5I_DATATYPE:
00176 return "DATATYPE";
00177 break;
00178 }
00179 return "UNKNOWN";
00180 }
std::string HDF5Reader::readAtt |
( |
std::string |
strPath, |
|
|
std::string |
attName, |
|
|
bool |
mustexist = true | |
|
) |
| | |
Read an attribute
- Parameters:
-
| strPath | The path to the link |
| attName | The name of the attribute |
| mustexist | If 1 throws an Exception if the attribute does not exist. If 0 just return an empty string |
- Returns:
Definition at line 186 of file hdf5reader.cpp.
00187 {
00188
00189 if (m_file == -1)
00190 {
00191 throw new Exception("HDF5Reader::readAtt error, open the file first.");
00192 }
00193
00194 hid_t att = H5Aopen_by_name(m_file,strPath.c_str(), attName.c_str(),H5P_DEFAULT,H5P_DEFAULT);
00195 if (att < 0 && mustexist)
00196 throw new Exception("Attribute %s/%s not found",strPath.c_str(),attName.c_str());
00197 if (att<0 && !mustexist)
00198 return std::string();
00199
00200
00201 hid_t datatype = H5Aget_type(att);
00202 if (H5Tget_class(datatype) != H5T_STRING)
00203 throw new Exception("Attribute %s/%s expected to be a string",strPath.c_str(),attName.c_str());
00204
00205 size_t size=H5Tget_size(datatype);
00206 char value[size];
00207 H5Aclose(att);
00208 H5Tclose(datatype);
00209
00210 hid_t error=H5LTget_attribute_string(m_file,strPath.c_str(),attName.c_str(),value);
00211 if (error>=0)
00212 return value;
00213 else
00214 return "";
00215 }
Member Data Documentation
The documentation for this class was generated from the following files: