Xmipp  v3.23.11-Nereus
Public Member Functions | List of all members

#include <xmipp_hdf5.h>

Inheritance diagram for XmippH5File:
Inheritance graph
[legend]
Collaboration diagram for XmippH5File:
Collaboration graph
[legend]

Public Member Functions

void showTree (std::ostream &out=std::cout)
 
void openFile (const H5std_string &name, unsigned int flags, const H5::FileAccPropList &access_plist=H5::FileAccPropList::DEFAULT)
 
int getDataset (const char *dsname, Matrix1D< double > &data, bool reportError=true) const
 
bool checkDataset (const char *dsname) const
 

Detailed Description

Definition at line 69 of file xmipp_hdf5.h.

Member Function Documentation

◆ checkDataset()

bool XmippH5File::checkDataset ( const char *  dsname) const

Return true if the dataset dsname exists in the file

Parameters
dsnameDataset name to check
Returns
true if dataset exists, false otherwise.

Definition at line 121 of file xmipp_hdf5.cpp.

122 {
123  H5::DataSet dataset;
124  // Open the dataset
125  try
126  {
127  dataset = openDataSet(dsname);
128  }
129  catch (H5::Exception &h5e)
130  {
131  return false;
132  }
133  dataset.close();
134  return true;
135 }

◆ getDataset()

int XmippH5File::getDataset ( const char *  dsname,
Matrix1D< double > &  data,
bool  reportError = true 
) const

Return the values in the dataset dsname and return them in a Matrix1D double data

Parameters
dsnameDataset name
dataVector data
reportErrorIf true throw an exception in case of failure, otherwise it returns a negative number

Definition at line 137 of file xmipp_hdf5.cpp.

138 {
139  H5::DataSet dataset;
140  // Open the dataset
141  try
142  {
143  dataset = openDataSet(dsname);
144  }
145  catch (H5::Exception &h5e)
146  {
147  if ( reportError )
148  REPORT_ERROR(ERR_ARG_MISSING,formatString("getDataset: %s dataset " \
149  "does not exist in file %s.", dsname, this->getFileName().c_str()));
150  // std::cerr << "getDataset Error: " << h5e.getCDetailMsg() << std::endl;
151  return -1;
152  }
153 
154  //Get dataspace of the dataset.
155  H5::DataSpace filespace = dataset.getSpace();
156 
157  // Check the number of dimensions in the dataspace is one.
158  if (filespace.getSimpleExtentNdims()!= 1 )
159  REPORT_ERROR(ERR_ARG_INCORRECT, formatString("getDataset: Dataset %s has "\
160  "more than 1 dimension", dsname));
161 
162  // Get the size of the dimension in the dataspace
163  hsize_t dim[1];
164  filespace.getSimpleExtentDims(dim);
165 
166 
167  hsize_t offset[1]; // Hyperslab offset in the file
168  // hsize_t count[1]; // Size of the hyperslab in the file
169 
170  // Define the offset and count of the hyperslab to be read.
171  offset[0] = 0;
172  // count[0] = dim[0];
173 
174  filespace.selectHyperslab( H5S_SELECT_SET, dim, offset );
175 
176  // Allocate space for data and define the memspace
177  data.resizeNoCopy((int)*dim);
178 
179  H5::DataSpace memspace(1, dim);
180 
181  // Read data from hyperslab in the file into the hyperslab in memory
182  dataset.read(MATRIX1D_ARRAY(data), H5::PredType::NATIVE_DOUBLE, memspace, filespace);
183 
184  filespace.close();
185  memspace.close();
186  dataset.close();
187 
188  return 0;
189 }
Argument missing.
Definition: xmipp_error.h:114
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect argument received.
Definition: xmipp_error.h:113
#define MATRIX1D_ARRAY(v)
Definition: matrix1d.h:58
String formatString(const char *format,...)
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458

◆ openFile()

void XmippH5File::openFile ( const H5std_string &  name,
unsigned int  flags,
const H5::FileAccPropList &  access_plist = H5::FileAccPropList::DEFAULT 
)

Open HDF5 file

Parameters
nameFile name
flagstandard hdf5 flags
access_plistStandard hdf5 plist

Definition at line 112 of file xmipp_hdf5.cpp.

114 {
115  if ( isHdf5(name.c_str()) )
116  H5::H5File::openFile(name.c_str(), flags, access_plist);
117  else
118  REPORT_ERROR(ERR_IMG_UNKNOWN, formatString("XmippH5File: Format of %s is not HDF5.",name.c_str()));
119 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Unknown image type.
Definition: xmipp_error.h:130
String formatString(const char *format,...)

◆ showTree()

void XmippH5File::showTree ( std::ostream &  out = std::cout)

Show the groups and dataset and print them in the output stream out.

Parameters
outOutput stream

Definition at line 191 of file xmipp_hdf5.cpp.

192 {
193  H5TreeInfo h5Info;
194 
195  h5Info.out = &out;
196  h5Info.rootname = "";
197 
198  this->iterateElems("/", NULL, showObjectInfo, &h5Info);
199 }
std::string rootname
Definition: xmipp_hdf5.cpp:32
std::ostream * out
Definition: xmipp_hdf5.cpp:33
herr_t showObjectInfo(hid_t objId, const char *name, void *op_data)
Definition: xmipp_hdf5.cpp:36

The documentation for this class was generated from the following files: