Convert units. More...
#include <convert_units.h>
Allow the user to convert between two different units after specifying a conversion factor. This class will also automatically combine two conversion factors to create a new unit conversion (but it cannot combine more than two).
Conversions are performed by the convert() function and the conversion factors must be specified beforehand using the insert_cache() function.
If the GNU units command is not in the local path, the user may modify units_cmd_string to specify the full pathname. One can also modify units_cmd_string to specify a different units.dat file.
Example:
An object of this type is created by o2scl_settings (of type lib_settings_class) for several unit conversions used internally in O2scl .
Definition at line 88 of file convert_units.h.
Classes | |
| struct | unit_t |
| The type for caching unit conversions. More... | |
Public Member Functions | |
| virtual double | convert (std::string from, std::string to, double val) |
Return the value val after converting using units from and to. | |
| virtual int | convert_ret (std::string from, std::string to, double val, double &converted) |
Return the value val after converting using units from and to, returning a non-zero value on failure. | |
| void | insert_cache (std::string from, std::string to, double conv) |
| Manually insert a unit conversion into the cache. | |
| void | remove_cache (std::string from, std::string to) |
| Manually remove a unit conversion into the cache. | |
| void | print_cache () |
| Print the present unit cache to std::cout. | |
| void | make_units_dat (std::string fname, bool c_1=false, bool hbar_1=false, bool K_1=false) |
Make a GNU units.dat file from the GSL constants. More... | |
Public Attributes | |
| int | verbose |
| Verbosity (default 0) | |
| bool | use_gnu_units |
| If true, use a system call to units to derive new conversions (default true) More... | |
| bool | err_on_fail |
| If true, throw an exception when a conversion fails (default true) | |
| bool | combine_two_conv |
| If true, allow combinations of two conversions (default true) | |
| std::string | units_cmd_string |
| Command string to call units (default "units") | |
Protected Types | |
| typedef std::map< std::string, unit_t, std::greater< std::string > >::iterator | miter |
| The iterator type. | |
Protected Attributes | |
| std::map< std::string, unit_t, std::greater< std::string > > | mcache |
| The cache where unit conversions are stored. | |
| void o2scl::convert_units::make_units_dat | ( | std::string | fname, |
| bool | c_1 = false, |
||
| bool | hbar_1 = false, |
||
| bool | K_1 = false |
||
| ) |
If c_1 is true, then the second is defined in terms of meters so that the speed of light is unitless. If hbar_1 is true, then the kilogram is defined in terms of s/m^2 so that
is unitless.
| bool o2scl::convert_units::use_gnu_units |
This also requires popen().
Definition at line 122 of file convert_units.h.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).