WXP C++ Library Version 6.74.9
|
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().
|
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::MosDataTool::compute(), WXP::SfcDataTool::compute(), WXP::UpaDataTool::compute(), WXP::DataMath::units(), and WXP::GridMath::units().
|
static |
Compares two units
unit1 | First unit specification |
unit2 | Second unit specification |
References WXP::StrLib::equal().
Referenced by WXP::DataMath::units(), and WXP::GridMath::units().
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(), WXP::StrLib::iequal(), WXP::File::scanf(), and WXP::File::skipLine().
|
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().
|
static |
Attempts to simplfy units
unit | Unit to simplify (modifies this string) |
References WXP::StrLib::where().
Referenced by simplify().
|
static |
Attempts to simplfy units
unit | Unit to simplify (modifies this string) |
References WXP::String::get(), WXP::String::set(), and simplify().
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(), valid(), and WXP::StrLib::valid().
Referenced by convert(), WXP::GridMath::units(), and valid().