hdf_io.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_IO_H
24 #define O2SCL_HDF_IO_H
25 
26 /** \file hdf_io.h
27  \brief File defining HDF I/O for selected \o2 objects
28 */
29 #include <boost/numeric/ublas/vector.hpp>
30 
31 #include <fnmatch.h>
32 
33 #include <o2scl/hdf_file.h>
34 #include <o2scl/table.h>
35 #include <o2scl/table_units.h>
36 #include <o2scl/hist.h>
37 #include <o2scl/hist_2d.h>
38 #include <o2scl/table3d.h>
39 #include <o2scl/tensor_grid.h>
40 #include <o2scl/expval.h>
41 #include <o2scl/contour.h>
42 #include <o2scl/uniform_grid.h>
43 #include <o2scl/prob_dens_mdim_amr.h>
44 
45 /** \brief The \o2 namespace for I/O with HDF
46  */
47 namespace o2scl_hdf {
48 
49  /** \brief Input a \ref o2scl::prob_dens_mdim_amr object from a
50  \ref hdf_file
51  */
52  template<class vec_t, class mat_t>
53  void hdf_input(hdf_file &hf,
55  std::string name) {
56 
57  // If no name specified, find name of first group of specified type
58  if (name.length()==0) {
59  hf.find_object_by_type("prob_dens_mdim_amr",name);
60  if (name.length()==0) {
61  O2SCL_ERR2("No object of type prob_dens_mdim_amr found in ",
62  "o2scl_hdf::hdf_input().",o2scl::exc_efailed);
63  }
64  }
65 
66  // Open main group
67  hid_t top=hf.get_current_id();
68  hid_t group=hf.open_group(name);
69  hf.set_current_id(group);
70 
71  size_t nd, dc, ms;
72  std::vector<double> data;
73  std::vector<size_t> insides;
74 
75  hf.get_szt("n_dim",nd);
76  hf.get_szt("dim_choice",dc);
77  hf.get_szt("mesh_size",ms);
78  hf.getd_vec("data",data);
79  hf.get_szt_vec("insides",insides);
80 
81  p.set_from_vectors(nd,dc,ms,data,insides);
82 
83  // Close group
84  hf.close_group(group);
85 
86  // Return location to previous value
87  hf.set_current_id(top);
88 
89  return;
90  }
91 
92  /** \brief Output a \ref o2scl::prob_dens_mdim_amr
93  object to a \ref hdf_file
94  */
95  template<class vec_t, class mat_t>
96  void hdf_output(hdf_file &hf,
98  std::string name) {
99 
100  if (hf.has_write_access()==false) {
101  O2SCL_ERR2("File not opened with write access in hdf_output",
102  "(hdf_file,prob_dens_mdim_amr<>,string).",
104  }
105 
106  // Start group
107  hid_t top=hf.get_current_id();
108  hid_t group=hf.open_group(name);
109  hf.set_current_id(group);
110 
111  // Add typename
112  hf.sets_fixed("o2scl_type","prob_dens_mdim_amr");
113 
114  size_t nd, dc, ms;
115  std::vector<double> data;
116  std::vector<size_t> insides;
117 
118  p.copy_to_vectors(nd,dc,ms,data,insides);
119 
120  hf.set_szt("n_dim",nd);
121  hf.set_szt("dim_choice",dc);
122  hf.set_szt("mesh_size",ms);
123  hf.setd_vec("data",data);
124  hf.set_szt_vec("insides",insides);
125 
126  // Close table_units group
127  hf.close_group(group);
128 
129  // Return location to previous value
130  hf.set_current_id(top);
131 
132  return;
133  }
134 
135  /** \brief Output a \ref o2scl::table object to a \ref hdf_file
136  */
137  void hdf_output(hdf_file &hf, o2scl::table<> &t, std::string name);
138 
139 #ifndef O2SCL_NO_HDF_INPUT
140  /** \brief Input a \ref o2scl::table object from a \ref hdf_file
141 
142  \comment
143  Note that a default value is not allowed here because this
144  is a template function
145  \endcomment
146  */
147  template<class vec_t>
148  void hdf_input(hdf_file &hf, o2scl::table<vec_t> &t, std::string name) {
149 
150  // If no name specified, find name of first group of specified type
151  if (name.length()==0) {
152  hf.find_object_by_type("table",name);
153  if (name.length()==0) {
154  O2SCL_ERR2("No object of type table found in ",
155  "o2scl_hdf::hdf_input().",o2scl::exc_efailed);
156  }
157  }
158 
159  // Open main group
160  hid_t top=hf.get_current_id();
161  hid_t group=hf.open_group(name);
162  hf.set_current_id(group);
163 
164  // Input the table data
165  hdf_input_data(hf,t);
166 
167  // Close group
168  hf.close_group(group);
169 
170  // Return location to previous value
171  hf.set_current_id(top);
172 
173  t.check_synchro();
174 
175  return;
176  }
177 #endif
178 
179  /** \brief Internal function for outputting a \ref o2scl::table object
180  */
181  void hdf_output_data(hdf_file &hf, o2scl::table<> &t);
182 
183  /** \brief Internal function for inputting a \ref o2scl::table object
184  */
185  template<class vec_t>
187  hid_t group=hf.get_current_id();
188 
189  // Clear previous data
190  t.clear_table();
191  t.clear_constants();
192 
193  // Check typename
194  std::string type2;
195  hf.gets_fixed("o2scl_type",type2);
196  if (type2!="table") {
197  O2SCL_ERR2("Typename in HDF group does not match ",
198  "class in o2scl_hdf::hdf_input_data().",o2scl::exc_einval);
199  }
200 
201  // Storage
202  std::vector<std::string> cnames, cols;
203  typedef boost::numeric::ublas::vector<double> ubvector;
204  ubvector cvalues;
205 
206  // Get constants
207  hf.gets_vec("con_names",cnames);
208  hf.getd_vec_copy("con_values",cvalues);
209  if (cnames.size()!=cvalues.size()) {
210  O2SCL_ERR2("Size mismatch between constant names and values ",
211  "in o2scl_hdf::hdf_input_data().",o2scl::exc_einval);
212  }
213  for(size_t i=0;i<cnames.size();i++) {
214  t.add_constant(cnames[i],cvalues[i]);
215  }
216 
217  // Get column names
218  hf.gets_vec("col_names",cols);
219  for(size_t i=0;i<cols.size();i++) {
220  t.new_column(cols[i]);
221  }
222 
223  // Get number of lines
224  int nlines2;
225  hf.geti("nlines",nlines2);
226  t.set_nlines(nlines2);
227 
228  // Output the interpolation type
229  hf.get_szt_def("itype",o2scl::itp_cspline,t.itype);
230 
231  // Open data group
232  hid_t group2=hf.open_group("data");
233  hf.set_current_id(group2);
234 
235  if (nlines2>0) {
236 
237  // Get data
238  for(size_t i=0;i<t.get_ncolumns();i++) {
239  ubvector vtmp(nlines2);
240  hf.getd_vec_copy(t.get_column_name(i),vtmp);
241  for(int j=0;j<nlines2;j++) {
242  t.set(t.get_column_name(i),j,vtmp[j]);
243  }
244  }
245 
246  }
247 
248  // Close groups
249  hf.close_group(group2);
250 
251  hf.set_current_id(group);
252 
253  // Check that input created a valid table
254  t.check_synchro();
255 
256  return;
257  }
258 
259  /** \brief Output a \ref o2scl::table_units object to a \ref hdf_file
260  */
261  void hdf_output(hdf_file &hf, o2scl::table_units<> &t,
262  std::string name);
263 
264  /** \brief Input a \ref o2scl::table_units object from a \ref hdf_file
265 
266  \comment
267  Note that a default value is not allowed here because this
268  is a template function
269  \endcomment
270  */
271  template<class vec_t>
273  std::string name) {
274 
275  // If no name specified, find name of first group of specified type
276  if (name.length()==0) {
277  hf.find_object_by_type("table",name);
278  if (name.length()==0) {
279  O2SCL_ERR2("No object of type table found in ",
280  "o2scl_hdf::hdf_input().",o2scl::exc_efailed);
281  }
282  }
283 
284  // Open main group
285  hid_t top=hf.get_current_id();
286  hid_t group=hf.open_group(name);
287  hf.set_current_id(group);
288 
289  // Input the table_units data
290  hdf_input_data(hf,t);
291 
292  // Close group
293  hf.close_group(group);
294 
295  // Return location to previous value
296  hf.set_current_id(top);
297 
298  t.check_synchro();
299 
300  return;
301  }
302 
303  /** \brief Internal function for outputting a \ref o2scl::table_units object
304  */
305  void hdf_output_data(hdf_file &hf, o2scl::table_units<> &t);
306 
307  /** \brief Internal function for inputting a \ref o2scl::table_units object
308  */
309  template<class vec_t>
311  // Input base table object
312  o2scl::table<vec_t> *tbase=dynamic_cast<o2scl::table_units<vec_t> *>(&t);
313  if (tbase==0) {
314  O2SCL_ERR2("Cast failed in hdf_input_data",
315  "(hdf_file &, table_units &).",o2scl::exc_efailed);
316  }
317  hdf_input_data(hf,*tbase);
318 
319  // Get unit flag
320  int uf;
321  hf.geti("unit_flag",uf);
322 
323  // If present, get units
324  if (uf>0) {
325  std::vector<std::string> units;
326  hf.gets_vec("units",units);
327  for(size_t i=0;i<units.size();i++) {
328  t.set_unit(t.get_column_name(i),units[i]);
329  }
330  }
331 
332  return;
333  }
334 
335  /// Output a \ref o2scl::hist object to a \ref hdf_file
336  void hdf_output(hdf_file &hf, o2scl::hist &h, std::string name);
337  /// Input a \ref o2scl::hist object from a \ref hdf_file
338  void hdf_input(hdf_file &hf, o2scl::hist &h, std::string name="");
339  /// Output a \ref o2scl::hist_2d object to a \ref hdf_file
340  void hdf_output(hdf_file &hf, const o2scl::hist_2d &h, std::string name);
341  /// Input a \ref o2scl::hist_2d object from a \ref hdf_file
342  void hdf_input(hdf_file &hf, o2scl::hist_2d &h, std::string name="");
343  /// Output a \ref o2scl::table3d object to a \ref hdf_file
344  void hdf_output(hdf_file &hf, const o2scl::table3d &h, std::string name);
345  /// Input a \ref o2scl::table3d object from a \ref hdf_file
346  void hdf_input(hdf_file &hf, o2scl::table3d &h, std::string name="");
347  /// Output a \ref o2scl::expval_scalar object to a \ref hdf_file
348  void hdf_output(hdf_file &hf, o2scl::expval_scalar &h,
349  std::string name);
350  /// Input a \ref o2scl::expval_scalar object from a \ref hdf_file
351  void hdf_input(hdf_file &hf, o2scl::expval_scalar &h,
352  std::string name="");
353  /// Output a \ref o2scl::expval_vector object to a \ref hdf_file
354  void hdf_output(hdf_file &hf, o2scl::expval_vector &h,
355  std::string name);
356  /// Input a \ref o2scl::expval_vector object from a \ref hdf_file
357  void hdf_input(hdf_file &hf, o2scl::expval_vector &h, std::string name="");
358  /// Output a \ref o2scl::expval_matrix object to a \ref hdf_file
359  void hdf_output(hdf_file &hf, o2scl::expval_matrix &h,
360  std::string name);
361  /// Input a \ref o2scl::expval_matrix object from a \ref hdf_file
362  void hdf_input(hdf_file &hf, o2scl::expval_matrix &h, std::string name="");
363  /// Output a \ref o2scl::uniform_grid object to a \ref hdf_file
364  void hdf_output(hdf_file &hf, o2scl::uniform_grid<double> &h,
365  std::string name);
366  /// Input a \ref o2scl::uniform_grid object from a \ref hdf_file
367  void hdf_input(hdf_file &hf, o2scl::uniform_grid<double> &h,
368  std::string name="");
369  /// Output a vector of \ref o2scl::contour_line objects to a \ref hdf_file
370  void hdf_output(hdf_file &hf, const std::vector<o2scl::contour_line> &cl,
371  std::string name);
372  /// Input a vector of \ref o2scl::contour_line objects from a \ref hdf_file
373  void hdf_input(hdf_file &hf, std::vector<o2scl::contour_line> &cl,
374  std::string name="");
375  /// Output a vector of \ref o2scl::edge_crossings objects to a \ref hdf_file
376  void hdf_output(hdf_file &hf, const std::vector<o2scl::edge_crossings> &ec,
377  std::string name);
378  /// Input a vector of \ref o2scl::edge_crossings objects from a \ref hdf_file
379  void hdf_input(hdf_file &hf, std::vector<o2scl::edge_crossings> &ec,
380  std::string name="");
381  /// Output a \ref o2scl::tensor_grid object to a \ref hdf_file
382  void hdf_output(hdf_file &hf, o2scl::tensor_grid<std::vector<double>,
383  std::vector<size_t> > &t, std::string name);
384  /// Input a \ref o2scl::tensor_grid object from a \ref hdf_file
385  void hdf_input(hdf_file &hf, o2scl::tensor_grid<std::vector<double>,
386  std::vector<size_t> > &t, std::string name="");
387 
388  /** \brief A value specified by a string
389 
390  Formats:
391  - func: <function>
392  - HDF5 object in file:
393  hdf5:<file name>:<object name>:[additional specification]
394 
395  \todo shell: option to use the result of a shell command
396 
397  \note unfinished.
398  */
399  int value_spec(std::string spec, double &d,
400  int verbose=0, bool err_on_fail=true);
401 
402  /** \brief A vector specified by a string
403 
404  Formats:
405  - single value: val:<value>
406  - list of values: list:<entry 0>,<entry 1>, ...,<entry n-1>
407  - function: func:<N>:<function of i>
408  - grid: grid:<begin>:<end>:<width>:["log"]
409  - column in text file: text:<filename>:<column index>
410  - HDF5 object in file:
411  hdf5:<file name>:<object name>:[additional specification]
412 
413  Filenames are expanded using wordexp() and HDF5 object names
414  are expanded using fnmatch() .
415 
416  Additional specifications
417  - table: <column>
418  */
419  template<class vec_t> int vector_spec(std::string spec, vec_t &v,
420  int verbose=0,
421  bool err_on_fail=true) {
422 
423  if (verbose>2) {
424  std::cout << "Function vector_spec is parsing: " << spec << std::endl;
425  }
426 
427  if (spec.find("val:")==0) {
428 
429  std::string temp=spec.substr(4,spec.length()-4);
430  if (verbose>1) {
431  std::cout << "vector_spec(): single value " << temp
432  << std::endl;
433  }
434  v.resize(1);
435  v[0]=o2scl::function_to_double(temp);
436 
437  } else if (spec.find("list:")==0) {
438 
439  // List
440  std::string list=spec.substr(5,spec.length()-5);
441  std::vector<std::string> sv;
442  o2scl::split_string_delim(list,sv,',');
443  size_t n=sv.size();
444  if (n==0) {
445  if (err_on_fail) {
446  O2SCL_ERR2("String split failed, spec empty? ",
447  "in vector_spec().",o2scl::exc_einval);
448  } else {
449  return 10;
450  }
451  }
452  if (verbose>1) {
453  std::cout << "vector_spec(): List " << list << std::endl;
454  std::cout << n << " " << sv[0] << " " << sv[n-1] << std::endl;
455  }
456  v.resize(n);
457  for(size_t i=0;i<n;i++) {
458  v[i]=o2scl::function_to_double(sv[i]);
459  }
460 
461  } else if (spec.find("func:")==0) {
462 
463  // Function
464  if (verbose>1) {
465  std::cout << "vector_spec(): Function " << spec << std::endl;
466  }
467  std::string temp=spec.substr(5,spec.length()-5);
468  size_t ncolon=temp.find(':');
469  if (ncolon==std::string::npos) {
470  if (err_on_fail) {
471  O2SCL_ERR2("Function specified but no array length specified ",
472  "in vector_spec().",o2scl::exc_einval);
473  } else {
474  return 1;
475  }
476  }
477  size_t n;
478  int cret=o2scl::stoszt_nothrow(temp.substr(0,ncolon),n);
479  if (cret!=0) {
480  if (err_on_fail) {
481  O2SCL_ERR2("Conversion to size_t failed ",
482  "in vector_spec().",o2scl::exc_einval);
483  } else {
484  return 2;
485  }
486  }
487  if (verbose>1) {
488  std::cout << "Size " << n << std::endl;
489  }
490  if (temp.length()<ncolon+1) {
491  if (err_on_fail) {
492  O2SCL_ERR2("No apparent function specified ",
493  "in vector_spec().",o2scl::exc_einval);
494  } else {
495  return 3;
496  }
497  }
498  std::string func=temp.substr(ncolon+1,temp.length()-ncolon-1);
499  if (verbose>1) {
500  std::cout << "Function " << func << std::endl;
501  }
502  o2scl::calculator calc;
503  std::map<std::string,double> vars;
504  calc.compile(func.c_str(),&vars);
505  v.resize(n);
506  for(size_t i=0;i<n;i++) {
507  vars["i"]=((double)i);
508  v[i]=calc.eval(&vars);
509  }
510 
511  } else if (spec.find("grid:")==0) {
512 
513  // Grid
514  if (verbose>1) {
515  std::cout << "vector_spec(): Grid " << spec << std::endl;
516  }
517 
518  std::string temp=spec.substr(5,spec.length()-5);
519 
520  std::vector<std::string> sv;
521  o2scl::split_string_delim(temp,sv,',');
522  if (sv.size()<3) {
523  if (err_on_fail) {
524  O2SCL_ERR2("Not enough information for grid ",
525  "in vector_spec().",o2scl::exc_einval);
526  } else {
527  return 7;
528  }
529  }
530  if (verbose>1) {
531  std::cout << "Begin,end,width "
532  << sv[0] << " " << sv[1] << " " << sv[2] << std::endl;
533  }
534  if (sv.size()>=4 && sv[3]=="log") {
536  ug(o2scl::function_to_double(sv[0]),
539  ug.vector(v);
540  } else {
542  ug(o2scl::function_to_double(sv[0]),
545  ug.vector(v);
546  }
547 
548  } else if (spec.find("text:")==0) {
549 
550  // Text
551  if (verbose>1) {
552  std::cout << "vector_spec(): Text " << spec << std::endl;
553  }
554 
555  std::vector<std::string> sv;
556  o2scl::split_string_delim(spec,sv,':');
557 
558  if (sv.size()<3) {
559  if (err_on_fail) {
560  O2SCL_ERR2("Not enough information for text file ",
561  "in vector_spec().",o2scl::exc_einval);
562  } else {
563  return 12;
564  }
565  }
566 
567  // The column index is 'col'
568  int col=o2scl::stoi(sv[2]);
569  if (verbose>1) {
570  std::cout << "Filename,column " << sv[1] << " " << col << std::endl;
571  }
572  if (col<0) {
573  if (err_on_fail) {
574  O2SCL_ERR2("Column is negative for text file ",
575  "in vector_spec().",o2scl::exc_einval);
576  } else {
577  return 13;
578  }
579  }
580 
581  // Open the file
582  std::ifstream fin;
583  fin.open(sv[1].c_str());
584 
585  // Read the header, if there is any
586  std::string line, word;
587  bool in_header=true;
588  do {
589  getline(fin,line);
590  std::istringstream is(line);
591  int i=0;
592  for(;i<=col && (is >> word) && in_header;i++) {
593  if (i==col && o2scl::is_number(word)) {
594  in_header=false;
595  }
596  if (i==col && verbose>2) {
597  if (in_header) {
598  std::cout << "Word: " << word << " header." << std::endl;
599  } else {
600  std::cout << "Word: " << word << " start of data."
601  << std::endl;
602  }
603  }
604  }
605  } while (in_header && !fin.eof());
606 
607  // If we got to the end of the file and there wasn't
608  // any data then call the error handler.
609  if (in_header) {
610  if (err_on_fail) {
611  O2SCL_ERR2("Couldn't find a number in text file ",
612  "in vector_spec().",o2scl::exc_einval);
613  } else {
614  return 13;
615  }
616  }
617 
618  // Now store the data in a temporary vector
619  std::vector<double> tempv;
620  bool end_of_data=false;
621  do {
622  tempv.push_back(o2scl::stod(word));
623 
624  getline(fin,line);
625  std::istringstream is(line);
626  for(int i=0;i<=col;i++) {
627  if (!(is >> word)) {
628  i=col;
629  end_of_data=true;
630  }
631  }
632  if (!o2scl::is_number(word)) end_of_data=true;
633 
634  } while (!end_of_data && !fin.eof());
635 
636  // Close the file
637  fin.close();
638 
639  // Copy the data back to the user-specified vector
640  v.resize(tempv.size());
641  for(size_t i=0;i<tempv.size();i++) {
642  v[i]=tempv[i];
643  }
644 
645  } else if (spec.find("hdf5:")==0) {
646 
647  // HDF5 object in a file
648  if (verbose>1) {
649  std::cout << "vector_spec(): HDF5 file " << spec << std::endl;
650  }
651  std::string temp=spec.substr(5,spec.length()-5);
652  size_t ncolon=temp.find(':');
653  if (ncolon==std::string::npos) {
654  if (err_on_fail) {
655  O2SCL_ERR2("No apparent object name specified ",
656  "in vector_spec().",o2scl::exc_einval);
657  } else {
658  return 4;
659  }
660  }
661  std::string fname=temp.substr(0,ncolon);
662  if (verbose>1) {
663  std::cout << "Filename " << fname << std::endl;
664  }
665  if (temp.length()<ncolon+1) {
666  if (err_on_fail) {
667  O2SCL_ERR2("No apparent object name specified ",
668  "in vector_spec().",o2scl::exc_einval);
669  } else {
670  return 5;
671  }
672  }
673  std::string obj_name=temp.substr(ncolon+1,temp.length()-ncolon-1);
674  std::string addl_spec;
675  ncolon=obj_name.find(':');
676  if (ncolon!=std::string::npos) {
677  addl_spec=obj_name.substr(ncolon+1,obj_name.length()-ncolon-1);
678  obj_name=obj_name.substr(0,ncolon);
679  }
680  if (verbose>1) {
681  std::cout << "Object name " << obj_name << std::endl;
682  std::cout << "Additional specification " << addl_spec << std::endl;
683  }
685 
686  std::string fname_old=fname;
687  std::vector<std::string> matches;
688  int wret=o2scl::wordexp_wrapper(fname_old,matches);
689  if (matches.size()>1 || matches.size()==0 || wret!=0) {
690  if (err_on_fail) {
691  O2SCL_ERR2("Function wordexp_wrapper() failed ",
692  "in vector_spec().",o2scl::exc_einval);
693  } else {
694  return 9;
695  }
696  }
697  fname=matches[0];
698  if (verbose>1) {
699  std::cout << "Filename after wordexp() " << fname << std::endl;
700  }
701 
702  hf.open(fname);
703  std::string type;
704  int find_ret=hf.find_object_by_name(obj_name,type);
705  if (find_ret!=0) {
706  if (err_on_fail) {
707  O2SCL_ERR2("Object not found in file ",
708  "in vector_spec().",o2scl::exc_einval);
709  } else {
710  return 11;
711  }
712  }
713  if (verbose>1) {
714  std::cout << "Object type from file: " << type << std::endl;
715  }
716 
717  if (type=="table") {
718  if (addl_spec.length()==0) {
719  if (err_on_fail) {
720  O2SCL_ERR2("No table column name specified ",
721  "in vector_spec().",o2scl::exc_einval);
722  } else {
723  return 6;
724  }
725  }
727  o2scl_hdf::hdf_input(hf,t,obj_name);
728  v.resize(t.get_nlines());
729  for(size_t i=0;i<t.get_nlines();i++) {
730  v[i]=t.get(addl_spec,i);
731  }
732  } else if (type=="double[]") {
733  std::vector<double> vtemp;
734  hf.getd_vec(obj_name,vtemp);
735  v.resize(vtemp.size());
736  for(size_t i=0;i<v.size();i++) {
737  v[i]=vtemp[i];
738  }
739  } else if (type=="hist") {
740  o2scl::hist ht;
741  hdf_input(hf,ht,obj_name);
742  typedef boost::numeric::ublas::vector<double> ubvector;
743  const ubvector &wgts=ht.get_wgts();
744  v.resize(wgts.size());
745  for(size_t i=0;i<v.size();i++) {
746  v[i]=wgts[i];
747  }
748  } else if (type=="int[]") {
749  std::vector<int> vtemp;
750  hf.geti_vec(obj_name,vtemp);
751  v.resize(vtemp.size());
752  for(size_t i=0;i<v.size();i++) {
753  v[i]=vtemp[i];
754  }
755  } else if (type=="size_t[]") {
756  std::vector<size_t> vtemp;
757  hf.get_szt_vec(obj_name,vtemp);
758  v.resize(vtemp.size());
759  for(size_t i=0;i<v.size();i++) {
760  v[i]=vtemp[i];
761  }
762  } else if (type=="uniform_grid<double>") {
764  hdf_input(hf,ug,obj_name);
765  std::vector<double> vtemp;
766  ug.vector(vtemp);
767  v.resize(vtemp.size());
768  for(size_t i=0;i<v.size();i++) {
769  v[i]=vtemp[i];
770  }
771  } else if (type=="int") {
772  int itemp;
773  hf.geti(obj_name,itemp);
774  v.resize(1);
775  v[0]=itemp;
776  } else if (type=="double") {
777  double dtemp;
778  hf.getd(obj_name,dtemp);
779  v.resize(1);
780  v[0]=dtemp;
781  } else if (type=="size_t") {
782  size_t szttemp;
783  hf.get_szt(obj_name,szttemp);
784  v.resize(1);
785  v[0]=szttemp;
786  }
787  hf.close();
788 
789  } else {
790 
791  if (verbose>0) {
792  std::cout << "Could not understand prefix in vector_spec()."
793  << std::endl;
794  }
795 
796  if (err_on_fail) {
797  O2SCL_ERR2("Could not parse specification ",
798  "in vector_spec().",o2scl::exc_einval);
799  } else {
800  return 8;
801  }
802 
803  }
804  return 0;
805  }
806 
807  /** \brief Desc
808  */
809  template<class vec_t> int strings_spec(std::string spec, vec_t &v,
810  int verbose=0,
811  bool err_on_fail=true) {
812 
813  if (verbose>2) {
814  std::cout << "Function strings_spec is parsing: " << spec << std::endl;
815  }
816 
817  if (spec.find("list:")==0) {
818 
819  // List
820  std::string list=spec.substr(5,spec.length()-5);
821  std::vector<std::string> sv;
822  o2scl::split_string_delim(list,sv,',');
823  size_t n=sv.size();
824  if (n==0) {
825  if (err_on_fail) {
826  O2SCL_ERR2("String split failed, spec empty? ",
827  "in strings_spec().",o2scl::exc_einval);
828  } else {
829  return 10;
830  }
831  }
832  if (verbose>1) {
833  std::cout << "strings_spec(): List " << list << std::endl;
834  std::cout << n << " " << sv[0] << " " << sv[n-1] << std::endl;
835  }
836  v.resize(n);
837  for(size_t i=0;i<n;i++) {
838  v[i]=sv[i];
839  }
840 
841  } else if (spec.find("shell:")==0) {
842 
843  // Result from shell command
844 
845 #ifdef HAVE_POPEN
846 
847  std::string cmd=spec.substr(6,spec.length()-6);
848  std::cout << "Using shell command: " << cmd << std::endl;
849  FILE *ps_pipe=popen(cmd.c_str(),"r");
850  if (!ps_pipe) {
851  if (err_on_fail) {
852  O2SCL_ERR2("Pipe could not be opened in ",
853  "convert_units::convert_gnu_units().",
855  }
857  }
858 
859  char line1[255];
860  char *cret=fgets(line1,255,ps_pipe);
861  v.clear();
862  while (cret!=0) {
863  std::string sline1=line1;
864  if (sline1[sline1.length()-1]=='\n') {
865  sline1=sline1.substr(0,sline1.length()-1);
866  }
867  if (verbose>0) {
868  std::cout << "Read line "
869  << sline1 << std::endl;
870  }
871  v.push_back(sline1);
872  cret=fgets(line1,255,ps_pipe);
873  }
874 
875  if (pclose(ps_pipe)!=0) {
876  if (err_on_fail) {
877  O2SCL_ERR2("Pipe could not be closed in ",
878  "value_spec().",o2scl::exc_efailed);
879  }
880  return o2scl::exc_efailed;
881  }
882 
883 #endif
884 
885  return o2scl::exc_efailed;
886 
887  } else if (spec.find("hdf5:")==0) {
888 
889  // HDF5 object in a file
890  if (verbose>1) {
891  std::cout << "strings_spec(): HDF5 file " << spec << std::endl;
892  }
893  std::string temp=spec.substr(5,spec.length()-5);
894  size_t ncolon=temp.find(':');
895  if (ncolon==std::string::npos) {
896  if (err_on_fail) {
897  O2SCL_ERR2("No apparent object name specified ",
898  "in strings_spec().",o2scl::exc_einval);
899  } else {
900  return 4;
901  }
902  }
903  std::string fname=temp.substr(0,ncolon);
904  if (verbose>1) {
905  std::cout << "Filename " << fname << std::endl;
906  }
907  if (temp.length()<ncolon+1) {
908  if (err_on_fail) {
909  O2SCL_ERR2("No apparent object name specified ",
910  "in strings_spec().",o2scl::exc_einval);
911  } else {
912  return 5;
913  }
914  }
915  std::string obj_name=temp.substr(ncolon+1,temp.length()-ncolon-1);
916  std::string addl_spec;
917  ncolon=obj_name.find(':');
918  if (ncolon!=std::string::npos) {
919  addl_spec=obj_name.substr(ncolon+1,obj_name.length()-ncolon-1);
920  obj_name=obj_name.substr(0,ncolon);
921  }
922  if (verbose>1) {
923  std::cout << "Object name " << obj_name << std::endl;
924  std::cout << "Additional specification " << addl_spec << std::endl;
925  }
927 
928  std::string fname_old=fname;
929  std::vector<std::string> matches;
930  int wret=o2scl::wordexp_wrapper(fname_old,matches);
931  if (matches.size()>1 || matches.size()==0 || wret!=0) {
932  if (err_on_fail) {
933  O2SCL_ERR2("Function wordexp_wrapper() failed ",
934  "in strings_spec().",o2scl::exc_einval);
935  } else {
936  return 9;
937  }
938  }
939  fname=matches[0];
940  if (verbose>1) {
941  std::cout << "Filename after wordexp() " << fname << std::endl;
942  }
943 
944  hf.open(fname);
945  std::string type;
946  int find_ret=hf.find_object_by_name(obj_name,type);
947  if (find_ret!=0) {
948  if (err_on_fail) {
949  O2SCL_ERR2("Object not found in file ",
950  "in strings_spec().",o2scl::exc_einval);
951  } else {
952  return 11;
953  }
954  }
955  if (verbose>1) {
956  std::cout << "Object type from file: " << type << std::endl;
957  }
958 
959  if (type=="table") {
960  if (addl_spec.length()==0) {
961  if (err_on_fail) {
962  O2SCL_ERR2("No table column name specified ",
963  "in strings_spec().",o2scl::exc_einval);
964  } else {
965  return 6;
966  }
967  }
969  o2scl_hdf::hdf_input(hf,t,obj_name);
970  v.resize(t.get_nlines());
971  for(size_t i=0;i<t.get_nlines();i++) {
972  v[i]=t.get(addl_spec,i);
973  }
974 
975  }
976 
977  } else {
978 
979  v.resize(1);
980  v[0]=spec;
981 
982  }
983 
984  return 0;
985  }
986 
987  /** \brief Return a std vector specified by a string
988  */
989  std::vector<double> vector_spec(std::string spec);
990 
991  /** \brief A list of vectors specified by a string
992 
993  Formats:
994  - function: func:<num>:<len(i)>:<function of i and j>
995  - columns in text file: text:<column index list>
996  - HDF5 object(s) in file(s):
997  hdf5:<file name(s)>:<object name(s)>:[additional specification]
998 
999  \note unfinished.
1000  */
1001  template<class vec_t> int mult_vector_spec(std::string spec,
1002  std::vector<vec_t> &v,
1003  int verbose=0,
1004  bool err_on_fail=true) {
1005 
1006  if (spec.find("func:")==0) {
1007 
1008  // Function
1009  if (verbose>1) {
1010  std::cout << "mult_vector_spec(): Function " << spec << std::endl;
1011  }
1012  std::string temp=spec.substr(5,spec.length()-5);
1013  std::vector<std::string> sv;
1014  o2scl::split_string_delim(temp,sv,':');
1015  if (sv.size()<3) {
1016  if (err_on_fail) {
1017  O2SCL_ERR2("Less than three parts for function type ",
1018  "in mult_vector_spec().",o2scl::exc_einval);
1019  } else {
1020  return 1;
1021  }
1022  }
1023 
1024  size_t n;
1025  int cret=o2scl::stoszt_nothrow(sv[0],n);
1026  if (cret!=0) {
1027  if (err_on_fail) {
1028  O2SCL_ERR2("Conversion to size_t failed ",
1029  "in mult_vector_spec().",o2scl::exc_einval);
1030  } else {
1031  return 2;
1032  }
1033  }
1034  if (verbose>1) {
1035  std::cout << "Size " << n << std::endl;
1036  }
1037 
1038  v.resize(n);
1039 
1040  for(size_t i=0;i<n;i++) {
1041 
1042  size_t n2;
1043  int cret2=o2scl::stoszt_nothrow(sv[1],n2);
1044  if (cret2!=0) {
1045  if (err_on_fail) {
1046  O2SCL_ERR2("Conversion to size_t failed ",
1047  "in mult_vector_spec().",o2scl::exc_einval);
1048  } else {
1049  return 2;
1050  }
1051  }
1052  if (verbose>1) {
1053  std::cout << "Size of " << n << " is " << n2 << std::endl;
1054  }
1055 
1056  if (verbose>1) {
1057  std::cout << "Function " << sv[2] << std::endl;
1058  }
1059 
1060  o2scl::calculator calc;
1061  std::map<std::string,double> vars;
1062  calc.compile(sv[2].c_str(),&vars);
1063 
1064  v[i].resize(n2);
1065  for(size_t j=0;j<n2;j++) {
1066  vars["i"]=((double)i);
1067  vars["j"]=((double)j);
1068  v[i][j]=calc.eval(&vars);
1069  }
1070 
1071  }
1072 
1073  } else if (spec.find("text:")==0) {
1074 
1075  // Text
1076  if (verbose>1) {
1077  std::cout << "mult_vector_spec(): Text " << spec << std::endl;
1078  }
1079 
1080  std::vector<std::string> sv;
1081  o2scl::split_string_delim(spec,sv,':');
1082 
1083  if (sv.size()<3) {
1084  if (err_on_fail) {
1085  O2SCL_ERR2("Not enough information for text file ",
1086  "in mult_vector_spec().",o2scl::exc_einval);
1087  } else {
1088  return 12;
1089  }
1090  }
1091 
1092  std::string col_list=sv[2];
1093  if (verbose>1) {
1094  std::cout << "Filename,column list: " << sv[1] << " "
1095  << col_list << std::endl;
1096  }
1097 
1098  std::vector<size_t> col_list2;
1099  o2scl::string_to_uint_list(col_list,col_list2);
1100  o2scl::vector_sort<std::vector<size_t>,size_t>(col_list2.size(),
1101  col_list2);
1102 
1103  if (col_list2.size()<1) {
1104  if (err_on_fail) {
1105  O2SCL_ERR2("No column list in ",
1106  "in mult_vector_spec().",o2scl::exc_einval);
1107  } else {
1108  return 20;
1109  }
1110  }
1111 
1112  bool in_header=true;
1113  std::ifstream fin;
1114  std::string line, word;
1115  fin.open(sv[1].c_str());
1116 
1117  std::cout << "Unfinished in mult_vector_spec." << std::endl;
1118  exit(-1);
1119 
1120  /*
1121  do {
1122  getline(fin,line);
1123  std::istringstream is(line);
1124  size_t i=0;
1125  for(;i<col_list2[col_list2.size()-1] && (is >> word) && in_header;i++) {
1126  if (i==col-1 && o2scl::is_number(word)) {
1127  in_header=false;
1128  }
1129  if (i==col-1 && verbose>2) {
1130  if (in_header) {
1131  std::cout << "Word: " << word << " header." << std::endl;
1132  } else {
1133  std::cout << "Word: " << word << " start of data."
1134  << std::endl;
1135  }
1136  }
1137  }
1138  } while (in_header && !fin.eof());
1139 
1140  if (in_header) {
1141  if (err_on_fail) {
1142  O2SCL_ERR2("Couldn't find a number in text file ",
1143  "in vector_spec().",o2scl::exc_einval);
1144  } else {
1145  return 13;
1146  }
1147  }
1148 
1149  std::vector<double> tempv;
1150 
1151  bool end_of_data=false;
1152  do {
1153  tempv.push_back(o2scl::stod(word));
1154 
1155  getline(fin,line);
1156  std::istringstream is(line);
1157  for(size_t i=0;i<col;i++) {
1158  if (!(is >> word)) {
1159  i=col;
1160  end_of_data=true;
1161  }
1162  }
1163  if (!o2scl::is_number(word)) end_of_data=true;
1164 
1165  } while (!end_of_data && !fin.eof());
1166 
1167  fin.close();
1168 
1169  v.resize(tempv.size());
1170  for(size_t i=0;i<tempv.size();i++) {
1171  v[i]=tempv[i];
1172  }
1173  */
1174 
1175  } else if (spec.find("hdf5:")==0) {
1176 
1177  // HDF5 object in a file
1178  if (verbose>1) {
1179  std::cout << "mult_vector_spec(): HDF5 file " << spec << std::endl;
1180  }
1181  std::string temp=spec.substr(5,spec.length()-5);
1182  size_t ncolon=temp.find(':');
1183  if (ncolon==std::string::npos) {
1184  if (err_on_fail) {
1185  O2SCL_ERR2("No apparent file name specified ",
1186  "in mult_vector_spec().",o2scl::exc_einval);
1187  } else {
1188  return 4;
1189  }
1190  }
1191  std::string fname=temp.substr(0,ncolon);
1192  if (verbose>1) {
1193  std::cout << "Filename " << fname << std::endl;
1194  }
1195  if (temp.length()<ncolon+1) {
1196  if (err_on_fail) {
1197  O2SCL_ERR2("No apparent object name specified ",
1198  "in mult_vector_spec().",o2scl::exc_einval);
1199  } else {
1200  return 5;
1201  }
1202  }
1203  std::string obj_name=temp.substr(ncolon+1,temp.length()-ncolon-1);
1204  std::string addl_spec;
1205  ncolon=obj_name.find(':');
1206  if (ncolon!=std::string::npos) {
1207  addl_spec=obj_name.substr(ncolon+1,obj_name.length()-ncolon-1);
1208  obj_name=obj_name.substr(0,ncolon);
1209  }
1210  if (verbose>1) {
1211  std::cout << "Object name " << obj_name << std::endl;
1212  std::cout << "Additional specification " << addl_spec << std::endl;
1213  }
1215 
1216  std::string fname_old=fname;
1217  std::vector<std::string> matches;
1218  int wret=o2scl::wordexp_wrapper(fname_old,matches);
1219  if (matches.size()==0 || wret!=0) {
1220  if (err_on_fail) {
1221  O2SCL_ERR2("Function wordexp_wrapper() failed ",
1222  "in mult_vector_spec().",o2scl::exc_einval);
1223  } else {
1224  return 9;
1225  }
1226  }
1227 
1228  size_t nfiles=matches.size();
1229  if (verbose>1) {
1230  std::cout << "Wordexp() found " << nfiles << " files."
1231  << std::endl;
1232  }
1233 
1234  for(size_t ifile=0;ifile<nfiles;ifile++) {
1235  fname=matches[ifile];
1236  if (verbose>1) {
1237  std::cout << "Filename for index " << ifile << " is " << fname
1238  << std::endl;
1239  }
1240 
1241  hf.open(fname);
1242  std::string type;
1243  int find_ret=hf.find_object_by_name(obj_name,type);
1244  if (find_ret!=0) {
1245  if (err_on_fail) {
1246  O2SCL_ERR2("Object not found in file ",
1247  "in mult_vector_spec().",o2scl::exc_einval);
1248  } else {
1249  return 11;
1250  }
1251  }
1252  if (verbose>1) {
1253  std::cout << "Object type from file: " << type << std::endl;
1254  }
1255 
1256  if (type=="table") {
1257  if (addl_spec.length()==0) {
1258  if (err_on_fail) {
1259  O2SCL_ERR2("No table column name specified ",
1260  "in mult_vector_spec().",o2scl::exc_einval);
1261  } else {
1262  return 6;
1263  }
1264  }
1266  o2scl_hdf::hdf_input(hf,t,obj_name);
1267 
1268  for(size_t j=0;j<t.get_ncolumns();j++) {
1269  if (fnmatch(addl_spec.c_str(),
1270  t.get_column_name(j).c_str(),0)==0) {
1271  if (verbose>1) {
1272  std::cout << "Column " << t.get_column_name(j)
1273  << " matches pattern " << addl_spec
1274  << "." << std::endl;
1275  }
1276  vec_t vtemp(t.get_nlines());
1277  for(size_t k=0;k<t.get_nlines();k++) {
1278  vtemp[k]=t.get(j,k);
1279  }
1280  v.push_back(vtemp);
1281  }
1282  }
1283  } else if (type=="double[]") {
1284  std::vector<double> vtemp;
1285  hf.getd_vec(obj_name,vtemp);
1286  v.push_back(vtemp);
1287  }
1288  hf.close();
1289 
1290  }
1291 
1292  } else {
1293 
1294  if (err_on_fail) {
1295  O2SCL_ERR2("Could not parse specification ",
1296  "in mult_vector_spec().",o2scl::exc_einval);
1297  } else {
1298  return 8;
1299  }
1300 
1301  }
1302  return 0;
1303  }
1304 
1305 }
1306 
1307 #endif
o2scl::hist
A one-dimensional histogram class.
Definition: hist.h:113
o2scl_hdf::vector_spec
int vector_spec(std::string spec, vec_t &v, int verbose=0, bool err_on_fail=true)
A vector specified by a string.
Definition: hdf_io.h:419
o2scl_hdf::hdf_file::get_szt
int get_szt(std::string name, size_t &u)
Get an unsigned integer named name.
o2scl::is_number
bool is_number(std::string s)
Return true if the string s is likely a integral or floating point number.
o2scl::table
Data table table class.
Definition: table.h:49
o2scl::string_to_uint_list
int string_to_uint_list(const std::string &x, size_vec_t &list)
Convert a string-based list of unsigned integers to a list.
Definition: string_conv.h:258
o2scl::table::set_nlines
void set_nlines(size_t il)
Set the number of lines.
Definition: table.h:470
boost::numeric::ublas::vector< double >
o2scl::table::new_column
void new_column(std::string head)
Add a new column owned by the table table .
Definition: table.h:751
o2scl::exc_efailed
@ exc_efailed
generic failure
Definition: err_hnd.h:61
o2scl::table::itype
size_t itype
Current interpolation type.
Definition: table.h:3101
O2SCL_ERR2
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
o2scl::stoi
int stoi(std::string s)
Convert a string to an integer.
o2scl_hdf::hdf_file::get_current_id
hid_t get_current_id()
Retrieve the current working id.
o2scl::table_units::set_unit
void set_unit(std::string scol, std::string unit)
Set the unit for column scol to unit.
Definition: table_units.h:405
o2scl::wordexp_wrapper
int wordexp_wrapper(std::string word, std::vector< std::string > &matches)
Wrapper for the wordexp() function.
o2scl::prob_dens_mdim_amr::set_from_vectors
void set_from_vectors(size_t &nd, size_t &dc, size_t &ms, const std::vector< double > &data, const std::vector< size_t > &insides)
Set the object from data specified as three size_t numbers and a set of two vectors.
Definition: prob_dens_mdim_amr.h:311
o2scl_hdf::mult_vector_spec
int mult_vector_spec(std::string spec, std::vector< vec_t > &v, int verbose=0, bool err_on_fail=true)
A list of vectors specified by a string.
Definition: hdf_io.h:1001
o2scl::stod
double stod(std::string s)
Convert a string to a double.
o2scl_hdf::hdf_file::geti
int geti(std::string name, int &i)
Get a integer named name.
o2scl::table::set
void set(std::string scol, size_t row, double val)
Set row row of column named col to value val . .
Definition: table.h:317
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::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_input
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
Definition: hdf_io.h:148
o2scl::expval_scalar
Scalar expectation value.
Definition: expval.h:181
o2scl::hist::get_wgts
const ubvector & get_wgts() const
Get a reference to the full y vector.
Definition: hist.h:371
o2scl::calculator::compile
void compile(const char *expr, std::map< std::string, double > *vars=0, bool debug=false, std::map< std::string, int > opPrec=opPrecedence)
Compile expression expr using variables specified in vars and return an integer to indicate success o...
o2scl::table_units
Data table table class with units.
Definition: table_units.h:42
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::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::exc_einval
@ exc_einval
invalid argument supplied by user
Definition: err_hnd.h:59
o2scl::calculator
Evaluate a mathematical expression in a string.
Definition: shunting_yard.h:119
o2scl::table::add_constant
virtual void add_constant(std::string name, double val)
Add a constant, or if the constant already exists, change its value.
Definition: table.h:2454
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::expval_vector
Vector expectation value.
Definition: expval.h:304
o2scl::expval_matrix
Matrix expectation value.
Definition: expval.h:584
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::uniform_grid_log_end_width
Logarithmic grid with fixed endpoint and fixed bin size.
Definition: uniform_grid.h:422
o2scl::tensor_grid
Tensor class with arbitrary dimensions with a grid.
Definition: tensor_grid.h:46
o2scl::uniform_grid< double >
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::prob_dens_mdim_amr::copy_to_vectors
void copy_to_vectors(size_t &nd, size_t &dc, size_t &ms, std::vector< double > &data, std::vector< size_t > &insides)
Copy the object data to three size_t numbers and two vectors.
Definition: prob_dens_mdim_amr.h:270
o2scl::stoszt_nothrow
int stoszt_nothrow(std::string s, size_t &result)
Convert a string to a size_t without throwing an exception.
o2scl::table::get_ncolumns
size_t get_ncolumns() const
Return the number of columns.
Definition: table.h:452
o2scl::exc_efilenotfound
@ exc_efilenotfound
File not found.
Definition: err_hnd.h:121
o2scl::prob_dens_mdim_amr
Probability distribution from an adaptive mesh created using a matrix of points.
Definition: prob_dens_mdim_amr.h:51
o2scl_hdf::hdf_input_data
void hdf_input_data(hdf_file &hf, o2scl::table< vec_t > &t)
Internal function for inputting a o2scl::table object.
Definition: hdf_io.h:186
o2scl::table::check_synchro
void check_synchro() const
Check if the tree and list are properly synchronized.
Definition: table.h:2632
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
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::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::itp_cspline
@ itp_cspline
Cubic spline for natural boundary conditions.
Definition: interp.h:73
o2scl::uniform_grid< double >::vector
void vector(resize_vec_t &v) const
Fill a vector with the specified grid.
Definition: uniform_grid.h:246
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::calculator::eval
double eval(std::map< std::string, double > *vars=0)
Evalate the previously compiled expression using variables specified in vars.
o2scl::uniform_grid_end_width
Linear grid with fixed endpoint and fixed bin size.
Definition: uniform_grid.h:368
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::function_to_double
double function_to_double(std::string s)
Convert a formula to a double.
o2scl::split_string_delim
int split_string_delim(std::string str, std::vector< std::string > &list, char delim)
Split a string into parts using a delimiter.
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::value_spec
int value_spec(std::string spec, double &d, int verbose=0, bool err_on_fail=true)
A value specified by a string.
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::table::clear_table
virtual void clear_table()
Clear the table and the column names (but leave constants)
Definition: table.h:2294
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::has_write_access
bool has_write_access()
If true, then the file has read and write access.
Definition: hdf_file.h:152
o2scl::table::clear_constants
void clear_constants()
CLear all constants.
Definition: table.h:2321
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::strings_spec
int strings_spec(std::string spec, vec_t &v, int verbose=0, bool err_on_fail=true)
Desc.
Definition: hdf_io.h:809
o2scl::table3d
A data structure containing one or more slices of two-dimensional data points defined on a grid.
Definition: table3d.h:78
o2scl::table::get_column_name
std::string get_column_name(size_t icol) const
Returns the name of column col .
Definition: table.h:819
o2scl::hist_2d
A two-dimensional histogram class.
Definition: hist_2d.h:103
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).