table_units.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2017, 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_TABLE_UNITS_H
24 #define O2SCL_TABLE_UNITS_H
25 
26 /** \file table_units.h
27  \brief File defining \ref o2scl::table_units
28 */
29 
30 #include <o2scl/table.h>
31 #include <o2scl/lib_settings.h>
32 
33 #ifndef DOXYGEN_NO_O2NS
34 
35 // Forward definition of the table_units class for HDF I/O
36 namespace o2scl {
37  template<class vec_t> class table_units;
38 }
39 
40 // Forward definition of HDF I/O to extend friendship in table_units
41 namespace o2scl_hdf {
42 
43  class hdf_file;
44 
45  template<class vec_t>
46  void hdf_input(hdf_file &hf, o2scl::table_units<vec_t> &t,
47  std::string name);
48 
49  void hdf_output
50  (hdf_file &hf,
51  o2scl::table_units<std::vector<double> > &t,
52  std::string name);
53 
54  template<class vec_t>
55  void hdf_input_data(hdf_file &hf, o2scl::table_units<vec_t> &t);
56 
57  void hdf_output_data
58  (hdf_file &hf,
59  o2scl::table_units<std::vector<double> > &t);
60 
61 }
62 
63 #endif
64 
65 #ifndef DOXYGEN_NO_O2NS
66 namespace o2scl {
67 #endif
68 
69  /** \brief Data \table class with units
70 
71  \future The unit conversion object is now always a pointer to
72  the global conversion object. This could be modified, so that
73  each table can have it's own, but this might require HDF output
74  of unit conversion objects.
75 
76  \future Make table methods virtual? (not necessary yet since
77  delete_column() isn't referred to internally)
78  */
79  template<class vec_t=std::vector<double> >
80  class table_units : public table<vec_t> {
81 
82  public:
83 
84 #ifdef O2SCL_NEVER_DEFINED
85  }{
86 #endif
87 
88  /** \brief Create a new table_units with space for nlines<=cmaxlines.
89  */
90  table_units(int cmaxlines=0) : table<vec_t>(cmaxlines) {
92  }
93 
94  virtual ~table_units() {
95  utree.clear();
96  }
97 
98  /// \name Copy constructors
99  //@{
100  /// Copy with constructor from \ref table_units
101  table_units(const table_units &t) : table<vec_t>(t.get_nlines()) {
102 
103  // Copy constants
104  this->constants=t.constants;
105 
106  // Copy interpolation type
107  this->itype=t.get_interp_type();
108 
109  // Copy the columns and data
110  this->nlines=t.get_nlines();
111  this->maxlines=this->nlines;
112  for(size_t i=0;i<t.get_ncolumns();i++) {
113 
114  // Column name
115  std::string cname=t.get_column_name(i);
116 
117  // Insert column into tree
118  typename table<vec_t>::col s;
119  s.dat.resize(this->nlines);
120  s.index=this->atree.size();
121  this->atree.insert(make_pair(cname,s));
122 
123  // Insert in iterator index
124  typename table<vec_t>::aiter it=this->atree.find(cname);
125  this->alist.push_back(it);
126 
127  // Insert in unit list
128  utree.insert(make_pair(cname,t.get_unit(cname)));
129 
130  // Fill the data
131  for(size_t j=0;j<t.get_nlines();j++) {
132  it->second.dat[j]=t.get(cname,j);
133  }
134 
135  }
136 
137  this->intp_set=false;
139 
140  return;
141  }
142 
143  /// Copy with constructor from \ref table
144  table_units(const table<vec_t> &t) : table<vec_t>(t.get_nlines()) {
145 
146  // Copy constants
147  size_t nc=t.get_nconsts();
148  for(size_t i=0;i<nc;i++) {
149  std::string name;
150  double val;
151  t.get_constant(i,name,val);
152  this->constants.insert(make_pair(name,val));
153  }
154 
155  // Copy interpolation type
156  this->itype=t.get_interp_type();
157 
158  // Copy the columns and data
159  this->nlines=t.get_nlines();
160  this->maxlines=this->nlines;
161  for(size_t i=0;i<t.get_ncolumns();i++) {
162 
163  // Column name
164  std::string cname=t.get_column_name(i);
165 
166  // Insert column into tree
167  typename table<vec_t>::col s;
168  s.dat.resize(this->nlines);
169  s.index=this->atree.size();
170  this->atree.insert(make_pair(cname,s));
171 
172  // Insert in iterator index
173  typename table<vec_t>::aiter it=this->atree.find(cname);
174  this->alist.push_back(it);
175 
176  // Fill the data
177  for(size_t j=0;j<t.get_nlines();j++) {
178  it->second.dat[j]=t.get(cname,j);
179  }
180 
181  }
182 
183  this->intp_set=false;
185 
186  return;
187 
188  }
189 
190  /// Copy with <tt>operator=</tt> from \ref table_units
192 
193  if (this!=&t) {
194 
195  this->clear_table();
196  this->constants.clear();
197  utree.clear();
198 
199  // Copy constants
200  this->constants=t.constants;
201 
202  // Copy interpolation type
203  this->itype=t.get_interp_type();
204 
205  // Copy the columns and data
206  this->nlines=t.get_nlines();
207  for(size_t i=0;i<t.get_ncolumns();i++) {
208 
209  // Column name
210  std::string cname=t.get_column_name(i);
211 
212  // Insert column into tree
213  typename table<vec_t>::col s;
214  s.dat.resize(this->nlines);
215  s.index=this->atree.size();
216  this->atree.insert(make_pair(cname,s));
217 
218  // Insert in iterator index
219  typename table<vec_t>::aiter it=this->atree.find(cname);
220  this->alist.push_back(it);
221 
222  // Insert in unit list
223  utree.insert(make_pair(cname,t.get_unit(cname)));
224 
225  // Fill the data
226  for(size_t j=0;j<t.get_nlines();j++) {
227  it->second.dat[j]=t.get(cname,j);
228  }
229 
230  }
231 
232  if (this->intp_set) {
233  this->intp_set=false;
234  delete this->si;
235  }
236 
238 
239  }
240 
241  return *this;
242  }
243 
244  /// Copy with <tt>operator=</tt> from \ref table
246 
247  if (this!=&t) {
248 
249  this->clear_table();
250  this->constants.clear();
251  utree.clear();
252 
253  // Copy constants
254  size_t nc=t.get_nconsts();
255  for(size_t i=0;i<nc;i++) {
256  std::string name;
257  double val;
258  t.get_constant(i,name,val);
259  this->constants.insert(make_pair(name,val));
260  }
261 
262  // Copy interpolation type
263  this->itype=t.get_interp_type();
264 
265  // Copy the columns and data
266  this->nlines=t.get_nlines();
267  for(size_t i=0;i<t.get_ncolumns();i++) {
268 
269  // Column name
270  std::string cname=t.get_column_name(i);
271 
272  // Insert column into tree
273  typename table<vec_t>::col s;
274  s.dat=new vec_t(this->nlines);
275  s.index=this->atree.size();
276  this->atree.insert(make_pair(cname,s));
277 
278  // Insert in iterator index
279  typename table<vec_t>::aiter it=this->atree.find(cname);
280  this->alist.push_back(it);
281 
282  // Fill the data
283  for(size_t j=0;j<t.get_nlines();j++) {
284  (*it->second.dat)[j]=t.get(cname,j);
285  }
286 
287  }
288 
289  if (this->intp_set) {
290  this->intp_set=false;
291  delete this->si;
292  }
293 
295 
296  }
297 
298  return *this;
299  }
300  //@}
301 
302  /** \brief Copy all rows matching a particular condition to
303  a new table
304 
305  This function begins by ensuring that all columns in the
306  current table are present in \c dest, creating new columns
307  (and copying their units) in \c dest if necessary. It then
308  copies all rows where \c func evaluates to a number greater
309  than 0.5 to table \c dest by adding rows at the end of the
310  table.
311  */
312  template<class vec2_t>
313  void copy_rows(std::string func, table_units<vec2_t> &dest) {
314 
315  // Set up columns
316  for(size_t i=0;i<this->get_ncolumns();i++) {
317  std::string cname=this->get_column_name(i);
318  if (dest.is_column(cname)==false) {
319  dest.new_column(cname);
320  }
321  dest.set_unit(get_unit(cname));
322  }
323 
324  size_t new_lines=dest.get_nlines();
325  for(size_t i=0;i<this->get_nlines();i++) {
326  double val=this->row_function(func,i);
327  if (val>0.5) {
328  this->set_nlines_auto(new_lines+1);
329  for(size_t j=0;j<this->get_ncolumns();j++) {
330  std::string cname=this->get_column_name(j);
331  dest.set(cname,new_lines);
332  }
333  new_lines++;
334  }
335  }
336 
337  return;
338  }
339 
340  /// \name Unit manipulation
341  //@{
342  /// Get the unit for column \c scol
343  std::string get_unit(std::string scol) const {
344 
345  uciter it=utree.find(scol);
346  if (it==utree.end()) {
347  // Not found in unit entry, look for column of data
348  typename table<vec_t>::aciter at=this->atree.find(scol);
349  if (at==this->atree.end()) {
350  O2SCL_ERR((((std::string)"Column '")+scol+
351  "' not found in table_units::get_unit().").c_str(),
352  exc_enotfound);
353  } else {
354  return "";
355  }
356  }
357 
358  return it->second;
359  }
360 
361  /** \brief Get the unit for column with index i
362 
363  \future Is there a way to make this function have O(1) time
364  rather than searching?
365  */
366  std::string get_unit(size_t i) const {
367  return get_unit(this->get_column_name(i));
368  }
369 
370  /// Remove the unit for column \c scol
371  void remove_unit(std::string scol) {
372 
373  uiter it=utree.find(scol);
374  if (it==utree.end()) {
375  O2SCL_ERR((((std::string)"Column '")+scol+
376  "' not found in table_units::get_unit().").c_str(),
377  exc_enotfound);
378  }
379 
380  if (utree.size()==0) {
381  O2SCL_ERR("No units specified in table_units::remove_unit().",
382  exc_efailed);
383  }
384 
385  utree.erase(it);
386  return;
387  }
388 
389  /// Set the unit for column \c scol to \c unit
390  void set_unit(std::string scol, std::string unit) {
391 
392  uiter it=utree.find(scol);
393  if (it==utree.end()) {
394  typename table<vec_t>::aiter at=this->atree.find(scol);
395  if (at==this->atree.end()) {
396  O2SCL_ERR((((std::string)"Column '")+scol+
397  "' not found in table_units::set_unit().").c_str(),
398  exc_enotfound);
399  }
400  utree.insert(make_pair(scol,unit));
401  } else {
402  it->second=unit;
403  }
404 
405  return;
406  }
407 
408  /// Convert the units of column \c scol to \c unit
409  int convert_to_unit(std::string scol, std::string unit,
410  bool err_on_fail=true) {
411 
412  // Find unit entry
413  uiter it=utree.find(scol);
414  if (it==utree.end()) {
415  if (err_on_fail) {
416  O2SCL_ERR((((std::string)"Column '")+scol+"' not found in "+
417  "table_units::convert_to_unit().").c_str(),
418  exc_enotfound);
419  } else {
420  return exc_enotfound;
421  }
422  };
423 
424  // If the units are equal, just do nothing
425  if (it->second==unit) return success;
426 
427  // Find column of data
428  typename table<vec_t>::aiter at=this->atree.find(scol);
429  if (at==this->atree.end()) {
430  if (err_on_fail) {
431  O2SCL_ERR((((std::string)"Column '")+scol+"' not found in "+
432  "table_units::convert_to_unit().").c_str(),
433  exc_enotfound);
434  } else {
435  return exc_enotfound;
436  }
437  };
438 
439  // Perform conversion
440  vec_t &vec=at->second.dat;
441  double conv=cup->convert(it->second,unit,1.0);
442 
443  for(size_t i=0;i<this->get_nlines();i++) {
444  vec[i]*=conv;
445  }
446 
447  // Set new unit entry
448  it->second=unit;
449 
450  return success;
451  }
452 
453  /// Return the number of columns with units
454  size_t get_nunits() {
455  return utree.size();
456  }
457 
458  /*
459  // Get the conversion factor from \c old_unit to \c new_unit
460  double get_conv(std::string old_unit, std::string new_unit);
461 
462  // Set the convert units object
463  void set_convert(convert_units &c) {
464  cup=&c;
465  return;
466  }
467 
468  // Show the unit cache as given by \ref convert_units::print_cache()
469  void show_units() {
470  cup->print_cache();
471  return;
472  }
473 
474  // The default object for unit conversions
475  convert_units def_cu;
476  */
477  //@}
478 
479  /// \name Virtual functions from \ref table
480  //@{
481  /// Delete column named \c scol
482  virtual void delete_column(std::string scol) {
483 
484  // Find the tree iterator for the element we want to erase
485  typename table<vec_t>::aiter it=this->atree.find(scol);
486  if (it==this->atree.end()) {
487  O2SCL_ERR((((std::string)"Column '")+scol+
488  " not found in table_units::delete_column().").c_str(),
489  exc_enotfound);
490  return;
491  }
492 
493  // Remove the unit for the specified column
494  if (get_unit(scol).length()>0) remove_unit(scol);
495 
496  // Find the corresponding list iterator
497  typename table<vec_t>::aviter vit=this->alist.begin();
498  vit+=it->second.index;
499 
500  // Find the last element in the list and it's corresponding table
501  // entry. Change it's index to the index of the column to be
502  // deleted.
503  this->alist[this->alist.size()-1]->second.index=it->second.index;
504 
505  // Erase the elements from the list and the tree
506  this->atree.erase(it);
507  this->alist.erase(vit);
508 
509  // Reset the list to reflect the proper iterators
510  this->reset_list();
511 
512  return;
513  }
514 
515  /** \brief Rename column named \c src to \c dest
516  \f$ {\cal O}(C) \f$
517  */
518  virtual void rename_column(std::string src, std::string dest) {
519  std::string unit=get_unit(src);
520  table<vec_t>::rename_column(src,dest);
521  set_unit(dest,unit);
522  return;
523  }
524 
525  /// Output a summary of the information stored
526  virtual void summary(std::ostream *out, size_t ncol=79) const {
527 
528  if (this->constants.size()==1) {
529  (*out) << "1 constant:" << std::endl;
530  } else {
531  (*out) << this->constants.size() << " constants:" << std::endl;
532  }
533  std::map<std::string,double>::const_iterator mit;
534  for(mit=this->constants.begin();mit!=this->constants.end();mit++) {
535  (*out) << mit->first << " " << mit->second << std::endl;
536  }
537 
538  // Output number of columns and preprend column numbers
539  size_t nh=this->get_ncolumns(), nh2;
540 
541  if (nh==0) {
542 
543  (*out) << "No columns." << std::endl;
544 
545  } else {
546 
547  if (nh==1) {
548  (*out) << "1 column: " << std::endl;
549  } else {
550  (*out) << nh << " columns: " << std::endl;
551  }
552  std::string *h=new std::string[nh];
553  for(size_t i=0;i<nh;i++) {
554  h[i]=szttos(i)+". "+this->get_column_name(i)+" ["+
555  get_unit(this->get_column_name(i))+"]";
556  }
557 
558  std::vector<std::string> h2;
559  // Convert to string with width 'ncol'
560  screenify(nh,h,h2,ncol);
561  nh2=h2.size();
562 
563  // Output column names
564  for(size_t i=0;i<nh2;i++) {
565  (*out) << h2[i] << std::endl;
566  }
567 
568  delete[] h;
569 
570  }
571 
572  if (this->get_nlines()==0) {
573  (*out) << "No lines of data." << std::endl;
574  } else if (this->get_nlines()==1) {
575  (*out) << "One line of data." << std::endl;
576  } else {
577  (*out) << this->get_nlines() << " lines of data." << std::endl;
578  }
579 
580  return;
581  }
582  //@}
583 
584  /// Return the type, \c "table_units".
585  virtual const char *type() { return "table_units"; }
586 
587  /** \brief Copy data from column named \c src to column named \c
588  dest, creating a new column if necessary \f$ {\cal O}(R
589  \log(C)) \f$
590 
591  This function also sets the units of column \c dest to be the
592  same as that in \c src, even if the column named \c dest
593  already exists and previously had different units.
594  */
595  virtual void copy_column(std::string src, std::string dest) {
596  if (!this->is_column(dest)) this->new_column(dest);
597 
598  typedef typename std::map<std::string,
599  typename table<vec_t>::col,std::greater<std::string> >::iterator aiter;
600 
601  aiter its=this->atree.find(src);
602  if (its==this->atree.end()) {
603  O2SCL_ERR((((std::string)"Column '")+src+
604  " not found in table_units::copy_column().").c_str(),
605  exc_enotfound);
606  return;
607  }
608  aiter itd=this->atree.find(dest);
609  if (itd==this->atree.end()) {
610  O2SCL_ERR((((std::string)"Destination column '")+dest+
611  " not found in table_units::copy_column().").c_str(),
612  exc_esanity);
613  return;
614  }
615  this->set_unit(dest,this->get_unit(src));
616  for(size_t i=0;i<this->nlines;i++) {
617  itd->second.dat[i]=its->second.dat[i];
618  }
619  return;
620  }
621 
622  /// Clear the current table and read from a generic data file
623  virtual int read_generic(std::istream &fin, int verbose=0) {
624 
625  double data;
626  std::string line;
627  std::string stemp;
628  std::istringstream *is;
629 
630  // Read first line and into list
631  std::vector<std::string> onames, nnames;
632  getline(fin,line);
633  is=new std::istringstream(line);
634  while ((*is) >> stemp) {
635  onames.push_back(stemp);
636  if (verbose>2) {
637  std::cout << "Read possible column name: " << stemp << std::endl;
638  }
639  }
640  delete is;
641 
642  // Count number of likely numbers in the first row
643  size_t n_nums=0;
644  for(size_t i=0;i<onames.size();i++) {
645  if (is_number(onames[i])) n_nums++;
646  }
647 
648  int irow=0;
649 
650  if (n_nums==onames.size()) {
651 
652  if (verbose>0) {
653  std::cout << "First row looks like it contains numerical values."
654  << std::endl;
655  std::cout << "Creating generic column names: ";
656  }
657 
658  for(size_t i=0;i<onames.size();i++) {
659  nnames.push_back(((std::string)"c")+szttos(i+1));
660  if (verbose>0) std::cout << nnames[i] << " ";
661 
662  }
663  if (verbose>0) std::cout << std::endl;
664 
665  // Make columns
666  for(size_t i=0;i<nnames.size();i++) {
667  this->new_column(nnames[i]);
668  }
669 
670  // Add first row of data
671  for(size_t i=0;i<onames.size();i++) {
672  this->set(i,irow,o2scl::stod(onames[i]));
673  }
674  irow++;
675 
676  } else {
677 
678  // Ensure good column names
679  for(size_t i=0;i<onames.size();i++) {
680  std::string temps=onames[i];
681  this->make_fp_varname(temps);
682  this->make_unique_name(temps,nnames);
683  nnames.push_back(temps);
684  if (temps!=onames[i] && verbose>0) {
685  std::cout << "Converted column named '" << onames[i] << "' to '"
686  << temps << "'." << std::endl;
687  }
688  }
689 
690  // Make columns
691  for(size_t i=0;i<nnames.size();i++) {
692  this->new_column(nnames[i]);
693  }
694 
695  // Read another line, and see if it looks like units
696  std::vector<std::string> units;
697  getline(fin,line);
698  is=new std::istringstream(line);
699  int num_units=0;
700  while ((*is) >> stemp) {
701  units.push_back(stemp);
702  if (stemp[0]=='[') num_units++;
703  if (verbose>2) {
704  std::cout << "Read word in second row: " << stemp << std::endl;
705  }
706  }
707  delete is;
708 
709  if (units.size()!=nnames.size()) {
710  std::cout << "Second row appears not to have same number of "
711  << "entries as the first." << std::endl;
712  std::cout << "Aborting." << std::endl;
713  return -1;
714  }
715 
716  if (num_units==((int)units.size()) || num_units>2) {
717  if (verbose>2) {
718  std::cout << "Looks like second row contains units." << std::endl;
719  }
720  for(size_t i=0;i<units.size();i++) {
721  // Remove brackets
722  stemp=units[i];
723  if (stemp[0]=='[') stemp=stemp.substr(1,stemp.length()-1);
724  if (stemp[stemp.length()-1]==']') {
725  stemp=stemp.substr(0,stemp.length()-1);
726  }
727  // Set the units
728  set_unit(nnames[i],stemp);
729  if (verbose>2) {
730  std::cout << "Name,unit: " << nnames[i] << " [" << stemp << "]"
731  << std::endl;
732  }
733  }
734 
735  } else {
736 
737  // Otherwise, assume this is a row of data
738  for(size_t i=0;i<units.size();i++) {
739  this->set(i,0,o2scl::stod(units[i]));
740  }
741  irow++;
742 
743  }
744 
745  }
746 
747  // Read remaining rows
748  while ((fin) >> data) {
749  this->set(0,irow,data);
750  for(size_t i=1;i<this->get_ncolumns();i++) {
751  (fin) >> data;
752  this->set(i,irow,data);
753  }
754  irow++;
755  }
756 
757  return 0;
758  }
759 
760  /** \brief Insert columns from a source table into the new
761  table by interpolation (or extrapolation)
762  */
763  template<class vec2_t>
764  void insert_table(table_units<vec2_t> &source, std::string src_index,
765  bool allow_extrap=true, std::string dest_index="") {
766 
767  if (dest_index=="") dest_index=src_index;
768 
769  // Find limits to avoid extrapolation if necessary
770  double min=source.min(src_index);
771  double max=source.max(src_index);
772  if (allow_extrap==false) {
773  if (!std::isfinite(min) || !std::isfinite(max)) {
774  O2SCL_ERR2("Minimum or maximum of source index not finite ",
775  "in table_units::insert_table().",exc_einval);
776  }
777  }
778 
779  // Create list of columns to interpolate
780  std::vector<std::string> col_list;
781  for(size_t i=0;i<source.get_ncolumns();i++) {
782  std::string col=source.get_column_name(i);
783  if (col!=src_index && col!=dest_index &&
784  this->is_column(col)==false) {
785  col_list.push_back(col);
786  }
787  }
788 
789  // Create new columns and perform interpolation
790  for(size_t i=0;i<col_list.size();i++) {
791  this->new_column(col_list[i]);
792  set_unit(col_list[i],source.get_unit(col_list[i]));
793  for(size_t j=0;j<this->get_nlines();j++) {
794  double val=this->get(dest_index,j);
795  if (allow_extrap || (val>=min && val<=max)) {
796  this->set(col_list[i],j,source.interp(src_index,val,col_list[i]));
797  }
798  }
799  }
800 
801  return;
802  }
803 
804  // ---------
805  // Allow HDF I/O functions to access table_units data
806  friend void o2scl_hdf::hdf_output
807  (o2scl_hdf::hdf_file &hf, table_units<> &t, std::string name);
808 
809  template<class vecf_t> friend void o2scl_hdf::hdf_input
810  (o2scl_hdf::hdf_file &hf, table_units<vecf_t> &t, std::string name);
811 
812  friend void o2scl_hdf::hdf_output_data
814 
815  template<class vecf_t> friend void o2scl_hdf::hdf_input_data
817 
818  // ---------
819 
820 #ifndef DOXYGEN_INTERNAL
821 
822  protected:
823 
824 
825  /// The pointer to the convert units object
827 
828  /// \name Unit map iterator types
829  //@{
830  typedef std::map<std::string,std::string,
831  std::greater<std::string> >::iterator uiter;
832  typedef std::map<std::string,std::string,
833  std::greater<std::string> >::const_iterator uciter;
834  //@}
835 
836  /// Unit map
837  std::map<std::string,std::string,std::greater<std::string> > utree;
838 
839 #endif
840 
841  };
842 
843 #ifndef DOXYGEN_NO_O2NS
844 }
845 #endif
846 
847 #endif
table_units(int cmaxlines=0)
Create a new table_units with space for nlines<=cmaxlines.
Definition: table_units.h:90
double max(std::string scol) const
Return column maximum. Makes no assumptions about ordering .
Definition: table.h:1834
double get(std::string scol, size_t row) const
Get value from row row of column named col. .
Definition: table.h:414
const double cup
cm^3
Definition: constants.h:187
void remove_unit(std::string scol)
Remove the unit for column scol.
Definition: table_units.h:371
The main O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$scl names...
Definition: anneal.h:42
size_t get_nlines() const
Return the number of lines.
Definition: table.h:457
double min(std::string scol) const
Return column minimum. Makes no assumptions about ordering .
Definition: table.h:1865
void hdf_input_data(hdf_file &hf, o2scl::table< vec_t > &t)
Internal function for inputting a o2scl::table object.
Definition: hdf_io.h:95
void hdf_input(hdf_file &hf, o2scl::table_units< vec_t > &t, std::string name)
Input a o2scl::table_units object from a hdf_file.
Definition: hdf_io.h:181
virtual int read_generic(std::istream &fin, int verbose=0)
Clear the current table and read from a generic data file.
Definition: table_units.h:623
Data table table class.
Definition: table.h:49
virtual void delete_column(std::string scol)
Delete column named scol.
Definition: table_units.h:482
virtual const char * type()
Return the type, "table_units".
Definition: table_units.h:585
sanity check failed - shouldn&#39;t happen
Definition: err_hnd.h:65
lib_settings_class o2scl_settings
The global library settings object.
Convert units.
Definition: convert_units.h:88
invalid argument supplied by user
Definition: err_hnd.h:59
virtual size_t get_nconsts() const
Get the number of constants.
Definition: table.h:2203
std::map< std::string, col, std::greater< std::string > >::const_iterator aciter
Const map iterator type.
Definition: table.h:2665
Generic "not found" result.
Definition: err_hnd.h:117
int convert_to_unit(std::string scol, std::string unit, bool err_on_fail=true)
Convert the units of column scol to unit.
Definition: table_units.h:409
generic failure
Definition: err_hnd.h:61
size_t get_interp_type() const
Get the interpolation type.
Definition: table.h:1443
virtual double get_constant(std::string name) const
Get a constant.
Definition: table.h:2193
virtual void summary(std::ostream *out, size_t ncol=79) const
Output a summary of the information stored.
Definition: table_units.h:526
void insert_table(table_units< vec2_t > &source, std::string src_index, bool allow_extrap=true, std::string dest_index="")
Insert columns from a source table into the new table by interpolation (or extrapolation) ...
Definition: table_units.h:764
virtual void rename_column(std::string src, std::string dest)
Rename column named src to dest .
Definition: table_units.h:518
std::map< std::string, double > constants
The list of constants.
Definition: table.h:2585
void set_unit(std::string scol, std::string unit)
Set the unit for column scol to unit.
Definition: table_units.h:390
double interp(std::string sx, double x0, std::string sy)
Interpolate x0 from sx into sy.
Definition: table.h:1453
convert_units * cup
The pointer to the convert units object.
Definition: table_units.h:826
size_t get_nunits()
Return the number of columns with units.
Definition: table_units.h:454
table_units & operator=(const table_units &t)
Copy with operator= from table_units.
Definition: table_units.h:191
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
Column structure for table [protected].
Definition: table.h:2649
The O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$scl namespace ...
Definition: table.h:53
void hdf_input_data(hdf_file &hf, o2scl::table_units< vec_t > &t)
Internal function for inputting a o2scl::table_units object.
Definition: hdf_io.h:217
std::map< std::string, std::string, std::greater< std::string > > utree
Unit map.
Definition: table_units.h:837
convert_units & get_convert_units()
Get the global convert_units object.
Definition: lib_settings.h:146
void screenify(size_t nin, const string_arr_t &in_cols, std::vector< std::string > &out_cols, size_t max_size=80)
Reformat the columns for output of width size.
Definition: misc.h:124
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
Definition: err_hnd.h:273
void copy_rows(std::string func, table_units< vec2_t > &dest)
Copy all rows matching a particular condition to a new table.
Definition: table_units.h:313
bool is_number(std::string s)
Return true if the string s is likely a integral or floating point number.
size_t get_ncolumns() const
Return the number of columns.
Definition: table.h:449
Data table table class with units.
Definition: table_units.h:37
void new_column(std::string head)
Add a new column owned by the table table .
Definition: table.h:690
void clear()
Clear everything.
Definition: table.h:1983
aiter end()
Return the end of the column tree.
Definition: table.h:2708
bool is_column(std::string scol) const
Return true if scol is a column in the current table table .
Definition: table.h:899
table_units(const table< vec_t > &t)
Copy with constructor from table.
Definition: table_units.h:144
table_units & operator=(const table< vec_t > &t)
Copy with operator= from table.
Definition: table_units.h:245
std::map< std::string, col, std::greater< std::string > >::iterator aiter
Map iterator type.
Definition: table.h:2661
virtual void copy_column(std::string src, std::string dest)
Copy data from column named src to column named dest, creating a new column if necessary ...
Definition: table_units.h:595
Store data in an O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$sc...
Definition: hdf_file.h:96
std::string get_unit(std::string scol) const
Get the unit for column scol.
Definition: table_units.h:343
void set(std::string scol, size_t row, double val)
Set row row of column named col to value val . .
Definition: table.h:327
double stod(std::string s, bool err_on_fail=true)
Convert a string to a double.
std::string get_unit(size_t i) const
Get the unit for column with index i.
Definition: table_units.h:366
std::string get_column_name(size_t icol) const
Returns the name of column col .
Definition: table.h:758
std::string szttos(size_t x)
Convert a size_t to a string.
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:59
vec_t dat
Pointer to column.
Definition: table.h:2652
std::vector< aiter >::iterator aviter
Vector iterator type.
Definition: table.h:2667
int index
Column index.
Definition: table.h:2654
Success.
Definition: err_hnd.h:47
table_units(const table_units &t)
Copy with constructor from table_units.
Definition: table_units.h:101
virtual void rename_column(std::string src, std::string dest)
Rename column named src to dest .
Definition: table.h:796

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