This class converts units. More...
#include "../include/Unit.h"
Public Member Functions | |
| Unit () | |
| int | init () |
| bool | valid (const char *in, const char *out) |
| float | convert (float value, const char *in, const char *out) |
| int | readFile (const char *uin, const char *uout, UnitData &data) |
Static Public Member Functions | |
| static int | scale (const char *in, float rscale, const char *mstr, String &out) |
| static int | parse (const char *str, String &var, String &units) |
| static int | change (String &str, const char *units) |
| static bool | equal (const char *unit1, const char *unit2) |
| static int | simplify (char *unit) |
| static int | simplify (String &unit) |
This class converts units.
| Unit::Unit | ( | ) |
Constructor. Initializes class values
References init().
| int Unit::change | ( | String & | str, | |
| const char * | units | |||
| ) | [static] |
Changes the units string in a variable specification
| str | Input variable string (output) | |
| units | New units string |
References WXP::String::get(), parse(), and WXP::String::printf().
| float Unit::convert | ( | float | value, | |
| const char * | in, | |||
| const char * | out | |||
| ) |
Converts the units of a value
| value | The original value | |
| unit_in | The original units | |
| unit_out | The output units |
References WXP::StrLib::copy(), WXP::StrLib::iequal(), WXP::Wxp::isDebug(), WXP::Const::MISS, readFile(), WXP::StrLib::replace(), and valid().
Referenced by WXP::UpaDataTool::compute(), WXP::SfcDataTool::compute(), WXP::MosDataTool::compute(), WXP::GridMath::units(), and WXP::DataMath::units().
| bool Unit::equal | ( | const char * | unit1, | |
| const char * | unit2 | |||
| ) | [static] |
Compares two units
| unit1 | First unit specification | |
| unit2 | Second unit specification |
Referenced by WXP::GridMath::units(), and WXP::DataMath::units().
| int Unit::init | ( | ) |
Initializes class values
Referenced by Unit().
Parses units out of variable specification
| str | Input variable string |
| rvar | Output variable name | |
| runits | Output units string |
References WXP::StrLib::copy(), WXP::StrLib::index(), WXP::String::set(), and WXP::StrLib::trimWS().
Referenced by change().
| int Unit::readFile | ( | const char * | uin, | |
| const char * | uout, | |||
| UnitData & | data | |||
| ) |
Gets the unit information from file giving the input and output units. The conversion values are saved for future conversions.
| uin | Input units | |
| uout | Output units |
References WXP::FileTool::addPath(), WXP::StrLib::copy(), WXP::String::get(), WXP::Wxp::getDatabasePath(), and WXP::StrLib::iequal().
| int Unit::scale | ( | const char * | in, | |
| float | rscale, | |||
| const char * | mstr, | |||
| String & | out | |||
| ) | [static] |
Scales values and changes unit scale factor.
| in | Input units and scale factor | |
| rscale | Scale factor | |
| mstr | Multiplier unit |
| out | Output string for new unit |
References WXP::String::printf().
| bool Unit::valid | ( | const char * | in, | |
| const char * | out | |||
| ) |
Checks validity of unit conversion. If the conversion is not available, the result is false. This can be used to check to make sure temperature units are not being used with length and so on.
| unit_in | The original units | |
| unit_out | The output units |
References WXP::StrLib::copy(), WXP::StrLib::iequal(), readFile(), WXP::StrLib::replace(), and WXP::StrLib::valid().
Referenced by convert(), and WXP::GridMath::units().
1.6.1