Public Member Functions | Protected Attributes | Friends | List of all members
o2scl::table_units< vec_t > Class Template Reference

Data table class with units. More...

#include <table_units.h>

Inheritance diagram for o2scl::table_units< vec_t >:
o2scl::table< vec_t >

Public Member Functions

 table_units (int cmaxlines=0)
 Create a new table_units with space for nlines<=cmaxlines.
 
template<class vec2_t >
void copy_rows (std::string func, table_units< vec2_t > &dest)
 Copy all rows matching a particular condition to a new table. More...
 
virtual const char * type ()
 Return the type, "table_units".
 
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 $ {\cal O}(R \log(C)) $. More...
 
virtual int read_generic (std::istream &fin, int verbose=0)
 Clear the current table and read from a generic data file.
 
template<class vec2_t >
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)
 
Copy constructors
 table_units (const table_units &t)
 Copy with constructor from table_units.
 
 table_units (const table< vec_t > &t)
 Copy with constructor from table.
 
table_unitsoperator= (const table_units &t)
 Copy with operator= from table_units.
 
table_unitsoperator= (const table< vec_t > &t)
 Copy with operator= from table.
 
Unit manipulation
std::string get_unit (std::string scol) const
 Get the unit for column scol.
 
std::string get_unit (size_t i) const
 Get the unit for column with index i. More...
 
void remove_unit (std::string scol)
 Remove the unit for column scol.
 
void set_unit (std::string scol, std::string unit)
 Set the unit for column scol to unit.
 
int convert_to_unit (std::string scol, std::string unit, bool err_on_fail=true)
 Convert the units of column scol to unit.
 
size_t get_nunits ()
 Return the number of columns with units.
 
Virtual functions from \ref table
virtual void delete_column (std::string scol)
 Delete column named scol.
 
virtual void rename_column (std::string src, std::string dest)
 Rename column named src to dest $ {\cal O}(C) $.
 
virtual void summary (std::ostream *out, size_t ncol=79) const
 Output a summary of the information stored.
 
- Public Member Functions inherited from o2scl::table< vec_t >
template<class vec2_t >
void insert_table (table< 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)
 
 table (size_t cmaxlines=0)
 Create a new table with space for nlines<=cmaxlines.
 
virtual ~table ()
 
 table (const table &t)
 Copy constructor.
 
tableoperator= (const table &t)
 Copy constructor.
 
void set (std::string scol, size_t row, double val)
 Set row row of column named col to value val . $ {\cal O}(\log(C)) $. More...
 
void set (size_t icol, size_t row, double val)
 Set row row of column number icol to value val . $ {\cal O}(1) $.
 
template<class size_vec_t >
void set_row (size_t row, size_vec_t &v)
 Set an entire row of data. More...
 
double get (std::string scol, size_t row) const
 Get value from row row of column named col. $ {\cal O}(\log(C)) $.
 
double get (size_t icol, size_t row) const
 Get value from row row of column number icol. $ {\cal O}(1) $.
 
size_t get_ncolumns () const
 Return the number of columns.
 
size_t get_nlines () const
 Return the number of lines.
 
void set_nlines (size_t il)
 Set the number of lines. More...
 
size_t get_maxlines ()
 Return the maximum number of lines before a reallocation is required.
 
template<class resize_vec_t >
void get_row (std::string scol, double val, resize_vec_t &row) const
 Returns a copy of the row with value val in column col. $ {\cal O}(R C) $. More...
 
template<class resize_vec_t >
void get_row (size_t irow, resize_vec_t &row) const
 Returns a copy of row number irow. $ {\cal O}(C) $. More...
 
void set_nlines_auto (size_t il)
 Set the number of lines, increasing the size more agressively. More...
 
void inc_maxlines (size_t llines)
 Manually increase the maximum number of lines.
 
const vec_t & get_column (std::string scol) const
 Returns a reference to the column named col. $ {\cal O}(\log(C)) $.
 
const vec_t & operator[] (size_t icol) const
 Returns the column of index icol (const version). $ {\cal O}(1) $. More...
 
const vec_t & operator[] (std::string scol) const
 Returns the column named scol (const version). $ {\cal O}(\log(C)) $. More...
 
void new_column (std::string head)
 Add a new column owned by the table $ {\cal O}(\log(C)) $. More...
 
template<class vec2_t >
int new_column (std::string name, size_t sz, vec2_t &v)
 Add a new column by copying data from another vector. More...
 
std::string get_column_name (size_t icol) const
 Returns the name of column col $ {\cal O}(1) $. More...
 
virtual void swap_column_data (std::string scol, vec_t &v)
 Swap the data in column scol with that in vector v. More...
 
std::string get_sorted_name (size_t icol) const
 Returns the name of column col in sorted order. $ {\cal O}(1) $.
 
void init_column (std::string scol, double val)
 Initialize all values of column named scol to val $ {\cal O}(R \log(C)) $. More...
 
bool is_column (std::string scol) const
 Return true if scol is a column in the current table. More...
 
size_t lookup_column (std::string lname) const
 Find the index for column named name $ {\cal O}(\log(C)) $. More...
 
template<class resize_vec_t >
void column_to_vector (std::string scol, resize_vec_t &v) const
 Copy a column to a generic vector object. More...
 
template<class vec2_t >
void copy_to_column (vec2_t &v, std::string scol)
 Copy to a column from a generic vector object. More...
 
template<class vec2_t >
void add_col_from_table (table< vec2_t > &source, std::string src_index, std::string src_col, std::string dest_index, std::string dest_col="")
 Insert a column from a separate table, interpolating it into a new column. More...
 
void new_row (size_t n)
 Insert a row before row n. More...
 
void copy_row (size_t src, size_t dest)
 Copy the data in row src to row dest.
 
void delete_row (std::string scol, double val)
 Delete the row with the entry closest to the value val in column scol $ {\cal O}(R C) $.
 
void delete_row (size_t irow)
 Delete the row of index irow $ {\cal O}(R C) $.
 
void delete_rows (std::string func)
 Delete all rows where func evaluates to a number greater than 0.5 $ {\cal O}(R C) $. More...
 
template<class vec2_t >
void copy_rows (std::string func, table< vec2_t > &dest)
 Copy all rows matching a particular condition to a new table. More...
 
void delete_rows (size_t row_start, size_t row_end)
 Delete all rows between row_start and row_end $ {\cal O}(R C) $. More...
 
void line_of_names (std::string newheads)
 Read a new set of names from newheads. More...
 
template<class vec2_t >
void line_of_data (size_t nv, const vec2_t &v)
 Read a line of data from the first nv entries in a vector and store as a new row in the table. More...
 
template<class vec2_t >
void line_of_data (const vec2_t &v)
 Read a line of data and store in a new row of the table. More...
 
size_t ordered_lookup (std::string scol, double val) const
 Look for a value in an ordered column $ {\cal O}(\log(C) \log(R)) $. More...
 
size_t lookup (std::string scol, double val) const
 Exhaustively search column col for the value val $ {\cal O}(R \log(C)) $.
 
double lookup_val (std::string scol, double val, std::string scol2) const
 Search column col for the value val and return value in col2.
 
size_t lookup (int icol, double val) const
 Exhaustively search column col for the value val $ {\cal O}(R \log(C)) $.
 
size_t mlookup (std::string scol, double val, std::vector< size_t > &results, double threshold=0.0) const
 Exhaustively search column col for many occurences of val $ {\cal O}(R \log(C)) $.
 
void set_interp_type (size_t interp_type)
 Set the base interpolation objects.
 
size_t get_interp_type () const
 Get the interpolation type.
 
double interp (std::string sx, double x0, std::string sy)
 Interpolate x0 from sx into sy. More...
 
double interp_const (std::string sx, double x0, std::string sy) const
 Interpolate x0 from sx into sy. More...
 
double interp (size_t ix, double x0, size_t iy)
 Interpolate x0 from ix into iy $ {\cal O}(\log(R)) $.
 
double interp_const (size_t ix, double x0, size_t iy) const
 Interpolate x0 from ix into iy $ {\cal O}(\log(R)) $.
 
void deriv (std::string x, std::string y, std::string yp)
 Make a new column yp which is the derivative $ y^{\prime}(x) $ . $ {\cal O}(R \log(C)) $.
 
double deriv (std::string sx, double x0, std::string sy)
 The first derivative of the function sy(sx) at sx=x0. More...
 
double deriv_const (std::string sx, double x0, std::string sy) const
 The first derivative of the function sy(sx) at sx=x0. More...
 
double deriv (size_t ix, double x0, size_t iy)
 The first derivative of the function iy(ix) at ix=x0. More...
 
double deriv_const (size_t ix, double x0, size_t iy) const
 The first derivative of the function iy(ix) at ix=x0. More...
 
void deriv2 (std::string x, std::string y, std::string yp)
 Make a new column yp which is $ y^{\prime \prime}(x) $ - O(log(C)*R).
 
double deriv2 (std::string sx, double x0, std::string sy)
 The second derivative of the function sy(sx) at sx=x0. More...
 
double deriv2_const (std::string sx, double x0, std::string sy) const
 The second derivative of the function sy(sx) at sx=x0. More...
 
double deriv2 (size_t ix, double x0, size_t iy)
 The second derivative of the function iy(ix) at ix=x0. More...
 
double deriv2_const (size_t ix, double x0, size_t iy) const
 The second derivative of the function iy(ix) at ix=x0. More...
 
double integ (std::string sx, double x1, double x2, std::string sy)
 The integral of the function sy(sx) from sx=x1 to sx=x2. More...
 
double integ_const (std::string sx, double x1, double x2, std::string sy) const
 The integral of the function sy(sx) from sx=x1 to sx=x2. More...
 
double integ (size_t ix, double x1, double x2, size_t iy)
 The integral of the function iy(ix) from ix=x1 to ix=x2. More...
 
double integ_const (size_t ix, double x1, double x2, size_t iy) const
 The integral of the function iy(ix) from ix=x1 to ix=x2. More...
 
void integ (std::string x, std::string y, std::string ynew)
 The integral of the function iy(ix) More...
 
double max (std::string scol) const
 Return column maximum. Makes no assumptions about ordering $ {\cal O}(R) $.
 
double min (std::string scol) const
 Return column minimum. Makes no assumptions about ordering $ {\cal O}(R) $.
 
void subtable (std::string list, size_t top, size_t bottom, table< vec_t > &tnew) const
 Make a subtable. More...
 
void zero_table ()
 Zero the data entries but keep the column names and nlines fixed.
 
void clear ()
 Clear everything.
 
void clear_table ()
 Clear the table and the column names (but leave constants)
 
void clear_data ()
 Remove all of the data by setting the number of lines to zero. More...
 
void clear_constants ()
 CLear all constants.
 
void sort_table (std::string scol)
 Sort the entire table by the column scol. More...
 
void sort_column (std::string scol)
 Individually sort the column scol.
 
virtual void add_constant (std::string name, double val)
 Add a constant, or if the constant already exists, change its value.
 
virtual int set_constant (std::string name, double val, bool err_on_notfound=true)
 Set a constant equal to a value, but don't add it if not already present. More...
 
virtual bool is_constant (std::string name) const
 Test if name is a constant.
 
virtual double get_constant (std::string name) const
 Get a constant.
 
virtual size_t get_nconsts () const
 Get the number of constants.
 
virtual void get_constant (size_t ix, std::string &name, double &val) const
 Get a constant by index.
 
virtual void remove_constant (std::string name)
 Remove a constant.
 
void check_synchro () const
 Return 0 if the tree and list are properly synchronized.
 
void functions_columns (std::string list)
 Create new columns or recompute from a list of functions. More...
 
void function_column (std::string function, std::string scol)
 Make a column from the function specified in function and add it to the table. More...
 
template<class resize_vec_t >
int function_vector (std::string function, resize_vec_t &vec, bool throw_on_err=true)
 Compute a column from a function specified in a string. More...
 
double row_function (std::string function, size_t row) const
 Compute a value by applying a function to a row.
 
size_t function_find_row (std::string function) const
 Find a row which maximizes a function.
 

Protected Types

Unit map iterator types
typedef std::map< std::string, std::string, std::greater< std::string > >::iterator uiter
 
typedef std::map< std::string, std::string, std::greater< std::string > >::const_iterator uciter
 
- Protected Types inherited from o2scl::table< vec_t >
typedef std::map< std::string, col, std::greater< std::string > >::iterator aiter
 Map iterator type.
 
typedef std::map< std::string, col, std::greater< std::string > >::const_iterator aciter
 Const map iterator type.
 
typedef std::vector< aiter >::iterator aviter
 Vector iterator type.
 

Protected Attributes

convert_unitscup
 The pointer to the convert units object.
 
std::map< std::string, std::string, std::greater< std::string > > utree
 Unit map.
 
- Protected Attributes inherited from o2scl::table< vec_t >
std::map< std::string, double > constants
 The list of constants.
 
vec_t empty_col
 An empty vector for get_column()
 
size_t maxlines
 The size of allocated memory.
 
size_t nlines
 The size of presently used memory.
 
std::map< std::string, col, std::greater< std::string > > atree
 The tree of columns.
 
std::vector< aiteralist
 The list of tree iterators.
 
bool intp_set
 True if the interpolation object is up-to-date.
 
size_t itype
 Current interpolation type.
 
interp_vec< vec_t > * si
 Interpolation object.
 
std::string intp_colx
 The last x-column interpolated.
 
std::string intp_coly
 The last y-column interpolated.
 

Friends

void o2scl_hdf::hdf_output (o2scl_hdf::hdf_file &hf, table_units<> &t, std::string name)
 
template<class vecf_t >
void o2scl_hdf::hdf_input (o2scl_hdf::hdf_file &hf, table_units< vecf_t > &t, std::string name)
 
void o2scl_hdf::hdf_output_data (o2scl_hdf::hdf_file &hf, table_units<> &t)
 
template<class vecf_t >
void o2scl_hdf::hdf_input_data (o2scl_hdf::hdf_file &hf, table_units< vecf_t > &t)
 

Additional Inherited Members

- Protected Member Functions inherited from o2scl::table< vec_t >
void reset_list ()
 Set the elements of alist with the appropriate iterators from atree. $ {\cal O}(C) $. More...
 
void make_fp_varname (std::string &s)
 Ensure a variable name does not match a function or contain non-alphanumeric characters.
 
void make_unique_name (std::string &colx, std::vector< std::string > &cnames)
 Make sure a name is unique.
 
aiter get_iterator (std::string lname)
 Return the iterator for a column.
 
colget_col_struct (std::string lname)
 Return the column structure for a column.
 
aiter begin ()
 Return the beginning of the column tree.
 
aiter end ()
 Return the end of the column tree.
 

Detailed Description

template<class vec_t = std::vector<double>>
class o2scl::table_units< vec_t >

Idea for Future:
The unit conversion object is now always a pointer to the global conversion object. This could be modified, so that each table can have it's own, but this might require HDF output of unit conversion objects.
Idea for Future:
Make table methods virtual? (not necessary yet since delete_column() isn't referred to internally)

Definition at line 37 of file table_units.h.

Member Function Documentation

◆ copy_column()

template<class vec_t = std::vector<double>>
virtual void o2scl::table_units< vec_t >::copy_column ( std::string  src,
std::string  dest 
)
inlinevirtual

This function also sets the units of column dest to be the same as that in src, even if the column named dest already exists and previously had different units.

Reimplemented from o2scl::table< vec_t >.

Definition at line 595 of file table_units.h.

◆ copy_rows()

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table_units< vec_t >::copy_rows ( std::string  func,
table_units< vec2_t > &  dest 
)
inline

This function begins by ensuring that all columns in the current table are present in dest, creating new columns (and copying their units) in dest if necessary. It then copies all rows where func evaluates to a number greater than 0.5 to table dest by adding rows at the end of the table.

Definition at line 313 of file table_units.h.

◆ get_unit()

template<class vec_t = std::vector<double>>
std::string o2scl::table_units< vec_t >::get_unit ( size_t  i) const
inline
Idea for Future:
Is there a way to make this function have O(1) time rather than searching?

Definition at line 366 of file table_units.h.


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

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