Gyoto
Classes | Functions
Gyoto::Units Namespace Reference

Units-related classes and functions. More...

Classes

class  Converter
 Wrapper around ut_converter from udunits. More...
 
class  Unit
 Wrapper around ut_unit from udunits. More...
 

Functions

ut_system * getSystem ()
 Retrieve the unit system used in all of Gyoto.
 
void Init ()
 Load and initialize all (non-context-sensitive) units. More...
 
double ToMeters (double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
 Convert from arbitrary length unit to meters. More...
 
double FromMeters (double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
 Convert to arbitrary length unit from meters. More...
 
double ToSeconds (double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
 Convert from arbitrary time unit to seconds. More...
 
double FromSeconds (double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
 Convert to arbitrary time unit from seconds. More...
 
double ToKilograms (double value, const std::string &unit)
 Convert from arbitrary mass unit to kilograms. More...
 
double FromKilograms (double value, const std::string &unit)
 Convert to arbitrary mass unit from kilograms. More...
 
double ToGeometrical (double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
 Convert from arbitrary length unit to geometrical units. More...
 
double FromGeometrical (double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
 Convert to arbitrary length unit from geometrical units. More...
 
double ToGeometricalTime (double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
 Convert from arbitrary time unit to geometrical units. More...
 
double FromGeometricalTime (double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
 Convert to arbitrary time unit from geometrical units. More...
 
double ToHerz (double value, const std::string &unit)
 Convert from arbitrary frequency unit to Herz. More...
 
double FromHerz (double value, const std::string &unit)
 Convert to arbitrary frequency unit from Herz. More...
 
bool areConvertible (const Unit &unit1, const Unit &unit2)
 Is it possible to convert between unit1 and unit2? More...
 

Detailed Description

Units-related classes and functions.

Function Documentation

◆ areConvertible()

bool Gyoto::Units::areConvertible ( const Unit unit1,
const Unit unit2 
)

Is it possible to convert between unit1 and unit2?

e.g. areConvertible("m", "kg") == 0; areConvertible("m", "km")==1.

Warning: angle units are dimensionless, therefore e.g. areConvertible("Jy", "Jy/microacsec2")==1. Numerically, "Jy" is the same as "Jy/sr2".

Parameters
unit1(Gyoto::Units::Unit) first unit
unit2(Gyoto::Units::Unit) second unit
Returns
bool, True if it is possible to convert between the two units, 0 otherwise.

◆ FromGeometrical()

double Gyoto::Units::FromGeometrical ( double  value,
const std::string &  unit,
const Gyoto::SmartPointer< Gyoto::Metric::Generic > &  gg 
)

Convert to arbitrary length unit from geometrical units.

Convert value to unit represented by "unit" from geometrical units.

Parameters
value(double) the value to convert, expressed in geometrical units.
unit(std::string) the "unit" to which to convert, e.g. "km", "sunradius" or "geometrical". More units are supported if Gyoto was compiled with udunits support.
gg(const Gyoto::SmartPointer<Gyoto::Metric::Generic> &) metric to interpret "geometrical".
Returns
value, expressed in "unit".

◆ FromGeometricalTime()

double Gyoto::Units::FromGeometricalTime ( double  value,
const std::string &  unit,
const Gyoto::SmartPointer< Gyoto::Metric::Generic > &  gg 
)

Convert to arbitrary time unit from geometrical units.

Parameters
value(double) the value to convert, expressed in geometrical units.
unit(std::string) the "unit" to which to convert, e.g. "yr", "s" or "geometrical_time". More units are supported if Gyoto was compiled with udunits support.
gg(const Gyoto::SmartPointer<Gyoto::Metric::Generic> &) metric to interpret "geometrical_time".
Returns
value, expressed in "unit".

◆ FromHerz()

double Gyoto::Units::FromHerz ( double  value,
const std::string &  unit 
)

Convert to arbitrary frequency unit from Herz.

FromHerz will also convert to length and energy units (such as "eV").

Parameters
value(double) the value to convert, expressed according in "Hz".
unit(std::string) the "unit" from which to convert, e.g. "MHz", "keV"
Returns
value, expressed in "units".

◆ FromKilograms()

double Gyoto::Units::FromKilograms ( double  value,
const std::string &  unit 
)

Convert to arbitrary mass unit from kilograms.

Convert value from unit represented by "unit" from kilograms.

Parameters
value(double) the value to convert, expressed inkilograms.
unit(std::string) the "unit" to which to convert, e.g. "g", "kg" or "sunmass". More units are supported if Gyoto was compiled with udunits support.
Returns
value, expressed in "unit".

◆ FromMeters()

double Gyoto::Units::FromMeters ( double  value,
const std::string &  unit,
const Gyoto::SmartPointer< Gyoto::Metric::Generic > &  gg = NULL 
)

Convert to arbitrary length unit from meters.

Convert value to unit represented by "unit" from meters.

If gg is provided (and not NULL), use it to interpret the string "geometrical" as representing gg->Gyoto::Metric::Generic::unitLength().

ToMeters() will also convert to time, frequency and energy units (as in wavelength -> frequency).

Parameters
value(double) the value to convert, expressed in meters.
unit(std::string) the "unit" to which to convert, e.g. "km", "sunradius" or "geometrical". More units are supported if Gyoto was compiled with udunits support.
gg(const Gyoto::SmartPointer<Gyoto::Metric::Generic> &, NULL if not specified) optional metric to interpret "geometrical".
Returns
value, expressed in "unit".

◆ FromSeconds()

double Gyoto::Units::FromSeconds ( double  value,
const std::string &  unit,
const Gyoto::SmartPointer< Gyoto::Metric::Generic > &  gg = NULL 
)

Convert to arbitrary time unit from seconds.

Convert value to unit represented by "unit" from seconds.

If gg is provided (and not NULL), use it to interpret the string "geometrical_time" as representing gg->Gyoto::Metric::Generic::unitLength()/GYOTO_C.

Parameters
value(double) the value to convert, expressed in seconds.
unit(std::string) the "unit" to which to convert, e.g. "s", "yr" or "geometrical_time". More units are supported if Gyoto was compiled with udunits support.
gg(const Gyoto::SmartPointer<Gyoto::Metric::Generic> &, NULL if not specified) optional metric to interpret "geometrical".
Returns
value, expressed in "unit".

◆ Init()

void Gyoto::Units::Init ( )

Load and initialize all (non-context-sensitive) units.

If udunits is used (preprocessor macro HAVE_UDUNITS), Init() initializes the ut_system used throughout Gyoto and maps a few additional units to the unit system.

◆ ToGeometrical()

double Gyoto::Units::ToGeometrical ( double  value,
const std::string &  unit,
const Gyoto::SmartPointer< Gyoto::Metric::Generic > &  gg 
)

Convert from arbitrary length unit to geometrical units.

Convert value from unit represented by "unit" to geometrical units.

Parameters
value(double) the value to convert, expressed according to "unit".
unit(std::string) the "unit" from which to convert, e.g. "km", "sunradius" or "geometrical". More units are supported if Gyoto was compiled with udunits support.
gg(const Gyoto::SmartPointer<Gyoto::Metric::Generic> &) metric to interpret "geometrical".
Returns
value, expressed in geometrical units.

◆ ToGeometricalTime()

double Gyoto::Units::ToGeometricalTime ( double  value,
const std::string &  unit,
const Gyoto::SmartPointer< Gyoto::Metric::Generic > &  gg 
)

Convert from arbitrary time unit to geometrical units.

Parameters
value(double) the value to convert, expressed according to "unit".
unit(std::string) the "unit" from which to convert, e.g. "s", "kyr" or "geometrical_time". More units are supported if Gyoto was compiled with udunits support.
gg(const Gyoto::SmartPointer<Gyoto::Metric::Generic> &) metric to interpret "geometrical_time".
Returns
value, expressed in geometrical (time) units.

◆ ToHerz()

double Gyoto::Units::ToHerz ( double  value,
const std::string &  unit 
)

Convert from arbitrary frequency unit to Herz.

ToHerz will also convert from length and energy units (such as "eV").

Parameters
value(double) the value to convert, expressed according to "unit".
unit(std::string) the "unit" from which to convert, e.g. "MHz", "keV"
Returns
value, expressed in "Hz".

◆ ToKilograms()

double Gyoto::Units::ToKilograms ( double  value,
const std::string &  unit 
)

Convert from arbitrary mass unit to kilograms.

Convert value from unit represented by "unit" to kilograms.

Parameters
value(double) the value to convert, expressed according to "unit"
unit(std::string) the "unit" from which to convert, e.g. "g", "kg" or "sunmass". More units are supported if Gyoto was compiled with udunits support.
Returns
value, expressed in kilograms.

◆ ToMeters()

double Gyoto::Units::ToMeters ( double  value,
const std::string &  unit,
const Gyoto::SmartPointer< Gyoto::Metric::Generic > &  gg = NULL 
)

Convert from arbitrary length unit to meters.

Convert value from unit represented by "unit" to meters.

If gg is provided (and not NULL), use it to interpret the string "geometrical" as representing gg->Gyoto::Metric::Generic::unitLength().

ToMeters() will also convert time, frequency and energy units to meters (as in frequency -> wavelength).

Parameters
value(double) the value to convert, expressed according to "unit"
unit(std::string) the "unit" from which to convert, e.g. "km", "sunradius" or "geometrical". More units are supported if Gyoto was compiled with udunits support.
gg(const Gyoto::SmartPointer<Gyoto::Metric::Generic> &, NULL if not specified) optional metric to interpret "geometrical".
Returns
value, expressed in meters.

◆ ToSeconds()

double Gyoto::Units::ToSeconds ( double  value,
const std::string &  unit,
const Gyoto::SmartPointer< Gyoto::Metric::Generic > &  gg = NULL 
)

Convert from arbitrary time unit to seconds.

Convert value from unit represented by "unit" to seconds.

If gg is provided (and not NULL), use it to interpret the string "geometrical_time" as representing gg->Gyoto::Metric::Generic::unitLength()/GYOTO_C.

Parameters
value(double) the value to convert, expressed according to "unit"
unit(std::string) the "unit" from which to convert, e.g. "s", "yr" or "geometrical_time". More units are supported if Gyoto was compiled with udunits support.
gg(const Gyoto::SmartPointer<Gyoto::Metric::Generic> &, NULL if not specified) optional metric to interpret "geometrical".
Returns
value, expressed in seconds.