Class table_units (o2scl)¶
-
template<class vec_t = std::vector<double>>
class table_units : public o2scl::table<std::vector<double>, double>¶ Data class with units.
- 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)
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¶
-
std::map<std::string, std::string, std::greater<std::string>> utree¶
Unit map.
Virtual functions from \ref table
-
convert_units<double> *cup¶
The pointer to the convert units object.
-
inline virtual void clear_table()¶
Clear the table and the column names and units (but leave constants)
-
inline virtual void delete_column(std::string scol)¶
Delete column named
scol
.
-
inline virtual void rename_column(std::string src, std::string dest)¶
Rename column named
src
todest
\( {\cal O}(C) \).
-
inline virtual void summary(std::ostream *out, size_t ncol = 79) const¶
Output a summary of the information stored.
-
inline virtual const char *type()¶
Return the type,
"table_units"
.
-
inline virtual void copy_column(std::string src, std::string dest)¶
Copy data from column named
src
to column nameddest
, creating a new column if necessary \( {\cal O}(R \log(C)) \).This function also sets the units of column
dest
to be the same as that insrc
, even if the column nameddest
already exists and previously had different units.
-
inline 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>
inline 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)
This takes all of the columns in
source
, and adds them into the current table using interpolation, using the columnssrc_index
anddest_index
as the independent variable. The column namedsrc_index
is the column of the independent variable insource
and the column nameddest_index
is the column of the independent variable in the current table. Ifdest_index
is empty (the default) then the names in the two tables are taken to be the same.If necessary, columns are created in the current table for the dependent variable columns in
source
. Columns in the current table which do not correspond to dependent variable columns insource
are left unchanged.If
allow_extrap
is false, then extrapolation is not allowed, and rows in the current table which have values of the independent variable which are outside the source table are unmodified.If a column for a dependent variable in
source
has the same name asdest_index
, then it is ignored and not inserted into the current table.If the column named
src_index
cannot be found insource
or the column namesdest_index
cannot be found in the current table, then the error handler is called.If the
allow_extrap
is false and either the minimum or maximum values of the column namedsrc_index
in thesource
table are not finite, then the error handler is called.
-
friend void hdf_output(o2scl_hdf::hdf_file &hf, table_units<> &t, std::string name)¶
-
template<class vecf_t>
friend void hdf_input(o2scl_hdf::hdf_file &hf, table_units<vecf_t> &t, std::string name)¶
-
friend void hdf_output_data(o2scl_hdf::hdf_file &hf, table_units<> &t)¶
-
template<class vecf_t>
friend void hdf_input_data(o2scl_hdf::hdf_file &hf, table_units<vecf_t> &t)¶
Copy constructors
-
inline table_units(const table_units &t)¶
Copy with constructor from table_units.
-
inline table_units &operator=(const table_units &t)¶
Copy with
operator=
from table_units.
-
inline table_units &operator=(const table<vec_t, double> &t)¶
Copy with
operator=
from table.
-
template<class vec2_t>
inline void copy_rows(std::string func, table_units<vec2_t> &dest, int loc_verbose = 0)¶ Copy all rows matching a particular condition to a new table.
This function begins by ensuring that all columns in the current table are present in
dest
, creating new columns (and copying their units) indest
if necessary. It then copies all rows wherefunc
evaluates to a number greater than 0.5 to tabledest
by adding rows at the end of the table.
Unit manipulation
-
inline std::string get_unit(std::string scol) const¶
Get the unit for column
scol
.
-
inline void line_of_units(std::string unit_line)¶
Specify the units as a string separated by spaces.
-
inline void copy_names_and_units(table_units &src)¶
Copy all names and units from
src
to the current table.If a column in the source table is already present in the current table, then its unit is unchanged. If all columns in the source are already present in the current table, then this function silently does nothing.
-
inline std::string get_unit(size_t i) const¶
Get the unit for column with index i.
- Idea for Future:
Is there a way to make this function have O(1) time rather than searching?
-
inline void remove_unit(std::string scol)¶
Remove the unit for column
scol
.
-
inline void set_unit(std::string scol, std::string unit)¶
Set the unit for column
scol
tounit
.
-
inline int convert_to_unit(std::string scol, std::string unit, bool err_on_fail = true)¶
Convert the units of column
scol
tounit
.
-
inline size_t get_nunits()¶
Return the number of columns with units.
Public Functions
-
inline table_units(int cmaxlines = 0)¶
Create a new table_units with space for nlines<=cmaxlines.
-
inline virtual ~table_units()¶