DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
Units.cpp
Go to the documentation of this file.
1// This file is part of DynExp.
2
3#include "Units.h"
4
5namespace DynExp::Units
6{
8 {
9 switch (Unit)
10 {
13 case UnitType::Index:
14 case UnitType::UnitlessInt: return true;
15 default: return false;
16 }
17 }
18
20 {
21 switch (Unit)
22 {
26 case UnitType::Volt:
29 case UnitType::Power_dBm: return true;
30 default: return false;
31 }
32 }
33
35 {
36 switch (Unit)
37 {
38 case UnitType::Index:
43 case UnitType::Time_ps: return true;
44 default: return false;
45 }
46 }
47
49 {
50 return IsTimeUnit(Unit) && Unit != UnitType::Index;
51 }
52
54 {
55 return Unit == UnitType::Index;
56 }
57
59 {
60 switch (Unit)
61 {
68 case UnitType::Wavelength_nm: return true;
69 default: return false;
70 }
71 }
72
73 const char* UnitCategoryToStr(UnitType Unit)
74 {
75 switch (Unit)
76 {
80 case UnitType::Volt:
83 case UnitType::Power_dBm: return "intensity";
84 case UnitType::Index: return "sample";
89 case UnitType::Time_ps: return "time";
95 case UnitType::Inv_cm: return "frequency";
96 case UnitType::Wavelength_nm: return "wavelength";
97 case UnitType::TperSqrtHz: return "amplitude spectral density";
99 case UnitType::UnitlessInt: return "number";
100 default: return "<unknown unit category>";
101 }
102 }
103
104 const char* UnitTypeToStr(UnitType Unit)
105 {
106 switch (Unit)
107 {
108 case UnitType::Arbitrary: return "a.u.";
109 case UnitType::LogicLevel: return "TTL";
110 case UnitType::Counts: return "#";
111 case UnitType::Volt: return "V";
112 case UnitType::Ampere: return "A";
113 case UnitType::Power_W: return "W";
114 case UnitType::Power_dBm: return "dBm";
115 case UnitType::Index: return "i";
116 case UnitType::Time_s: return "s";
117 case UnitType::Time_ms: return "ms";
118 case UnitType::Time_us: return "us";
119 case UnitType::Time_ns: return "ns";
120 case UnitType::Time_ps: return "ps";
121 case UnitType::Freq_Hz: return "Hz";
122 case UnitType::Freq_kHz: return "kHz";
123 case UnitType::Freq_MHz: return "MHz";
124 case UnitType::Freq_GHz: return "GHz";
125 case UnitType::Freq_THz: return "THz";
126 case UnitType::Inv_cm: return "1/cm";
127 case UnitType::Wavelength_nm: return "nm";
128 case UnitType::TperSqrtHz: return "T/sqrt(Hz)";
130 case UnitType::UnitlessInt: return "";
131 default: return "<unknown unit>";
132 }
133 }
134
135 std::string UnitToStr(UnitType Unit)
136 {
137 if (Unit == UnitType::Unitless || Unit == UnitType::UnitlessInt)
138 return UnitCategoryToStr(Unit);
139 else
140 return std::string(UnitCategoryToStr(Unit)) + " [" + UnitTypeToStr(Unit) + "]";
141 }
142}
Physical units used in DynExp. This file does not depend on further DynExp files and therefore can be...
bool IsIndexUnit(UnitType Unit)
Checks whether Unit is a sample index unit (UnitType::Index).
Definition Units.cpp:53
bool IsTimeUnit(UnitType Unit)
Checks whether Unit is a time-like unit.
Definition Units.cpp:34
UnitType
Units which can be used with DynExp instruments.
Definition Units.h:28
@ TperSqrtHz
Magnetic field amplitude spectral density in T/sqrt(Hz)
@ Freq_THz
Frequency in THz.
@ Ampere
Electric current in Ampere (A)
@ Inv_cm
Wavenumber in 1/cm.
@ Power_dBm
Power in dBm.
@ Arbitrary
Arbitrary units (a.u.)
@ Unitless
Unitless scalar number.
@ LogicLevel
Logic level (TTL) units (1 or 0)
@ Freq_Hz
Frequency in Hz.
@ Freq_GHz
Frequency in GHz.
@ Wavelength_nm
Wavelength in nm.
@ Index
Sample index.
@ Freq_kHz
Frequency in kHz.
@ UnitlessInt
Unitless scalar integer number.
@ Freq_MHz
Frequency in MHz.
@ Power_W
Power in Watt (W)
@ Volt
Voltage in Volt (V)
@ Counts
Count rate in counts per second (cps)
std::string UnitToStr(UnitType Unit)
Returns a descriptive string of a respective unit category and type to be e.g. used in plots.
Definition Units.cpp:135
const char * UnitCategoryToStr(UnitType Unit)
Returns a descriptive string of the given unit's category (e.g. 'intensity').
Definition Units.cpp:73
bool IsIntensityUnit(UnitType Unit)
Checks whether Unit is an intensity-like unit.
Definition Units.cpp:19
bool IsIntegerUnit(UnitType Unit)
Checks whether Unit implies integer values.
Definition Units.cpp:7
bool IsTimeUnitStrict(UnitType Unit)
Checks whether Unit is a time unit (excluding UnitType::Index).
Definition Units.cpp:48
bool IsFrequencyUnit(UnitType Unit)
Checks whether Unit is a frequency-like unit.
Definition Units.cpp:58
const char * UnitTypeToStr(UnitType Unit)
Returns a descriptive string of the given unit's type (e.g. 'dBm').
Definition Units.cpp:104