ReFRACtor
double_with_unit.h
Go to the documentation of this file.
1 #ifndef DOUBLE_WITH_UNIT_H
2 #define DOUBLE_WITH_UNIT_H
3 #include "printable.h"
4 #include "unit.h"
5 #include <cmath>
6 
7 namespace FullPhysics {
8  class SpectralDomain;
9 /****************************************************************/
13 class DoubleWithUnit : public Printable<DoubleWithUnit>,
14  boost::ordered_field_operators<DoubleWithUnit> {
15 public:
17  DoubleWithUnit(double V, const Unit& U)
18  : value(V), units(U) {}
19  DoubleWithUnit(double V, const std::string& U)
20  : value(V), units(U) {}
21  DoubleWithUnit(double V)
22  : value(V), units(units::dimensionless) {}
23  double value;
25 
26 //-----------------------------------------------------------------------
28 //-----------------------------------------------------------------------
30  { value *= D.value; units *= D.units; return *this;}
32  { value /= D.value; units /= D.units; return *this;}
34  { value += D.value * FullPhysics::conversion(D.units, units); return *this;}
36  { value -= D.value * FullPhysics::conversion(D.units, units); return *this;}
37 
38 //-----------------------------------------------------------------------
40 //-----------------------------------------------------------------------
41 
42  inline DoubleWithUnit convert(const Unit& R) const
43  { return DoubleWithUnit(value * FullPhysics::conversion(units, R), R); }
44 
45 //-----------------------------------------------------------------------
51 //-----------------------------------------------------------------------
52 
53  inline DoubleWithUnit convert_wave(const Unit& R) const
54  {
55  if(units.is_commensurate(R))
56  return convert(R);
57  else
58  return (1.0 / *this).convert(R);
59  }
60 
62  const SpectralDomain& Pixel_grid) const;
63 
64  void print(std::ostream& Os) const
65  { Os << value << " " << units.name(); }
66 
67 };
68 
69 //-----------------------------------------------------------------------
71 // Compare DoubleWithUnits
74 //-----------------------------------------------------------------------
76 { return A.value < B.convert(A.units).value; }
77 
79 //-----------------------------------------------------------------------
81 { return A.value == B.convert(A.units).value; }
82 
83 
84 }
85 
86 
87 //-----------------------------------------------------------------------
89 //-----------------------------------------------------------------------
90 namespace std {
91  // Math functions are in std:: namespace.
93  {
95  }
96 
98  {
100  }
101 
103  {
105  }
106 
108  {
110  }
111 
113  {
115  }
116 
117 }
118 
119 #endif
DoubleWithUnit convert_wave(const Unit &R) const
We often need to handle conversion from wavenumber to/from wavelength.
FullPhysics::DoubleWithUnit min(const FullPhysics::DoubleWithUnit &x, const FullPhysics::DoubleWithUnit &y)
FullPhysics::DoubleWithUnit max(const FullPhysics::DoubleWithUnit &x, const FullPhysics::DoubleWithUnit &y)
DoubleWithUnit & operator-=(const DoubleWithUnit &D)
FullPhysics::DoubleWithUnit floor(const FullPhysics::DoubleWithUnit &x)
For different instruments, it is more natural to either work with wavenumbers (e.g., GOSAT) or wavelength (e.g., OCO).
const Unit dimensionless("dimensionless", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
double conversion(const Unit &Dunit_from, const Unit &Dunit_to)
Return conversion factor to go from one unit to another.
Definition: unit.cc:180
STL namespace.
DoubleWithUnit & operator/=(const DoubleWithUnit &D)
DoubleWithUnit & operator+=(const DoubleWithUnit &D)
This is a Mixin for classes that can be printed.
Definition: printable.h:24
void print(std::ostream &Os) const
const Unit A("A", 1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)
DoubleWithUnit & operator*=(const DoubleWithUnit &D)
Basic math operators for class.
We frequently have a double with units associated with it.
DoubleWithUnit convert(const Unit &R) const
Convert to the given units.
Libraries such as boost::units allow unit handling where we know the units at compile time...
Definition: unit.h:25
DoubleWithUnit(double V, const std::string &U)
bool is_commensurate(const Unit &Units) const
Test if this set of units is commensurate with another set.
Definition: unit.h:68
FullPhysics::DoubleWithUnit round(const FullPhysics::DoubleWithUnit &x)
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
DoubleWithUnit(double V, const Unit &U)
bool operator<(const FullPhysics::DoubleWithUnit &A, const FullPhysics::DoubleWithUnit &B)
const std::string & name() const
Name of unit. May be an empty string if a name wasn&#39;t assigned.
Definition: unit.h:77
FullPhysics::DoubleWithUnit ceil(const FullPhysics::DoubleWithUnit &x)
bool operator==(const FullPhysics::DoubleWithUnit &A, const FullPhysics::DoubleWithUnit &B)
We define != in terms of this operator.

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11