WXP C++ Library Version 6.74.9
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
WXP::Unit Class Reference

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)
 

Detailed Description

This class converts units.

Author
Dan Vietor

Constructor & Destructor Documentation

◆ Unit()

Unit::Unit ( )

Constructor. Initializes class values

References init().

Member Function Documentation

◆ change()

int Unit::change ( String str,
const char *  units 
)
static

Changes the units string in a variable specification

Parameters
strInput variable string (output)
unitsNew units string

References WXP::String::get(), parse(), and WXP::String::printf().

◆ convert()

float Unit::convert ( float  value,
const char *  in,
const char *  out 
)

Converts the units of a value

Parameters
valueThe original value
unit_inThe original units
unit_outThe output units
Returns
The new value with units converted

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().

◆ equal()

bool Unit::equal ( const char *  unit1,
const char *  unit2 
)
static

Compares two units

Parameters
unit1First unit specification
unit2Second unit specification

References WXP::StrLib::equal().

Referenced by WXP::DataMath::units(), and WXP::GridMath::units().

◆ init()

int Unit::init ( )

Initializes class values

References init().

Referenced by init(), and Unit().

◆ parse()

int Unit::parse ( const char *  str,
String rvar,
String runits 
)
static

Parses units out of variable specification

Parameters
strInput variable string
Return values
rvarOutput variable name
runitsOutput units string

References WXP::StrLib::copy(), WXP::StrLib::index(), WXP::String::set(), and WXP::StrLib::trimWS().

Referenced by change().

◆ readFile()

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.

Parameters
uinInput units
uoutOutput units

References WXP::FileTool::addPath(), WXP::StrLib::copy(), WXP::String::get(), WXP::Wxp::getDatabasePath(), WXP::StrLib::iequal(), WXP::File::scanf(), and WXP::File::skipLine().

Referenced by convert(), and valid().

◆ scale()

int Unit::scale ( const char *  in,
float  rscale,
const char *  mstr,
String out 
)
static

Scales values and changes unit scale factor.

Parameters
inInput units and scale factor
rscaleScale factor
mstrMultiplier unit
Return values
outOutput string for new unit

References WXP::String::printf().

◆ simplify() [1/2]

int Unit::simplify ( char *  unit)
static

Attempts to simplfy units

Parameters
unitUnit to simplify (modifies this string)

References WXP::StrLib::where().

Referenced by simplify().

◆ simplify() [2/2]

int Unit::simplify ( String unit)
static

Attempts to simplfy units

Parameters
unitUnit to simplify (modifies this string)

References WXP::String::get(), WXP::String::set(), and simplify().

◆ valid()

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.

Parameters
unit_inThe original units
unit_outThe output units
Returns
Valid or not

References WXP::StrLib::copy(), WXP::StrLib::iequal(), readFile(), WXP::StrLib::replace(), valid(), and WXP::StrLib::valid().

Referenced by convert(), WXP::GridMath::units(), and valid().


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