All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hdf_file.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2014, 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 #include <hdf5.h>
32 
33 #include <boost/numeric/ublas/vector.hpp>
34 #include <boost/numeric/ublas/matrix.hpp>
35 
36 #include <o2scl/vector.h>
37 #include <o2scl/tensor.h>
38 #include <o2scl/format_float.h>
39 
40 /** \brief The \o2 namespace for I/O with HDF
41  */
42 namespace o2scl_hdf {
43 
44  /** \brief Store data in an \o2 compatible HDF5 file
45 
46  See also the \ref hdf_section section of the \o2
47  User's guide.
48 
49  The member functions which write or get data from an HDF file
50  begin with either <tt>get</tt> or <tt>set</tt>. Where
51  appropriate, the next character is either \c c for character, \c
52  d for double, \c f for float, or \c i for int.
53 
54  By default, vectors and matrices are written to HDF files in a
55  chunked format, so their length can be changed later as
56  necessary. The chunk size is chosen in \ref def_chunk() to be
57  the closest power of 10 to the current vector size.
58 
59  All files not closed by the user are closed in the destructor,
60  but the destructor does not automatically close groups.
61 
62  \note Currently, HDF I/O functions write data to HDF files
63  assuming that \c int and \c float have 4 bytes, while \c size_t
64  and \c double are 8 bytes. All output is done in little endian
65  format. While <tt>get</tt> functions can read data with
66  different sizes or in big endian format, the <tt>set</tt>
67  functions cannot currently write data this way.
68 
69  \note It does make sense to write a zero-length vector to an HDF
70  file if the vector does not have a fixed size in order to create
71  a placeholder for future output. Thus the <tt>set_vec()</tt> and
72  allow zero-length vectors and the <tt>set_arr()</tt> functions
73  allow the <tt>size_t</tt> parameter to be zero, in which case
74  the pointer parameter is ignored. The <tt>set_vec_fixed()</tt>
75  and <tt>set_arr_fixed()</tt> functions do not allow this, and
76  will throw an exception if sent a zero-length vector.
77 
78  \warning This class is still in development. Because of this,
79  hdf5 files generated by this class may not be easily read by
80  future versions. Later versions of \o2 will have stronger
81  guarantees on backwards compatibility.
82 
83  \future The \o2 HDF functions do not always consistently choose
84  between throwing \o2 exceptions and throwing HDF5 exceptions.
85  Check and/or fix this.
86  \future Automatically close groups, e.g. by storing hid_t's in a
87  stack?
88  \future Rewrite the _arr_alloc() functions so that they
89  return a shared_ptr.
90  \future Move the code from the 'filelist' acol command here
91  into hdf_file.
92  */
93  class hdf_file {
94 
95  public:
96 
101 
102 #ifndef DOXYGEN_INTERNAL
103 
104  protected:
105 
106  /// File ID
107  hid_t file;
108 
109  /// True if a file has been opened
110  bool file_open;
111 
112  /// Current file or group location
113  hid_t current;
114 
115  /** \brief Default chunk size
116 
117  Choose the closest power of 10 which is greater than or equal
118  to 10 and less than or equal to \f$ 10^6 \f$.
119  */
120  virtual hsize_t def_chunk(size_t n) {
121  size_t ch=(size_t)((1.0+1.0e-12)*
122  pow(10.0,floor(log10(((double)n))+0.5)));
123  if (ch<10) ch=10;
124  if (ch>1000000) ch=1000000;
125  return ch;
126  }
127 
128 #endif
129 
130  public:
131 
132  hdf_file();
133 
134  virtual ~hdf_file();
135 
136  /// Desc
138 
139  /// \name Open and close files
140  //@{
141  /** \brief Open a file named \c fname
142 
143  If \c err_on_fail is \c true, this calls the error handler if
144  opening the file fails (e.g. because the file does not exist).
145  If \c err_on_fail is \c false and opening the file fails,
146  nothing is done and the function returns the value \ref
147  o2scl::exc_efilenotfound. If the open succeeds, this function
148  returns \ref o2scl::success.
149  */
150  int open(std::string fname, bool err_on_fail=true);
151 
152  /// Open a file named \c fname or create if it doesn't already exist
153  void open_or_create(std::string fname);
154 
155  /// Close the file
156  void close();
157  //@}
158 
159  /// \name Manipulate ids
160  //@{
161  /// Get the current file id
162  hid_t get_file_id();
163 
164  /// Set the current working id
165  void set_current_id(hid_t cur);
166 
167  /// Retrieve the current working id
168  hid_t get_current_id();
169  //@}
170 
171  /** \name Simple get functions
172 
173  If the specified object is not found, the \o2 error handler
174  will be called.
175  */
176  //@{
177  /// Get a character named \c name
178  int getc(std::string name, char &c);
179 
180  /// Get a double named \c name
181  int getd(std::string name, double &d);
182 
183  /// Get a float named \c name
184  int getf(std::string name, float &f);
185 
186  /// Get a integer named \c name
187  int geti(std::string name, int &i);
188 
189  /// Get an unsigned integer named \c name
190  int get_szt(std::string name, size_t &u);
191 
192  /** \brief Get a string named \c name
193 
194  \note Strings are stored as character arrays and thus
195  retrieving a string from a file requires loading the
196  information from the file into a character array, and then
197  copying it to the string. This will be slow for very long
198  strings.
199  */
200  int gets(std::string name, std::string &s);
201 
202  /** \brief Get a fixed-length string named \c name
203  */
204  int gets_fixed(std::string name, std::string &s);
205 
206  /** \brief Get a fixed-length string named \c name with default
207  value \c s
208  */
209  int gets_def_fixed(std::string name, std::string def, std::string &s);
210  //@}
211 
212  /// \name Simple set functions
213  //@{
214  /// Set a character named \c name to value \c c
215  void setc(std::string name, char c);
216 
217  /// Set a double named \c name to value \c d
218  void setd(std::string name, double d);
219 
220  /// Set a float named \c name to value \c f
221  void setf(std::string name, float f);
222 
223  /// Set an integer named \c name to value \c i
224  void seti(std::string name, int i);
225 
226  /// Set an unsigned integer named \c name to value \c u
227  void set_szt(std::string name, size_t u);
228 
229  /** \brief Set a string named \c name to value \c s
230 
231  The string is stored in the HDF file as an extensible
232  character array rather than a string.
233  */
234  void sets(std::string name, std::string s);
235 
236  /** \brief Set a fixed-length string named \c name to value \c s
237 
238  This function stores <tt>s</tt> as a fixed-length string
239  in the HDF file. If a dataset named \c name is already
240  present, then \c s must not be longer than the string
241  length already specified in the HDF file.
242  */
243  void sets_fixed(std::string name, std::string s);
244  //@}
245 
246  /// \name Group manipulation
247  //@{
248  /** \brief Open a group relative to the location specified in
249  \c init_id
250 
251  \note In order to ensure that future objects are written to the
252  newly-created group, the user must use set_current_id()
253  using the newly-created group ID for the argument.
254  */
255  hid_t open_group(hid_t init_id, std::string path);
256 
257  /** \brief Open a group relative to the current location
258 
259  \note In order to ensure that future objects are written to the
260  newly-created group, the user must use set_current_id()
261  using the newly-created group ID for the argument.
262  */
263  hid_t open_group(std::string path);
264 
265  /// Close a previously created group
266  int close_group(hid_t group) {
267  return H5Gclose(group);
268  }
269  //@}
270 
271  /** \name Vector get functions
272 
273  These functions automatically free any previously allocated
274  memory in <tt>v</tt> and then allocate the proper space
275  required to read the information from the HDF file.
276  */
277  //@{
278  /// Get vector dataset and place data in \c v
279  int getd_vec(std::string name, std::vector<double> &v);
280 
281  /** \brief Get vector dataset and place data in \c v
282 
283  This works with any vector class which has a
284  <tt>resize()</tt> method.
285 
286  \future This currently requires a copy, but there may
287  be a way to write a new version which does not.
288  \comment
289  AWS 12/10/13: I don't think the ublas library guarantees
290  that the vector occupies a continuous chunk of memory
291  like std::vector<> now does.
292  \endcomment
293  */
294  template<class vec_t>
295  int getd_vec_copy(std::string name, vec_t &v) {
296  std::vector<double> v2;
297  int ret=getd_vec(name,v2);
298  v.resize(v2.size());
299  o2scl::vector_copy(v2.size(),v2,v);
300  return ret;
301  }
302 
303  /// Get vector dataset and place data in \c v
304  int geti_vec(std::string name, std::vector<int> &v);
305  /** \brief Get vector dataset and place data in \c v
306 
307  \future This currently requires a copy, but there may
308  be a way to write a new version which does not.
309  */
310  template<class vec_int_t>
311  int geti_vec_copy(std::string name, vec_int_t &v) {
312  std::vector<int> v2;
313  int ret=geti_vec(name,v2);
314  v.resize(v2.size());
315  for(size_t i=0;i<v2.size();i++) v[i]=v2[i];
316  return ret;
317  }
318  /// Get vector dataset and place data in \c v
319  int get_szt_vec(std::string name, std::vector<size_t> &v);
320  /** \brief Get vector dataset and place data in \c v
321 
322  \future This currently requires a copy, but there may
323  be a way to write a new version which does not.
324  */
325  template<class vec_size_t>
326  int get_szt_vec_copy(std::string name, vec_size_t &v) {
327  std::vector<int> v2;
328  int ret=geti_vec(name,v2);
329  v.resize(v2.size());
330  for(size_t i=0;i<v2.size();i++) v[i]=v2[i];
331  return ret;
332  }
333  /** \brief Get a vector of strings named \c name and store it in \c s
334  */
335  int gets_vec(std::string name, std::vector<std::string> &s);
336  //@}
337 
338  /** \name Vector set functions
339 
340  These functions automatically write all of the vector elements
341  to the HDF file, if necessary extending the data that is
342  already present.
343  */
344  //@{
345  /// Set vector dataset named \c name with \c v
346  int setd_vec(std::string name, const std::vector<double> &v);
347 
348  /** \brief Set vector dataset named \c name with \c v
349 
350  This requires a copy before the vector is written to
351  the file.
352  */
353  template<class vec_t>
354  int setd_vec_copy(std::string name, const vec_t &v) {
355  if (v.size()==0) {
356  return setd_arr(name,0,0);
357  }
358 
359  // We have to copy to an std::vector first
360  std::vector<double> v2(v.size());
361  o2scl::vector_copy(v.size(),v,v2);
362 
363  return setd_arr(name,v2.size(),&v2[0]);
364  }
365 
366  /// Set vector dataset named \c name with \c v
367  int seti_vec(std::string name, const std::vector<int> &v);
368  /** \brief Set vector dataset named \c name with \c v
369 
370  This requires a copy before the vector is written to
371  the file.
372  */
373  template<class vec_int_t>
374  int seti_vec_copy(std::string name, vec_int_t &v) {
375  if (v.size()==0) {
376  return seti_arr(name,0,0);
377  }
378 
379  // We have to copy to an std::vector first
380  std::vector<int> v2(v.size());
381  vector_copy(v.size(),v,v2);
382 
383  return seti_arr(name,v2.size(),&v2[0]);
384  }
385  /// Set vector dataset named \c name with \c v
386  int set_szt_vec(std::string name, const std::vector<size_t> &v);
387  /** \brief Set vector dataset named \c name with \c v
388 
389  This requires a copy before the vector is written to
390  the file.
391  */
392  template<class vec_size_t>
393  int set_szt_vec_copy(std::string name, vec_size_t &v) {
394  if (v.size()==0) {
395  return set_szt_arr(name,0,0);
396  }
397 
398  // We have to copy to an std::vector first
399  std::vector<size_t> v2(v.size());
400  vector_copy(v.size(),v,v2);
401 
402  return set_szt_arr(name,v2.size(),&v2[0]);
403  }
404 
405  /** \brief Set a vector of strings named \c name
406 
407  \devnote
408  String vectors are reformatted as a single character array, in
409  order to allow each string to have different length and to
410  make each string extensible. The size of the vector \c s is
411  stored as an integer named <tt>nw</tt>.
412  */
413  int sets_vec(std::string name, std::vector<std::string> &s);
414  //@}
415 
416  /** \name Matrix get functions
417 
418  These functions automatically free any previously allocated
419  memory in <tt>m</tt> and then allocate the proper space
420  required to read the information from the HDF file.
421  */
422  //@{
423  /// Get matrix dataset and place data in \c m
424  int getd_mat_copy(std::string name, ubmatrix &m);
425  /// Get matrix dataset and place data in \c m
426  int geti_mat_copy(std::string name, ubmatrix_int &m);
427  //@}
428 
429  /** \name Matrix set functions
430 
431  These functions automatically write all of the vector elements
432  to the HDF file, if necessary extending the data that is
433  already present.
434  */
435  //@{
436  /** \brief Set matrix dataset named \c name with \c m
437  */
438  int setd_mat_copy(std::string name, const ubmatrix &m);
439  int seti_mat_copy(std::string name, const ubmatrix_int &m);
440  //@}
441 
442  /// \name Tensor I/O functions
443  //@{
444  /** \brief Get a tensor from an HDF file
445 
446  This version does not require a full copy of the tensor.
447  */
448  int getd_ten(std::string name,
449  o2scl::tensor<std::vector<double>,std::vector<size_t> > &t);
450 
451  /** \brief Get a tensor from an HDF file
452 
453  This version requires a full copy of the tensor from the
454  HDF5 file into the \ref o2scl::tensor object.
455  */
456  template<class vec_t, class vec_size_t>
457  int getd_ten_copy(std::string name, o2scl::tensor<vec_t,vec_size_t> &t) {
458  o2scl::tensor<std::vector<double>,std::vector<size_t> > t2;
459  int ret=getd_ten(name,t2);
460  t=t2;
461  return ret;
462  }
463 
464  /** \brief Write a tensor to an HDF file
465 
466  You may overwrite a tensor already present in the
467  HDF file only if it has the same rank. This version
468  does not require a full copy of the tensor.
469  */
470  int setd_ten(std::string name,
471  const o2scl::tensor<std::vector<double>,
472  std::vector<size_t> > &t);
473 
474  /** \brief Write a tensor to an HDF file
475 
476  You may overwrite a tensor already present in the
477  HDF file only if it has the same rank. This version
478  requires a full copy of the tensor from the \ref o2scl::tensor
479  object into the HDF5 file.
480  */
481  template<class vec_t, class vec_size_t>
482  int setd_ten_copy(std::string name,
483  const o2scl::tensor<std::vector<double>,
484  std::vector<size_t> > &t) {
485  o2scl::tensor<std::vector<double>,std::vector<size_t> > t2;
486  t2=t;
487  int ret=getd_ten(name,t2);
488  return ret;
489  }
490  //@}
491 
492  /** \name Array get functions
493 
494  All of these functions assume that the
495  pointer allocated beforehand, and matches the size of the
496  array in the HDF file. If the specified object is not found,
497  the \o2 error handler will be called.
498  */
499  //@{
500  /** \brief Get a character array named \c name of size \c n
501 
502  \note The pointer \c c must be allocated beforehand to
503  hold \c n entries, and \c n must match the size of the
504  array in the HDF file.
505  */
506  int getc_arr(std::string name, size_t n, char *c);
507 
508  /** \brief Get a double array named \c name of size \c n
509 
510  \note The pointer \c d must be allocated beforehand to
511  hold \c n entries, and \c n must match the size of the
512  array in the HDF file.
513  */
514  int getd_arr(std::string name, size_t n, double *d);
515 
516  /** \brief Get a float array named \c name of size \c n
517 
518  \note The pointer \c f must be allocated beforehand to
519  hold \c n entries, and \c n must match the size of the
520  array in the HDF file.
521  */
522  int getf_arr(std::string name, size_t n, float *f);
523 
524  /** \brief Get an integer array named \c name of size \c n
525 
526  \note The pointer \c i must be allocated beforehand to
527  hold \c n entries, and \c n must match the size of the
528  array in the HDF file.
529  */
530  int geti_arr(std::string name, size_t n, int *i);
531  //@}
532 
533  /** \name Array get functions with memory allocation
534 
535  These functions allocate memory with \c new, which
536  should be freed by the user with \c delete .
537  */
538  //@{
539  /// Get a character array named \c name of size \c n
540  int getc_arr_alloc(std::string name, size_t &n, char *c);
541 
542  /// Get a double array named \c name of size \c n
543  int getd_arr_alloc(std::string name, size_t &n, double *d);
544 
545  /// Get a float array named \c name of size \c n
546  int getf_arr_alloc(std::string name, size_t &n, float *f);
547 
548  /// Get an integer array named \c name of size \c n
549  int geti_arr_alloc(std::string name, size_t &n, int *i);
550  //@}
551 
552  /** \name Array set functions
553  */
554  //@{
555  /// Set a character array named \c name of size \c n to value \c c
556  int setc_arr(std::string name, size_t n, const char *c);
557 
558  /// Set a double array named \c name of size \c n to value \c d
559  int setd_arr(std::string name, size_t n, const double *d);
560 
561  int setd_arr_comp(std::string name, size_t n, const double *d);
562 
563  /// Set a float array named \c name of size \c n to value \c f
564  int setf_arr(std::string name, size_t n, const float *f);
565 
566  /// Set a integer array named \c name of size \c n to value \c i
567  int seti_arr(std::string name, size_t n, const int *i);
568 
569  /// Set a integer array named \c name of size \c n to value \c i
570  int set_szt_arr(std::string name, size_t n, const size_t *u);
571  //@}
572 
573  /** \name Fixed-length array set functions
574 
575  If a dataset named \c name is already present, then the
576  user-specified array must not be longer than the array already
577  present in the HDF file.
578  */
579  //@{
580  /// Set a character array named \c name of size \c n to value \c c
581  int setc_arr_fixed(std::string name, size_t n, const char *c);
582 
583  /// Set a double array named \c name of size \c n to value \c d
584  int setd_arr_fixed(std::string name, size_t n, const double *c);
585 
586  /// Set a float array named \c name of size \c n to value \c f
587  int setf_arr_fixed(std::string name, size_t n, const float *f);
588 
589  /// Set an integer array named \c name of size \c n to value \c i
590  int seti_arr_fixed(std::string name, size_t n, const int *i);
591  //@}
592 
593  /** \name Get functions with default values
594 
595  If the requested dataset is not found in the HDF file,
596  the object is set to the specified default value
597  and the error handler is not called.
598  */
599  //@{
600  /// Get a character named \c name
601  int getc_def(std::string name, char def, char &c);
602 
603  /// Get a double named \c name
604  int getd_def(std::string name, double def, double &d);
605 
606  /// Get a float named \c name
607  int getf_def(std::string name, float def, float &f);
608 
609  /// Get a integer named \c name
610  int geti_def(std::string name, int def, int &i);
611 
612  /// Get a size_t named \c name
613  int get_szt_def(std::string name, size_t def, size_t &i);
614 
615  /// Get a string named \c name
616  int gets_def(std::string name, std::string def, std::string &s);
617  //@}
618 
619  /** \name Get functions with pre-allocated pointer
620  */
621  //@{
622  /// Get a double array \c d pre-allocated to have size \c n
623  int getd_vec_prealloc(std::string name, size_t n, double *d);
624 
625  /// Get an integer array \c i pre-allocated to have size \c n
626  int geti_vec_prealloc(std::string name, size_t n, int *i);
627 
628  /// Get a double matrix \c d pre-allocated to have size <tt>(n,m)</tt>
629  int getd_mat_prealloc(std::string name, size_t n, size_t m, double *d);
630 
631  /// Get an integer matrix \c i pre-allocated to have size <tt>(n,m)</tt>
632  int geti_mat_prealloc(std::string name, size_t n, size_t m, int *i);
633  //@}
634 
635  /// \name Find a group
636  //@{
637  /** \brief Look in hdf_file \c hf for an \o2 object of type \c
638  type and if found, set \c group_name to the associated object
639  name
640 
641  This function returns 1 if an object of type \c type is found
642  and 0 if it fails.
643  */
644  int find_group_by_type(hdf_file &hf, std::string type,
645  std::string &group_name, int verbose=0);
646 
647  /** \brief Look in hdf_file \c hf for an \o2 object with name
648  \c name and if found, set \c type to the associated type
649 
650  This function returns 1 if an object with name \c name is
651  found and 0 if it fails.
652  */
653  int find_group_by_name(hdf_file &hf, std::string name,
654  std::string &type, int verbose=0);
655  //@}
656 
657 #ifndef DOXYGEN_INTERNAL
658 
659  private:
660 
661  /*
662  In principle, one might be able to copy the IDs, but then we'd
663  have to worry about the possibility that the file would be
664  closed twice.
665  */
666  hdf_file(const hdf_file &);
667  hdf_file& operator=(const hdf_file&);
668 
669 #endif
670 
671  };
672 
673  /// \name Helper functions
674  //@{
675  /** \brief An internal structure to pass information to and
676  from \ref iterate_match_type() and \ref iterate_match_name()
677  */
678  typedef struct {
679  hdf_file *hf;
680  std::string type;
681  std::string group_name;
682  bool found;
683  int verbose;
684  } iterate_parms;
685 
686  /** \brief Look at location \c loc in an HDF file for an \o2 object
687  of a specified type
688 
689  This is used by \ref hdf_file::find_group_by_type() where \c
690  op_data is a pointer to an object of type \ref iterate_parms to
691  look for \o2 objects of a specified type without knowing the
692  group name.
693  */
694  int iterate_match_type(hid_t loc, const char *name,
695  const H5L_info_t *inf, void *op_data);
696 
697  /** \brief Look at location \c loc in an HDF file for an \o2 object
698  with a specified name
699 
700  This is used by \ref hdf_file::find_group_by_name() where \c
701  op_data is a pointer to an object of type \ref iterate_parms to
702  look for \o2 objects with a specified name without knowing the
703  type.
704  */
705  int iterate_match_name(hid_t loc, const char *name,
706  const H5L_info_t *inf, void *op_data);
707  //@}
708 
709 }
710 
711 #endif
int getf_arr_alloc(std::string name, size_t &n, float *f)
Get a float array named name of size n.
int seti_vec_copy(std::string name, vec_int_t &v)
Set vector dataset named name with v.
Definition: hdf_file.h:374
int getd_ten_copy(std::string name, o2scl::tensor< vec_t, vec_size_t > &t)
Get a tensor from an HDF file.
Definition: hdf_file.h:457
int open(std::string fname, bool err_on_fail=true)
Open a file named fname.
hid_t current
Current file or group location.
Definition: hdf_file.h:113
int getd_vec(std::string name, std::vector< double > &v)
Get vector dataset and place data in v.
int setd_mat_copy(std::string name, const ubmatrix &m)
Set matrix dataset named name with m.
int setd_vec_copy(std::string name, const vec_t &v)
Set vector dataset named name with v.
Definition: hdf_file.h:354
int setd_vec(std::string name, const std::vector< double > &v)
Set vector dataset named name with v.
int setd_arr(std::string name, size_t n, const double *d)
Set a double array named name of size n to value d.
int geti(std::string name, int &i)
Get a integer named name.
int getd_arr(std::string name, size_t n, double *d)
Get a double array named name of size n.
int set_szt_vec(std::string name, const std::vector< size_t > &v)
Set vector dataset named name with v.
int get_szt_def(std::string name, size_t def, size_t &i)
Get a size_t named name.
int getf_arr(std::string name, size_t n, float *f)
Get a float array named name of size n.
void close()
Close the file.
void set_szt(std::string name, size_t u)
Set an unsigned integer named name to value u.
int getd(std::string name, double &d)
Get a double named name.
void setd(std::string name, double d)
Set a double named name to value d.
int gets_def(std::string name, std::string def, std::string &s)
Get a string named name.
int find_group_by_name(hdf_file &hf, 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...
bool file_open
True if a file has been opened.
Definition: hdf_file.h:110
int setf_arr(std::string name, size_t n, const float *f)
Set a float array named name of size n to value f.
int iterate_match_name(hid_t loc, const char *name, const H5L_info_t *inf, void *op_data)
Look at location loc in an HDF file for an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl object with a specified name.
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.
int getd_ten(std::string name, o2scl::tensor< std::vector< double >, std::vector< size_t > > &t)
Get a tensor from an HDF file.
int getc_arr(std::string name, size_t n, char *c)
Get a character array named name of size n.
int getc_arr_alloc(std::string name, size_t &n, char *c)
Get a character array named name of size n.
void seti(std::string name, int i)
Set an integer named name to value i.
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.
void sets_fixed(std::string name, std::string s)
Set a fixed-length string named name to value s.
int geti_vec_copy(std::string name, vec_int_t &v)
Get vector dataset and place data in v.
Definition: hdf_file.h:311
int geti_arr_alloc(std::string name, size_t &n, int *i)
Get an integer array named name of size n.
int geti_arr(std::string name, size_t n, int *i)
Get an integer array named name of size n.
int iterate_match_type(hid_t loc, const char *name, const H5L_info_t *inf, void *op_data)
Look at location loc in an HDF file for an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl object of a specified type.
int get_szt(std::string name, size_t &u)
Get an unsigned integer named name.
hid_t get_current_id()
Retrieve the current working id.
int getf_def(std::string name, float def, float &f)
Get a float named name.
An internal structure to pass information to and from iterate_match_type() and iterate_match_name() ...
Definition: hdf_file.h:678
int getd_vec_prealloc(std::string name, size_t n, double *d)
Get a double array d pre-allocated to have size n.
int geti_vec(std::string name, std::vector< int > &v)
Get vector dataset and place data in v.
void sets(std::string name, std::string s)
Set a string named name to value s.
int setd_ten_copy(std::string name, const o2scl::tensor< std::vector< double >, std::vector< size_t > > &t)
Write a tensor to an HDF file.
Definition: hdf_file.h:482
int close_group(hid_t group)
Close a previously created group.
Definition: hdf_file.h:266
int getf(std::string name, float &f)
Get a float named name.
int gets_fixed(std::string name, std::string &s)
Get a fixed-length string named name.
int setc_arr(std::string name, size_t n, const char *c)
Set a character array named name of size n to value c.
int geti_def(std::string name, int def, int &i)
Get a integer named name.
void open_or_create(std::string fname)
Open a file named fname or create if it doesn't already exist.
int getd_mat_copy(std::string name, ubmatrix &m)
Get matrix dataset and place data in m.
int seti_vec(std::string name, const std::vector< int > &v)
Set vector dataset named name with v.
int set_szt_vec_copy(std::string name, vec_size_t &v)
Set vector dataset named name with v.
Definition: hdf_file.h:393
int setd_ten(std::string name, const o2scl::tensor< std::vector< double >, std::vector< size_t > > &t)
Write a tensor to an HDF file.
void set_current_id(hid_t cur)
Set the current working id.
int geti_vec_prealloc(std::string name, size_t n, int *i)
Get an integer array i pre-allocated to have size n.
int getd_def(std::string name, double def, double &d)
Get a double named name.
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.
int compr_type
Desc.
Definition: hdf_file.h:137
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)
int find_group_by_type(hdf_file &hf, std::string type, std::string &group_name, int verbose=0)
Look in hdf_file hf for an O<span style='position: relative; top: 0.3em; font-size: 0...
int geti_mat_copy(std::string name, ubmatrix_int &m)
Get matrix dataset and place data in m.
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)
hid_t file
File ID.
Definition: hdf_file.h:107
virtual hsize_t def_chunk(size_t n)
Default chunk size.
Definition: hdf_file.h:120
hid_t get_file_id()
Get the current file id.
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl...
Definition: hdf_file.h:93
int sets_vec(std::string name, std::vector< std::string > &s)
Set a vector of strings named name.
int getc(std::string name, char &c)
Get a character named name.
int gets_vec(std::string name, std::vector< std::string > &s)
Get a vector of strings named name and store it in s.
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.
void vector_copy(vec_t &src, vec2_t &dest)
Simple generic vector copy.
Definition: vector.h:73
void setc(std::string name, char c)
Set a character named name to value c.
int gets(std::string name, std::string &s)
Get a string named name.
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.
int getd_vec_copy(std::string name, vec_t &v)
Get vector dataset and place data in v.
Definition: hdf_file.h:295
int get_szt_vec_copy(std::string name, vec_size_t &v)
Get vector dataset and place data in v.
Definition: hdf_file.h:326
void setf(std::string name, float f)
Set a float named name to value f.
int gets_def_fixed(std::string name, std::string def, std::string &s)
Get a fixed-length string named name with default value s.
int get_szt_vec(std::string name, std::vector< size_t > &v)
Get vector dataset and place data in v.
int getd_arr_alloc(std::string name, size_t &n, double *d)
Get a double array named name of size n.
int seti_arr(std::string name, size_t n, const int *i)
Set a integer array named name of size n to value i.
Tensor class with arbitrary dimensions.
Definition: tensor.h:121
hid_t open_group(hid_t init_id, std::string path)
Open a group relative to the location specified in init_id.
int getc_def(std::string name, char def, char &c)
Get a character named name.

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..