hdf_file.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2020, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef O2SCL_HDF_FILE_H
24 #define O2SCL_HDF_FILE_H
25 
26 /** \file hdf_file.h
27  \brief File defining \ref o2scl_hdf::hdf_file
28 */
29 #include <limits>
30 
31 #ifdef O2SCL_PLAIN_HDF5_HEADER
32 #include <hdf5.h>
33 #else
34 #ifdef O2SCL_LINUX
35 #include <hdf5/serial/hdf5.h>
36 #else
37 #include <hdf5.h>
38 #endif
39 #endif
40 
41 #include <boost/numeric/ublas/vector.hpp>
42 #include <boost/numeric/ublas/matrix.hpp>
43 
44 #include <o2scl/vector.h>
45 #include <o2scl/tensor.h>
46 #include <o2scl/format_float.h>
47 
48 /** \brief The \o2 namespace for I/O with HDF
49  */
50 namespace o2scl_hdf {
51 
52  /** \brief Store data in an \o2 compatible HDF5 file
53 
54  See also the \ref hdf_section section of the \o2
55  User's guide.
56 
57  The member functions which write or get data from an HDF file
58  begin with either <tt>get</tt> or <tt>set</tt>. Where
59  appropriate, the next character is either \c c for character, \c
60  d for double, \c f for float, or \c i for int.
61 
62  By default, vectors and matrices are written to HDF files in a
63  chunked format, so their length can be changed later as
64  necessary. The chunk size is chosen in \ref def_chunk() to be
65  the closest power of 10 to the current vector size.
66 
67  All files not closed by the user are closed in the destructor,
68  but the destructor does not automatically close groups.
69 
70  \note Currently, HDF I/O functions write data to HDF files
71  assuming that \c int and \c float have 4 bytes, while \c size_t
72  and \c double are 8 bytes. All output is done in little endian
73  format. While <tt>get</tt> functions can read data with
74  different sizes or in big endian format, the <tt>set</tt>
75  functions cannot currently write data this way.
76 
77  \note It does make sense to write a zero-length vector to an HDF
78  file if the vector does not have a fixed size in order to create
79  a placeholder for future output. Thus the <tt>set_vec()</tt> and
80  allow zero-length vectors and the <tt>set_arr()</tt> functions
81  allow the <tt>size_t</tt> parameter to be zero, in which case
82  the pointer parameter is ignored. The <tt>set_vec_fixed()</tt>
83  and <tt>set_arr_fixed()</tt> functions do not allow this, and
84  will throw an exception if sent a zero-length vector.
85 
86  \warning This class is still in development. Because of this,
87  hdf5 files generated by this class may not be easily read by
88  future versions. Later versions of \o2 may have stronger
89  guarantees on backwards compatibility.
90 
91  \future This class opens all files in R/W mode, which may
92  cause I/O problems in file systems. This needs to be
93  fixed by allowing the user to open a read-only file.
94  (AWS: 3/16/18 I think this is fixed now.)
95  \future The \o2 HDF functions do not always consistently choose
96  between throwing \o2 exceptions and throwing HDF5 exceptions.
97  Check and/or fix this.
98  \future Automatically close groups, e.g. by storing hid_t's in a
99  stack?
100  \future Rewrite the _arr_alloc() functions so that they
101  return a shared_ptr?
102  \future Move the code from the 'filelist' acol command here
103  into hdf_file.
104  */
105  class hdf_file {
106 
107  public:
108 
113 
114 #ifndef DOXYGEN_INTERNAL
115 
116  protected:
117 
118  /// File ID
119  hid_t file;
120 
121  /// True if a file has been opened
122  bool file_open;
123 
124  /// Current file or group location
125  hid_t current;
126 
127  /** \brief Default chunk size
128 
129  Choose the closest power of 10 which is greater than or equal
130  to 10 and less than or equal to \f$ 10^6 \f$.
131  */
132  virtual hsize_t def_chunk(size_t n) {
133  size_t ch=(size_t)((1.0+1.0e-12)*
134  pow(10.0,floor(log10(((double)n))+0.5)));
135  if (ch<10) ch=10;
136  if (ch>1000000) ch=1000000;
137  return ch;
138  }
139 
140  /// If true, then the file has read and write access
142 
143 #endif
144 
145  public:
146 
147  hdf_file();
148 
149  virtual ~hdf_file();
150 
151  /// If true, then the file has read and write access
153  return write_access;
154  }
155 
156  /// Compression type (support experimental)
158 
159  /// Minimum size to compress by default
161 
162  /// \name Open and close files
163  //@{
164  /** \brief Open a file named \c fname
165 
166  If \c err_on_fail is \c true, this calls the error handler if
167  opening the file fails (e.g. because the file does not exist).
168  If \c err_on_fail is \c false and opening the file fails,
169  nothing is done and the function returns the value \ref
170  o2scl::exc_efilenotfound. If the open succeeds, this function
171  returns \ref o2scl::success.
172  */
173  int open(std::string fname, bool write_access=false,
174  bool err_on_fail=true);
175 
176  /// Open a file named \c fname or create if it doesn't already exist
177  void open_or_create(std::string fname);
178 
179  /// Close the file
180  void close();
181  //@}
182 
183  /// \name Manipulate ids
184  //@{
185  /// Get the current file id
186  hid_t get_file_id();
187 
188  /// Set the current working id
189  void set_current_id(hid_t cur);
190 
191  /// Retrieve the current working id
192  hid_t get_current_id();
193  //@}
194 
195  /** \name Simple get functions
196 
197  If the specified object is not found, the \o2 error handler
198  will be called.
199  */
200  //@{
201  /// Get a character named \c name
202  int getc(std::string name, char &c);
203 
204  /// Get a double named \c name
205  int getd(std::string name, double &d);
206 
207  /// Get a float named \c name
208  int getf(std::string name, float &f);
209 
210  /// Get a integer named \c name
211  int geti(std::string name, int &i);
212 
213  /// Get an unsigned integer named \c name
214  int get_szt(std::string name, size_t &u);
215 
216  /** \brief Get a string named \c name
217 
218  \note Strings are stored as character arrays and thus
219  retrieving a string from a file requires loading the
220  information from the file into a character array, and then
221  copying it to the string. This will be slow for very long
222  strings.
223  */
224  int gets(std::string name, std::string &s);
225 
226  /** \brief Get a variable length string named \c name
227  */
228  int gets_var(std::string name, std::string &s);
229 
230  /** \brief Get a fixed-length string named \c name
231  */
232  int gets_fixed(std::string name, std::string &s);
233 
234  /** \brief Get a fixed-length string named \c name with default
235  value \c s
236  */
237  int gets_def_fixed(std::string name, std::string def, std::string &s);
238  //@}
239 
240  /// \name Simple set functions
241  //@{
242  /// Set a character named \c name to value \c c
243  void setc(std::string name, char c);
244 
245  /// Set a double named \c name to value \c d
246  void setd(std::string name, double d);
247 
248  /// Set a float named \c name to value \c f
249  void setf(std::string name, float f);
250 
251  /// Set an integer named \c name to value \c i
252  void seti(std::string name, int i);
253 
254  /// Set an unsigned integer named \c name to value \c u
255  void set_szt(std::string name, size_t u);
256 
257  /** \brief Set a string named \c name to value \c s
258 
259  The string is stored in the HDF file as an extensible
260  character array rather than a string.
261  */
262  void sets(std::string name, std::string s);
263 
264  /** \brief Set a fixed-length string named \c name to value \c s
265 
266  This function stores <tt>s</tt> as a fixed-length string
267  in the HDF file. If a dataset named \c name is already
268  present, then \c s must not be longer than the string
269  length already specified in the HDF file.
270  */
271  void sets_fixed(std::string name, std::string s);
272  //@}
273 
274  /// \name Group manipulation
275  //@{
276  /** \brief Open a group relative to the location specified in
277  \c init_id
278 
279  \note In order to ensure that future objects are written to the
280  newly-created group, the user must use set_current_id()
281  using the newly-created group ID for the argument.
282  */
283  hid_t open_group(hid_t init_id, std::string path);
284 
285  /** \brief Open a group relative to the current location
286 
287  \note In order to ensure that future objects are written to the
288  newly-created group, the user must use set_current_id()
289  using the newly-created group ID for the argument.
290  */
291  hid_t open_group(std::string path);
292 
293  /// Close a previously created group
294  int close_group(hid_t group) {
295  return H5Gclose(group);
296  }
297  //@}
298 
299  /** \name Vector get functions
300 
301  These functions automatically free any previously allocated
302  memory in <tt>v</tt> and then allocate the proper space
303  required to read the information from the HDF file.
304  */
305  //@{
306  /// Get vector dataset and place data in \c v
307  int getd_vec(std::string name, std::vector<double> &v);
308 
309  /** \brief Get vector dataset and place data in \c v
310 
311  This works with any vector class which has a
312  <tt>resize()</tt> method.
313 
314  \future This currently requires a copy, but there may
315  be a way to write a new version which does not.
316  \comment
317  AWS 12/10/13: I don't think the ublas library guarantees
318  that the vector occupies a continuous chunk of memory
319  like std::vector<> now does.
320  \endcomment
321  */
322  template<class vec_t>
323  int getd_vec_copy(std::string name, vec_t &v) {
324  std::vector<double> v2;
325  int ret=getd_vec(name,v2);
326  v.resize(v2.size());
327  o2scl::vector_copy(v2.size(),v2,v);
328  return ret;
329  }
330 
331  /// Get vector dataset and place data in \c v
332  int geti_vec(std::string name, std::vector<int> &v);
333  /** \brief Get vector dataset and place data in \c v
334 
335  \future This currently requires a copy, but there may
336  be a way to write a new version which does not.
337  */
338  template<class vec_int_t>
339  int geti_vec_copy(std::string name, vec_int_t &v) {
340  std::vector<int> v2;
341  int ret=geti_vec(name,v2);
342  v.resize(v2.size());
343  for(size_t i=0;i<v2.size();i++) v[i]=v2[i];
344  return ret;
345  }
346  /// Get vector dataset and place data in \c v
347  int get_szt_vec(std::string name, std::vector<size_t> &v);
348  /** \brief Get vector dataset and place data in \c v
349 
350  \future This currently requires a copy, but there may
351  be a way to write a new version which does not.
352  */
353  template<class vec_size_t>
354  int get_szt_vec_copy(std::string name, vec_size_t &v) {
355  std::vector<int> v2;
356  int ret=geti_vec(name,v2);
357  v.resize(v2.size());
358  for(size_t i=0;i<v2.size();i++) v[i]=v2[i];
359  return ret;
360  }
361  /** \brief Get a vector of strings named \c name and store it in \c s
362  */
363  int gets_vec(std::string name, std::vector<std::string> &s);
364  //@}
365 
366  /** \name Vector set functions
367 
368  These functions automatically write all of the vector elements
369  to the HDF file, if necessary extending the data that is
370  already present.
371  */
372  //@{
373  /// Set vector dataset named \c name with \c v
374  int setd_vec(std::string name, const std::vector<double> &v);
375 
376  /** \brief Set vector dataset named \c name with \c v
377 
378  This requires a copy before the vector is written to
379  the file.
380  */
381  template<class vec_t>
382  int setd_vec_copy(std::string name, const vec_t &v) {
383  if (v.size()==0) {
384  return setd_arr(name,0,0);
385  }
386 
387  // We have to copy to an std::vector first
388  std::vector<double> v2(v.size());
389  o2scl::vector_copy(v.size(),v,v2);
390 
391  return setd_arr(name,v2.size(),&v2[0]);
392  }
393 
394  /// Set vector dataset named \c name with \c v
395  int seti_vec(std::string name, const std::vector<int> &v);
396  /** \brief Set vector dataset named \c name with \c v
397 
398  This requires a copy before the vector is written to
399  the file.
400  */
401  template<class vec_int_t>
402  int seti_vec_copy(std::string name, vec_int_t &v) {
403  if (v.size()==0) {
404  return seti_arr(name,0,0);
405  }
406 
407  // We have to copy to an std::vector first
408  std::vector<int> v2(v.size());
409  vector_copy(v.size(),v,v2);
410 
411  return seti_arr(name,v2.size(),&v2[0]);
412  }
413  /// Set vector dataset named \c name with \c v
414  int set_szt_vec(std::string name, const std::vector<size_t> &v);
415  /** \brief Set vector dataset named \c name with \c v
416 
417  This requires a copy before the vector is written to
418  the file.
419  */
420  template<class vec_size_t>
421  int set_szt_vec_copy(std::string name, const vec_size_t &v) {
422  if (v.size()==0) {
423  return set_szt_arr(name,0,0);
424  }
425 
426  // We have to copy to an std::vector first
427  std::vector<size_t> v2(v.size());
428  vector_copy(v.size(),v,v2);
429 
430  return set_szt_arr(name,v2.size(),&v2[0]);
431  }
432 
433  /** \brief Set a vector of strings named \c name
434 
435  \devnote
436  String vectors are reformatted as a single character array, in
437  order to allow each string to have different length and to
438  make each string extensible. The size of the vector \c s is
439  stored as an integer named <tt>nw</tt>.
440  */
441  int sets_vec(std::string name, const std::vector<std::string> &s);
442  //@}
443 
444  /** \name Matrix get functions
445 
446  These functions automatically free any previously allocated
447  memory in <tt>m</tt> and then allocate the proper space
448  required to read the information from the HDF file.
449  */
450  //@{
451  /// Get matrix dataset and place data in \c m
452  int getd_mat_copy(std::string name, ubmatrix &m);
453  /// Get matrix dataset and place data in \c m
454  int geti_mat_copy(std::string name, ubmatrix_int &m);
455  //@}
456 
457  /** \name Matrix set functions
458 
459  These functions automatically write all of the vector elements
460  to the HDF file, if necessary extending the data that is
461  already present.
462  */
463  //@{
464  /** \brief Set matrix dataset named \c name with \c m
465  */
466  int setd_mat_copy(std::string name, const ubmatrix &m);
467 
468  /** \brief Set matrix dataset named \c name with \c m
469  */
470  int seti_mat_copy(std::string name, const ubmatrix_int &m);
471 
472  /** \brief Set a two-dimensional array dataset named \c name with \c m
473  */
474  template<class arr2d_t>
475  int setd_arr2d_copy(std::string name, size_t r,
476  size_t c, const arr2d_t &a2d) {
477 
478  if (write_access==false) {
479  O2SCL_ERR2("File not opened with write access ",
480  "in hdf_file::setd_arr2d_copy().",o2scl::exc_efailed);
481  }
482 
483  // Copy to a C-style array
484  double *d=new double[r*c];
485  for(size_t i=0;i<r;i++) {
486  for(size_t j=0;j<c;j++) {
487  d[i*c+j]=a2d[i][j];
488  }
489  }
490 
491  hid_t dset, space, dcpl=0;
492  bool chunk_alloc=false;
493 
494  H5E_BEGIN_TRY
495  {
496  // See if the dataspace already exists first
497  dset=H5Dopen(current,name.c_str(),H5P_DEFAULT);
498  }
499  H5E_END_TRY
500 #ifdef O2SCL_NEVER_DEFINED
501  {
502  }
503 #endif
504 
505  // If it doesn't exist, create it
506  if (dset<0) {
507 
508  // Create the dataspace
509  hsize_t dims[2]={r,c};
510  hsize_t max[2]={H5S_UNLIMITED,H5S_UNLIMITED};
511  space=H5Screate_simple(2,dims,max);
512 
513  // Set chunk with size determined by def_chunk()
514  dcpl=H5Pcreate(H5P_DATASET_CREATE);
515  hsize_t chunk[2]={def_chunk(r),def_chunk(c)};
516  int status2=H5Pset_chunk(dcpl,2,chunk);
517 
518 #ifdef O2SCL_HDF5_COMP
519  // Compression part
520  if (compr_type==1) {
521  int status3=H5Pset_deflate(dcpl,6);
522  } else if (compr_type==2) {
523  int status3=H5Pset_szip(dcpl,H5_SZIP_NN_OPTION_MASK,16);
524  } else if (compr_type!=0) {
525  O2SCL_ERR2("Invalid compression type in ",
526  "hdf_file::setd_arr2d_copy().",o2scl::exc_einval);
527  }
528 #endif
529 
530  // Create the dataset
531  dset=H5Dcreate(current,name.c_str(),H5T_IEEE_F64LE,space,H5P_DEFAULT,
532  dcpl,H5P_DEFAULT);
533  chunk_alloc=true;
534 
535  } else {
536 
537  // Get current dimensions
538  space=H5Dget_space(dset);
539  hsize_t dims[2];
540  int ndims=H5Sget_simple_extent_dims(space,dims,0);
541 
542  // Set error if this dataset is more than 1-dimensional
543  if (ndims!=2) {
544  O2SCL_ERR2("Tried to set a non-matrix dataset with a ",
545  "matrix in hdf_file::setd_arr2d_copy().",
547  }
548 
549  // If necessary, extend the dataset
550  if (r!=dims[0] || c!=dims[1]) {
551  hsize_t new_dims[2]={r,c};
552  int status3=H5Dset_extent(dset,new_dims);
553  }
554 
555  }
556 
557  // Write the data
558  int status;
559  status=H5Dwrite(dset,H5T_NATIVE_DOUBLE,H5S_ALL,
560  H5S_ALL,H5P_DEFAULT,d);
561 
562  status=H5Dclose(dset);
563  status=H5Sclose(space);
564  if (chunk_alloc) {
565  status=H5Pclose(dcpl);
566  }
567 
568  // Free the C-style array
569  delete[] d;
570 
571  return 0;
572  }
573 
574  /** \brief Set a two-dimensional array dataset named \c name with \c m
575  */
576  template<class arr2d_t>
577  int seti_arr2d_copy(std::string name, size_t r,
578  size_t c, const arr2d_t &a2d) {
579 
580  if (write_access==false) {
581  O2SCL_ERR2("File not opened with write access ",
582  "in hdf_file::seti_arr2d_copy().",o2scl::exc_efailed);
583  }
584 
585  // Copy to a C-style array
586  int *d=new int[r*c];
587  for(size_t i=0;i<r;i++) {
588  for(size_t j=0;j<c;j++) {
589  d[i*c+j]=a2d[i][j];
590  }
591  }
592 
593  hid_t dset, space, dcpl=0;
594  bool chunk_alloc=false;
595 
596  H5E_BEGIN_TRY
597  {
598  // See if the dataspace already exists first
599  dset=H5Dopen(current,name.c_str(),H5P_DEFAULT);
600  }
601  H5E_END_TRY
602 #ifdef O2SCL_NEVER_DEFINED
603  {
604  }
605 #endif
606 
607  // If it doesn't exist, create it
608  if (dset<0) {
609 
610  // Create the dataspace
611  hsize_t dims[2]={r,c};
612  hsize_t max[2]={H5S_UNLIMITED,H5S_UNLIMITED};
613  space=H5Screate_simple(2,dims,max);
614 
615  // Set chunk with size determined by def_chunk()
616  dcpl=H5Pcreate(H5P_DATASET_CREATE);
617  hsize_t chunk[2]={def_chunk(r),def_chunk(c)};
618  int status2=H5Pset_chunk(dcpl,2,chunk);
619 
620 #ifdef O2SCL_HDF5_COMP
621  // Compression part
622  if (compr_type==1) {
623  int status3=H5Pset_deflate(dcpl,6);
624  } else if (compr_type==2) {
625  int status3=H5Pset_szip(dcpl,H5_SZIP_NN_OPTION_MASK,16);
626  } else if (compr_type!=0) {
627  O2SCL_ERR2("Invalid compression type in ",
628  "hdf_file::seti_arr2d_copy().",o2scl::exc_einval);
629  }
630 #endif
631 
632  // Create the dataset
633  dset=H5Dcreate(current,name.c_str(),H5T_STD_I32LE,space,H5P_DEFAULT,
634  dcpl,H5P_DEFAULT);
635  chunk_alloc=true;
636 
637  } else {
638 
639  // Get current dimensions
640  space=H5Dget_space(dset);
641  hsize_t dims[2];
642  int ndims=H5Sget_simple_extent_dims(space,dims,0);
643 
644  // Set error if this dataset is more than 1-dimensional
645  if (ndims!=2) {
646  O2SCL_ERR2("Tried to set a non-matrix dataset with a ",
647  "matrix in hdf_file::seti_arr2d_copy().",
649  }
650 
651  // If necessary, extend the dataset
652  if (r!=dims[0] || c!=dims[1]) {
653  hsize_t new_dims[2]={r,c};
654  int status3=H5Dset_extent(dset,new_dims);
655  }
656 
657  }
658 
659  // Write the data
660  int status;
661  status=H5Dwrite(dset,H5T_NATIVE_INT,H5S_ALL,
662  H5S_ALL,H5P_DEFAULT,d);
663 
664  status=H5Dclose(dset);
665  status=H5Sclose(space);
666  if (chunk_alloc) {
667  status=H5Pclose(dcpl);
668  }
669 
670  // Free the C-style array
671  delete[] d;
672 
673  return 0;
674  }
675 
676  /** \brief Set a two-dimensional array dataset named \c name with \c m
677  */
678  template<class arr2d_t>
679  int set_szt_arr2d_copy(std::string name, size_t r,
680  size_t c, const arr2d_t &a2d) {
681 
682  if (write_access==false) {
683  O2SCL_ERR2("File not opened with write access ",
684  "in hdf_file::set_szt_arr2d_copy().",o2scl::exc_efailed);
685  }
686 
687  // Copy to a C-style array
688  size_t *d=new size_t[r*c];
689  for(size_t i=0;i<r;i++) {
690  for(size_t j=0;j<c;j++) {
691  d[i*c+j]=a2d[i][j];
692  }
693  }
694 
695  hid_t dset, space, dcpl=0;
696  bool chunk_alloc=false;
697 
698  H5E_BEGIN_TRY
699  {
700  // See if the dataspace already exists first
701  dset=H5Dopen(current,name.c_str(),H5P_DEFAULT);
702  }
703  H5E_END_TRY
704 #ifdef O2SCL_NEVER_DEFINED
705  {
706  }
707 #endif
708 
709  // If it doesn't exist, create it
710  if (dset<0) {
711 
712  // Create the dataspace
713  hsize_t dims[2]={r,c};
714  hsize_t max[2]={H5S_UNLIMITED,H5S_UNLIMITED};
715  space=H5Screate_simple(2,dims,max);
716 
717  // Set chunk with size determined by def_chunk()
718  dcpl=H5Pcreate(H5P_DATASET_CREATE);
719  hsize_t chunk[2]={def_chunk(r),def_chunk(c)};
720  int status2=H5Pset_chunk(dcpl,2,chunk);
721 
722 #ifdef O2SCL_HDF5_COMP
723  // Compression part
724  if (compr_type==1) {
725  int status3=H5Pset_deflate(dcpl,6);
726  } else if (compr_type==2) {
727  int status3=H5Pset_szip(dcpl,H5_SZIP_NN_OPTION_MASK,16);
728  } else if (compr_type!=0) {
729  O2SCL_ERR2("Invalid compression type in ",
730  "hdf_file::set_szt_arr2d_copy().",o2scl::exc_einval);
731  }
732 #endif
733 
734  // Create the dataset
735  dset=H5Dcreate(current,name.c_str(),H5T_STD_U64LE,space,H5P_DEFAULT,
736  dcpl,H5P_DEFAULT);
737  chunk_alloc=true;
738 
739  } else {
740 
741  // Get current dimensions
742  space=H5Dget_space(dset);
743  hsize_t dims[2];
744  int ndims=H5Sget_simple_extent_dims(space,dims,0);
745 
746  // Set error if this dataset is more than 1-dimensional
747  if (ndims!=2) {
748  O2SCL_ERR2("Tried to set a non-matrix dataset with a ",
749  "matrix in hdf_file::set_szt_arr2d_copy().",
751  }
752 
753  // If necessary, extend the dataset
754  if (r!=dims[0] || c!=dims[1]) {
755  hsize_t new_dims[2]={r,c};
756  int status3=H5Dset_extent(dset,new_dims);
757  }
758 
759  }
760 
761  // Write the data
762  int status;
763  status=H5Dwrite(dset,H5T_NATIVE_HSIZE,H5S_ALL,
764  H5S_ALL,H5P_DEFAULT,d);
765 
766  status=H5Dclose(dset);
767  status=H5Sclose(space);
768  if (chunk_alloc) {
769  status=H5Pclose(dcpl);
770  }
771 
772  // Free the C-style array
773  delete[] d;
774 
775  return 0;
776  }
777  //@}
778 
779  /// \name Tensor I/O functions
780  //@{
781  /** \brief Get a tensor of double-precision numbers from an HDF file
782 
783  This version does not require a full copy of the tensor.
784  */
785  int getd_ten(std::string name,
786  o2scl::tensor<double,std::vector<double>,
787  std::vector<size_t> > &t);
788 
789  /** \brief Get a tensor of integers from an HDF file
790 
791  This version does not require a full copy of the tensor.
792  */
793  int geti_ten(std::string name,
794  o2scl::tensor<int,std::vector<int>,
795  std::vector<size_t> > &t);
796 
797  /** \brief Get a tensor of size_t from an HDF file
798 
799  This version does not require a full copy of the tensor.
800  */
801  int get_szt_ten(std::string name,
802  o2scl::tensor<size_t,std::vector<size_t>,
803  std::vector<size_t> > &t);
804 
805  /** \brief Get a tensor of double-precision numbers from an HDF file
806 
807  This version requires a full copy of the tensor from the
808  HDF5 file into the \ref o2scl::tensor object.
809  */
810  template<class vec_t, class vec_size_t>
811  int getd_ten_copy(std::string name,
813  o2scl::tensor<double,std::vector<double>,std::vector<size_t> > t2;
814  int ret=getd_ten(name,t2);
815  t=t2;
816  return ret;
817  }
818 
819  /** \brief Get a tensor of integers from an HDF file
820 
821  This version requires a full copy of the tensor from the
822  HDF5 file into the \ref o2scl::tensor object.
823  */
824  template<class vec_t, class vec_size_t>
825  int geti_ten_copy(std::string name,
827  o2scl::tensor<int,std::vector<int>,std::vector<size_t> > t2;
828  int ret=geti_ten(name,t2);
829  t=t2;
830  return ret;
831  }
832 
833  /** \brief Write a tensor of double-precision numbers to an HDF file
834 
835  You may overwrite a tensor already present in the
836  HDF file only if it has the same rank. This version
837  does not require a full copy of the tensor.
838  */
839  int setd_ten(std::string name,
840  const o2scl::tensor<double,std::vector<double>,
841  std::vector<size_t> > &t);
842 
843  /** \brief Write a tensor of integers to an HDF file
844 
845  You may overwrite a tensor already present in the
846  HDF file only if it has the same rank. This version
847  does not require a full copy of the tensor.
848  */
849  int seti_ten(std::string name,
850  const o2scl::tensor<int,std::vector<int>,
851  std::vector<size_t> > &t);
852 
853  /** \brief Write a tensor of integers to an HDF file
854 
855  You may overwrite a tensor already present in the
856  HDF file only if it has the same rank. This version
857  does not require a full copy of the tensor.
858  */
859  int set_szt_ten(std::string name,
860  const o2scl::tensor<size_t,std::vector<size_t>,
861  std::vector<size_t> > &t);
862 
863  /** \brief Write a tensor of double-precision numbers to an HDF file
864 
865  You may overwrite a tensor already present in the
866  HDF file only if it has the same rank. This version
867  requires a full copy of the tensor from the \ref o2scl::tensor
868  object into the HDF5 file.
869  */
870  template<class vec_t, class vec_size_t>
871  int setd_ten_copy(std::string name,
872  const o2scl::tensor<double,std::vector<double>,
873  std::vector<size_t> > &t) {
874  o2scl::tensor<double,std::vector<double>,std::vector<size_t> > t2;
875  t2=t;
876  int ret=setd_ten(name,t2);
877  return ret;
878  }
879 
880  /** \brief Write a tensor of integers to an HDF file
881 
882  You may overwrite a tensor already present in the
883  HDF file only if it has the same rank. This version
884  requires a full copy of the tensor from the \ref o2scl::tensor
885  object into the HDF5 file.
886  */
887  template<class vec_t, class vec_size_t>
888  int seti_ten_copy(std::string name,
889  const o2scl::tensor<int,std::vector<int>,
890  std::vector<size_t> > &t) {
891  o2scl::tensor<int,std::vector<int>,std::vector<size_t> > t2;
892  t2=t;
893  int ret=seti_ten(name,t2);
894  return ret;
895  }
896  //@}
897 
898  /** \name Array get functions
899 
900  All of these functions assume that the
901  pointer allocated beforehand, and matches the size of the
902  array in the HDF file. If the specified object is not found,
903  the \o2 error handler will be called.
904  */
905  //@{
906  /** \brief Get a character array named \c name of size \c n
907 
908  \note The pointer \c c must be allocated beforehand to
909  hold \c n entries, and \c n must match the size of the
910  array in the HDF file.
911  */
912  int getc_arr(std::string name, size_t n, char *c);
913 
914  /** \brief Get a double array named \c name of size \c n
915 
916  \note The pointer \c d must be allocated beforehand to
917  hold \c n entries, and \c n must match the size of the
918  array in the HDF file.
919  */
920  int getd_arr(std::string name, size_t n, double *d);
921 
922  /** \brief Get a double array named \c name of size \c n
923  and put the compression type in \c compr
924 
925  \note The pointer \c d must be allocated beforehand to
926  hold \c n entries, and \c n must match the size of the
927  array in the HDF file.
928  */
929  int getd_arr_compr(std::string name, size_t n, double *d,
930  int &compr);
931 
932  /** \brief Get a float array named \c name of size \c n
933 
934  \note The pointer \c f must be allocated beforehand to
935  hold \c n entries, and \c n must match the size of the
936  array in the HDF file.
937  */
938  int getf_arr(std::string name, size_t n, float *f);
939 
940  /** \brief Get an integer array named \c name of size \c n
941 
942  \note The pointer \c i must be allocated beforehand to
943  hold \c n entries, and \c n must match the size of the
944  array in the HDF file.
945  */
946  int geti_arr(std::string name, size_t n, int *i);
947  //@}
948 
949  /** \name Array get functions with memory allocation
950 
951  These functions allocate memory with \c new, which
952  should be freed by the user with \c delete .
953  */
954  //@{
955  /// Get a character array named \c name of size \c n
956  int getc_arr_alloc(std::string name, size_t &n, char *c);
957 
958  /// Get a double array named \c name of size \c n
959  int getd_arr_alloc(std::string name, size_t &n, double *d);
960 
961  /// Get a float array named \c name of size \c n
962  int getf_arr_alloc(std::string name, size_t &n, float *f);
963 
964  /// Get an integer array named \c name of size \c n
965  int geti_arr_alloc(std::string name, size_t &n, int *i);
966  //@}
967 
968  /** \name Array set functions
969  */
970  //@{
971  /// Set a character array named \c name of size \c n to value \c c
972  int setc_arr(std::string name, size_t n, const char *c);
973 
974  /// Set a double array named \c name of size \c n to value \c d
975  int setd_arr(std::string name, size_t n, const double *d);
976 
977  /// Set a float array named \c name of size \c n to value \c f
978  int setf_arr(std::string name, size_t n, const float *f);
979 
980  /// Set a integer array named \c name of size \c n to value \c i
981  int seti_arr(std::string name, size_t n, const int *i);
982 
983  /// Set a integer array named \c name of size \c n to value \c i
984  int set_szt_arr(std::string name, size_t n, const size_t *u);
985  //@}
986 
987  /** \name Fixed-length array set functions
988 
989  If a dataset named \c name is already present, then the
990  user-specified array must not be longer than the array already
991  present in the HDF file.
992  */
993  //@{
994  /// Set a character array named \c name of size \c n to value \c c
995  int setc_arr_fixed(std::string name, size_t n, const char *c);
996 
997  /// Set a double array named \c name of size \c n to value \c d
998  int setd_arr_fixed(std::string name, size_t n, const double *c);
999 
1000  /// Set a float array named \c name of size \c n to value \c f
1001  int setf_arr_fixed(std::string name, size_t n, const float *f);
1002 
1003  /// Set an integer array named \c name of size \c n to value \c i
1004  int seti_arr_fixed(std::string name, size_t n, const int *i);
1005  //@}
1006 
1007  /** \name Get functions with default values
1008 
1009  If the requested dataset is not found in the HDF file,
1010  the object is set to the specified default value
1011  and the error handler is not called.
1012  */
1013  //@{
1014  /// Get a character named \c name
1015  int getc_def(std::string name, char def, char &c);
1016 
1017  /// Get a double named \c name
1018  int getd_def(std::string name, double def, double &d);
1019 
1020  /// Get a float named \c name
1021  int getf_def(std::string name, float def, float &f);
1022 
1023  /// Get a integer named \c name
1024  int geti_def(std::string name, int def, int &i);
1025 
1026  /// Get a size_t named \c name
1027  int get_szt_def(std::string name, size_t def, size_t &i);
1028 
1029  /// Get a string named \c name
1030  int gets_def(std::string name, std::string def, std::string &s);
1031 
1032  /// Get a variable length string named \c name
1033  int gets_var_def(std::string name, std::string def, std::string &s);
1034  //@}
1035 
1036  /** \name Get functions with pre-allocated pointer
1037  */
1038  //@{
1039  /// Get a double array \c d pre-allocated to have size \c n
1040  int getd_vec_prealloc(std::string name, size_t n, double *d);
1041 
1042  /// Get an integer array \c i pre-allocated to have size \c n
1043  int geti_vec_prealloc(std::string name, size_t n, int *i);
1044 
1045  /// Get a double matrix \c d pre-allocated to have size <tt>(n,m)</tt>
1046  int getd_mat_prealloc(std::string name, size_t n, size_t m, double *d);
1047 
1048  /// Get an integer matrix \c i pre-allocated to have size <tt>(n,m)</tt>
1049  int geti_mat_prealloc(std::string name, size_t n, size_t m, int *i);
1050  //@}
1051 
1052  /// \name Find a group
1053  //@{
1054  /** \brief Look in hdf_file \c hf for an \o2 object of type \c
1055  type and if found, set \c group_name to the associated object
1056  name
1057 
1058  This function returns 0 if an object of type \c type is found
1059  and \ref o2scl::exc_enoprog if it fails.
1060  */
1061  int find_object_by_type(std::string type,
1062  std::string &name, int verbose=0);
1063 
1064  /** \brief Look in hdf_file \c hf for an \o2 object with name
1065  \c name and if found, set \c type to the associated type
1066 
1067  This function returns 0 if an object with name \c name is
1068  found and \ref o2scl::exc_enoprog if it fails.
1069  */
1070  int find_object_by_name(std::string name,
1071  std::string &type, int verbose=0);
1072 
1073  /** \brief Look in hdf_file \c hf for an \o2 object with name
1074  which matches (by <tt>fnmatch()</tt>) \c pattern.
1075 
1076  If an object is found, \c type is set to the associated type.
1077  This function returns 0 if an object with name \c name is
1078  found and \ref o2scl::exc_enoprog if it fails.
1079  */
1080  int find_object_by_pattern(std::string name,
1081  std::string &type, int verbose=0);
1082  //@}
1083 
1084  /** \brief List datasets and \o2 objects in the top-level
1085  of the file
1086  */
1087  void file_list(int verbose);
1088 
1089  /// Parameters for iterate_func()
1090  typedef struct {
1091  std::string tname;
1092  o2scl_hdf::hdf_file *hf;
1093  bool found;
1094  std::string type;
1095  int verbose;
1096  int mode;
1097  } iterate_parms;
1098 
1099  /// \name Mode values for \ref iterate_parms
1100  //@{
1101  static const int ip_filelist=1;
1102  static const int ip_name_from_type=2;
1103  static const int ip_type_from_name=3;
1104  static const int ip_type_from_pattern=4;
1105  //@}
1106 
1107  /// Process a type for \ref iterate_func()
1108  static void type_process(iterate_parms &ip, int mode, size_t ndims,
1109  hsize_t dims[100], hsize_t max_dims[100],
1110  std::string base_type, std::string name);
1111 
1112  /// HDF object iteration function
1113  static herr_t iterate_func(hid_t loc, const char *name,
1114  const H5L_info_t *inf, void *op_data);
1115 
1116 #ifndef DOXYGEN_INTERNAL
1117 
1118  private:
1119 
1120  /*
1121  In principle, one might be able to copy the IDs, but then we'd
1122  have to worry about the possibility that the file would be
1123  closed twice.
1124  */
1125  hdf_file(const hdf_file &);
1126  hdf_file& operator=(const hdf_file&);
1127 
1128 #endif
1129 
1130  };
1131 
1132 }
1133 
1134 #endif
o2scl::tensor
Tensor class with arbitrary dimensions.
Definition: tensor.h:226
o2scl_hdf::hdf_file::type_process
static void type_process(iterate_parms &ip, int mode, size_t ndims, hsize_t dims[100], hsize_t max_dims[100], std::string base_type, std::string name)
Process a type for iterate_func()
boost::numeric::ublas::matrix< double >
o2scl_hdf::hdf_file::get_szt
int get_szt(std::string name, size_t &u)
Get an unsigned integer named name.
o2scl_hdf::hdf_file::getc
int getc(std::string name, char &c)
Get a character named name.
boost::numeric::ublas::vector< double >
o2scl_hdf::hdf_file::geti_mat_prealloc
int geti_mat_prealloc(std::string name, size_t n, size_t m, int *i)
Get an integer matrix i pre-allocated to have size (n,m)
o2scl_hdf::hdf_file::sets
void sets(std::string name, std::string s)
Set a string named name to value s.
o2scl_hdf::hdf_file::geti_vec_copy
int geti_vec_copy(std::string name, vec_int_t &v)
Get vector dataset and place data in v.
Definition: hdf_file.h:339
o2scl::exc_efailed
@ exc_efailed
generic failure
Definition: err_hnd.h:61
o2scl_hdf::hdf_file::getc_arr
int getc_arr(std::string name, size_t n, char *c)
Get a character array named name of size n.
o2scl_hdf::hdf_file::gets_var_def
int gets_var_def(std::string name, std::string def, std::string &s)
Get a variable length string named name.
o2scl_hdf::hdf_file::setd_arr2d_copy
int setd_arr2d_copy(std::string name, size_t r, size_t c, const arr2d_t &a2d)
Set a two-dimensional array dataset named name with m.
Definition: hdf_file.h:475
o2scl_hdf::hdf_file::gets_var
int gets_var(std::string name, std::string &s)
Get a variable length string named name.
O2SCL_ERR2
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
o2scl_hdf::hdf_file::set_szt_ten
int set_szt_ten(std::string name, const o2scl::tensor< size_t, std::vector< size_t >, std::vector< size_t > > &t)
Write a tensor of integers to an HDF file.
o2scl_hdf::hdf_file::get_current_id
hid_t get_current_id()
Retrieve the current working id.
o2scl_hdf::hdf_file::getd_mat_copy
int getd_mat_copy(std::string name, ubmatrix &m)
Get matrix dataset and place data in m.
o2scl_hdf::hdf_file::file
hid_t file
File ID.
Definition: hdf_file.h:119
o2scl_hdf::hdf_file::geti_vec_prealloc
int geti_vec_prealloc(std::string name, size_t n, int *i)
Get an integer array i pre-allocated to have size n.
o2scl::vector_copy
void vector_copy(const vec_t &src, vec2_t &dest)
Simple vector copy.
Definition: vector.h:124
o2scl_hdf::hdf_file::sets_vec
int sets_vec(std::string name, const std::vector< std::string > &s)
Set a vector of strings named name.
o2scl_hdf::hdf_file::getc_def
int getc_def(std::string name, char def, char &c)
Get a character named name.
o2scl_hdf::hdf_file::geti
int geti(std::string name, int &i)
Get a integer named name.
o2scl_hdf::hdf_file::getf_arr
int getf_arr(std::string name, size_t n, float *f)
Get a float array named name of size n.
o2scl_hdf::hdf_file::set_szt_arr
int set_szt_arr(std::string name, size_t n, const size_t *u)
Set a integer array named name of size n to value i.
o2scl_hdf::hdf_file::geti_vec
int geti_vec(std::string name, std::vector< int > &v)
Get vector dataset and place data in v.
o2scl_hdf::hdf_file::geti_ten_copy
int geti_ten_copy(std::string name, o2scl::tensor< int, vec_t, vec_size_t > &t)
Get a tensor of integers from an HDF file.
Definition: hdf_file.h:825
o2scl_hdf::hdf_file::close
void close()
Close the file.
o2scl_hdf::hdf_file::getd_vec
int getd_vec(std::string name, std::vector< double > &v)
Get vector dataset and place data in v.
o2scl_hdf::hdf_file::getf
int getf(std::string name, float &f)
Get a float named name.
o2scl_hdf::hdf_file::seti_vec_copy
int seti_vec_copy(std::string name, vec_int_t &v)
Set vector dataset named name with v.
Definition: hdf_file.h:402
o2scl_hdf::hdf_file::seti_ten
int seti_ten(std::string name, const o2scl::tensor< int, std::vector< int >, std::vector< size_t > > &t)
Write a tensor of integers to an HDF file.
o2scl_hdf::hdf_file::file_list
void file_list(int verbose)
List datasets and O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$s...
o2scl_hdf::hdf_file::open
int open(std::string fname, bool write_access=false, bool err_on_fail=true)
Open a file named fname.
o2scl_hdf::hdf_file::setd_vec_copy
int setd_vec_copy(std::string name, const vec_t &v)
Set vector dataset named name with v.
Definition: hdf_file.h:382
o2scl_hdf::hdf_file::sets_fixed
void sets_fixed(std::string name, std::string s)
Set a fixed-length string named name to value s.
o2scl_hdf::hdf_file::getd
int getd(std::string name, double &d)
Get a double named name.
o2scl_hdf::hdf_file::gets
int gets(std::string name, std::string &s)
Get a string named name.
o2scl_hdf::hdf_file::setd_ten
int setd_ten(std::string name, const o2scl::tensor< double, std::vector< double >, std::vector< size_t > > &t)
Write a tensor of double-precision numbers to an HDF file.
o2scl_hdf::hdf_file::setd_arr_fixed
int setd_arr_fixed(std::string name, size_t n, const double *c)
Set a double array named name of size n to value d.
o2scl_hdf::hdf_file::geti_mat_copy
int geti_mat_copy(std::string name, ubmatrix_int &m)
Get matrix dataset and place data in m.
o2scl::exc_einval
@ exc_einval
invalid argument supplied by user
Definition: err_hnd.h:59
o2scl_hdf::hdf_file::getc_arr_alloc
int getc_arr_alloc(std::string name, size_t &n, char *c)
Get a character array named name of size n.
o2scl_hdf::hdf_file::find_object_by_type
int find_object_by_type(std::string type, std::string &name, int verbose=0)
Look in hdf_file hf for an O<span style='position: relative; top: 0.3em; font-size: 0....
o2scl_hdf::hdf_file::get_szt_ten
int get_szt_ten(std::string name, o2scl::tensor< size_t, std::vector< size_t >, std::vector< size_t > > &t)
Get a tensor of size_t from an HDF file.
o2scl_hdf::hdf_file::set_szt_arr2d_copy
int set_szt_arr2d_copy(std::string name, size_t r, size_t c, const arr2d_t &a2d)
Set a two-dimensional array dataset named name with m.
Definition: hdf_file.h:679
o2scl_hdf::hdf_file::seti_vec
int seti_vec(std::string name, const std::vector< int > &v)
Set vector dataset named name with v.
o2scl_hdf::hdf_file::write_access
bool write_access
If true, then the file has read and write access.
Definition: hdf_file.h:141
o2scl_hdf
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
Definition: table.h:59
o2scl_hdf::hdf_file::set_szt_vec_copy
int set_szt_vec_copy(std::string name, const vec_size_t &v)
Set vector dataset named name with v.
Definition: hdf_file.h:421
o2scl_hdf::hdf_file::set_szt
void set_szt(std::string name, size_t u)
Set an unsigned integer named name to value u.
o2scl_hdf::hdf_file::getd_def
int getd_def(std::string name, double def, double &d)
Get a double named name.
o2scl_hdf::hdf_file::setf_arr_fixed
int setf_arr_fixed(std::string name, size_t n, const float *f)
Set a float array named name of size n to value f.
o2scl_hdf::hdf_file::get_szt_vec_copy
int get_szt_vec_copy(std::string name, vec_size_t &v)
Get vector dataset and place data in v.
Definition: hdf_file.h:354
o2scl_hdf::hdf_file::file_open
bool file_open
True if a file has been opened.
Definition: hdf_file.h:122
o2scl_hdf::hdf_file::setd_arr
int setd_arr(std::string name, size_t n, const double *d)
Set a double array named name of size n to value d.
o2scl_hdf::hdf_file::setf_arr
int setf_arr(std::string name, size_t n, const float *f)
Set a float array named name of size n to value f.
o2scl_hdf::hdf_file::seti_arr_fixed
int seti_arr_fixed(std::string name, size_t n, const int *i)
Set an integer array named name of size n to value i.
o2scl_hdf::hdf_file::def_chunk
virtual hsize_t def_chunk(size_t n)
Default chunk size.
Definition: hdf_file.h:132
o2scl_hdf::hdf_file::setc
void setc(std::string name, char c)
Set a character named name to value c.
o2scl_hdf::hdf_file::geti_arr
int geti_arr(std::string name, size_t n, int *i)
Get an integer array named name of size n.
o2scl_hdf::hdf_file::get_file_id
hid_t get_file_id()
Get the current file id.
o2scl_hdf::hdf_file::seti
void seti(std::string name, int i)
Set an integer named name to value i.
o2scl_hdf::hdf_file::find_object_by_name
int find_object_by_name(std::string name, std::string &type, int verbose=0)
Look in hdf_file hf for an O<span style='position: relative; top: 0.3em; font-size: 0....
o2scl_hdf::hdf_file::geti_def
int geti_def(std::string name, int def, int &i)
Get a integer named name.
o2scl_hdf::hdf_file::geti_arr_alloc
int geti_arr_alloc(std::string name, size_t &n, int *i)
Get an integer array named name of size n.
o2scl_hdf::hdf_file::current
hid_t current
Current file or group location.
Definition: hdf_file.h:125
o2scl_hdf::hdf_file
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
Definition: hdf_file.h:105
o2scl_hdf::hdf_file::open_or_create
void open_or_create(std::string fname)
Open a file named fname or create if it doesn't already exist.
o2scl_hdf::hdf_file::seti_ten_copy
int seti_ten_copy(std::string name, const o2scl::tensor< int, std::vector< int >, std::vector< size_t > > &t)
Write a tensor of integers to an HDF file.
Definition: hdf_file.h:888
o2scl_hdf::hdf_file::seti_arr2d_copy
int seti_arr2d_copy(std::string name, size_t r, size_t c, const arr2d_t &a2d)
Set a two-dimensional array dataset named name with m.
Definition: hdf_file.h:577
o2scl_hdf::hdf_file::setd
void setd(std::string name, double d)
Set a double named name to value d.
o2scl_hdf::hdf_file::gets_vec
int gets_vec(std::string name, std::vector< std::string > &s)
Get a vector of strings named name and store it in s.
o2scl_hdf::hdf_file::iterate_parms
Parameters for iterate_func()
Definition: hdf_file.h:1090
o2scl_hdf::hdf_file::min_compr_size
size_t min_compr_size
Minimum size to compress by default.
Definition: hdf_file.h:160
o2scl_hdf::hdf_file::getd_vec_prealloc
int getd_vec_prealloc(std::string name, size_t n, double *d)
Get a double array d pre-allocated to have size n.
o2scl_hdf::hdf_file::gets_def_fixed
int gets_def_fixed(std::string name, std::string def, std::string &s)
Get a fixed-length string named name with default value s.
o2scl_hdf::hdf_file::setc_arr
int setc_arr(std::string name, size_t n, const char *c)
Set a character array named name of size n to value c.
o2scl_hdf::hdf_file::seti_arr
int seti_arr(std::string name, size_t n, const int *i)
Set a integer array named name of size n to value i.
o2scl_hdf::hdf_file::getd_ten
int getd_ten(std::string name, o2scl::tensor< double, std::vector< double >, std::vector< size_t > > &t)
Get a tensor of double-precision numbers from an HDF file.
o2scl_hdf::hdf_file::gets_def
int gets_def(std::string name, std::string def, std::string &s)
Get a string named name.
o2scl_hdf::hdf_file::getd_arr
int getd_arr(std::string name, size_t n, double *d)
Get a double array named name of size n.
o2scl_hdf::hdf_file::get_szt_def
int get_szt_def(std::string name, size_t def, size_t &i)
Get a size_t named name.
o2scl_hdf::hdf_file::getf_def
int getf_def(std::string name, float def, float &f)
Get a float named name.
o2scl_hdf::hdf_file::getd_mat_prealloc
int getd_mat_prealloc(std::string name, size_t n, size_t m, double *d)
Get a double matrix d pre-allocated to have size (n,m)
o2scl_hdf::hdf_file::getd_ten_copy
int getd_ten_copy(std::string name, o2scl::tensor< double, vec_t, vec_size_t > &t)
Get a tensor of double-precision numbers from an HDF file.
Definition: hdf_file.h:811
o2scl_hdf::hdf_file::setf
void setf(std::string name, float f)
Set a float named name to value f.
o2scl_hdf::hdf_file::setc_arr_fixed
int setc_arr_fixed(std::string name, size_t n, const char *c)
Set a character array named name of size n to value c.
o2scl_hdf::hdf_file::getd_arr_alloc
int getd_arr_alloc(std::string name, size_t &n, double *d)
Get a double array named name of size n.
o2scl_hdf::hdf_file::getd_vec_copy
int getd_vec_copy(std::string name, vec_t &v)
Get vector dataset and place data in v.
Definition: hdf_file.h:323
o2scl_hdf::hdf_file::setd_ten_copy
int setd_ten_copy(std::string name, const o2scl::tensor< double, std::vector< double >, std::vector< size_t > > &t)
Write a tensor of double-precision numbers to an HDF file.
Definition: hdf_file.h:871
o2scl_hdf::hdf_file::close_group
int close_group(hid_t group)
Close a previously created group.
Definition: hdf_file.h:294
o2scl_hdf::hdf_file::gets_fixed
int gets_fixed(std::string name, std::string &s)
Get a fixed-length string named name.
o2scl_hdf::hdf_file::setd_mat_copy
int setd_mat_copy(std::string name, const ubmatrix &m)
Set matrix dataset named name with m.
o2scl_hdf::hdf_file::set_szt_vec
int set_szt_vec(std::string name, const std::vector< size_t > &v)
Set vector dataset named name with v.
o2scl_hdf::hdf_file::geti_ten
int geti_ten(std::string name, o2scl::tensor< int, std::vector< int >, std::vector< size_t > > &t)
Get a tensor of integers from an HDF file.
o2scl_hdf::hdf_file::iterate_func
static herr_t iterate_func(hid_t loc, const char *name, const H5L_info_t *inf, void *op_data)
HDF object iteration function.
o2scl_hdf::hdf_file::setd_vec
int setd_vec(std::string name, const std::vector< double > &v)
Set vector dataset named name with v.
o2scl_hdf::hdf_file::set_current_id
void set_current_id(hid_t cur)
Set the current working id.
o2scl_hdf::hdf_file::getf_arr_alloc
int getf_arr_alloc(std::string name, size_t &n, float *f)
Get a float array named name of size n.
o2scl_hdf::hdf_file::find_object_by_pattern
int find_object_by_pattern(std::string name, std::string &type, int verbose=0)
Look in hdf_file hf for an O<span style='position: relative; top: 0.3em; font-size: 0....
o2scl_hdf::hdf_file::seti_mat_copy
int seti_mat_copy(std::string name, const ubmatrix_int &m)
Set matrix dataset named name with m.
o2scl_hdf::hdf_file::has_write_access
bool has_write_access()
If true, then the file has read and write access.
Definition: hdf_file.h:152
o2scl_hdf::hdf_file::open_group
hid_t open_group(hid_t init_id, std::string path)
Open a group relative to the location specified in init_id.
o2scl_hdf::hdf_file::getd_arr_compr
int getd_arr_compr(std::string name, size_t n, double *d, int &compr)
Get a double array named name of size n and put the compression type in compr.
o2scl_hdf::hdf_file::compr_type
int compr_type
Compression type (support experimental)
Definition: hdf_file.h:157
o2scl_hdf::hdf_file::get_szt_vec
int get_szt_vec(std::string name, std::vector< size_t > &v)
Get vector dataset and place data in v.

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).