1 #ifndef GUARD_GGEMS_TOOLS_GGEMSSYSTEMOFUNITS_HH
2 #define GUARD_GGEMS_TOOLS_GGEMSSYSTEMOFUNITS_HH
38 #ifndef __OPENCL_C_VERSION__
43 #define __constant inline static constexpr
192 #ifndef __OPENCL_C_VERSION__
201 "y",
"z",
"a",
"f",
"p",
"n",
"u",
"m",
205 "k",
"M",
"G",
"T",
"P",
"E",
"Z",
"Y"
216 template <
typename T>
219 std::string base_unit =
"m";
222 GGint index =
static_cast<GGint>(std::log(std::fabs(
static_cast<GGdouble>(value)))/std::log(1000.0)) + 7;
223 index = (index < 0) ? 0 : index;
224 index = (index > 16) ? 16 : index;
226 if (
static_cast<GGdouble>(value) == 0.0) index = 7;
228 std::ostringstream oss(std::stringstream::out);
229 oss << static_cast<GGdouble>(value)/std::pow(1000, index - 7) <<
" " <<
::prefix_unit[index]+base_unit;
242 template <
typename T>
245 T new_value =
static_cast<T>(0);
247 new_value =
static_cast<T>(value *
nm);
249 else if (unit ==
"um") {
250 new_value =
static_cast<T>(value *
um);
252 else if (unit ==
"mm") {
253 new_value =
static_cast<T>(value *
mm);
255 else if (unit ==
"cm") {
256 new_value =
static_cast<T>(value *
cm);
258 else if (unit ==
"m") {
259 new_value =
static_cast<T>(value *
m);
261 else if (unit ==
"km") {
262 new_value =
static_cast<T>(value *
km);
264 else if (unit ==
"pc") {
265 new_value =
static_cast<T>(value *
pc);
268 std::ostringstream oss(std::ostringstream::out);
269 oss <<
"Unknown unit!!! You have choice between:" << std::endl;
270 oss <<
" - \"nm\": nanometer" << std::endl;
271 oss <<
" - \"um\": micrometer" << std::endl;
272 oss <<
" - \"mm\": millimeter" << std::endl;
273 oss <<
" - \"cm\": centimeter" << std::endl;
274 oss <<
" - \"m\": meter" << std::endl;
275 oss <<
" - \"km\": kilometer" << std::endl;
276 oss <<
" - \"pc\": parsec";
289 template <
typename T>
292 std::string base_unit =
"eV";
295 GGint index =
static_cast<GGint>(std::log(std::fabs(
static_cast<GGdouble>(value)))/std::log(1000.0)) + 10;
296 index = (index < 0) ? 0 : index;
297 index = (index > 16) ? 16 : index;
299 if (
static_cast<GGdouble>(value) == 0.0) index = 8;
301 std::ostringstream oss(std::stringstream::out);
302 oss << static_cast<GGdouble>(value)/std::pow(1000, index - 10) <<
" " <<
::prefix_unit[index]+base_unit;
315 template <
typename T>
318 T new_value =
static_cast<T>(0);
320 new_value =
static_cast<T>(value *
eV);
322 else if (unit ==
"keV") {
323 new_value =
static_cast<T>(value *
keV);
325 else if (unit ==
"MeV") {
326 new_value =
static_cast<T>(value *
MeV);
328 else if (unit ==
"GeV") {
329 new_value =
static_cast<T>(value *
GeV);
331 else if (unit ==
"TeV") {
332 new_value =
static_cast<T>(value *
TeV);
334 else if (unit ==
"PeV") {
335 new_value =
static_cast<T>(value *
PeV);
338 std::ostringstream oss(std::ostringstream::out);
339 oss <<
"Unknown unit!!! You have choice between:" << std::endl;
340 oss <<
" - \"eV\": electronvolt" << std::endl;
341 oss <<
" - \"keV\": kiloelectronvolt" << std::endl;
342 oss <<
" - \"MeV\": megaelectronvolt" << std::endl;
343 oss <<
" - \"GeV\": gigaelectronvolt" << std::endl;
344 oss <<
" - \"TeV\": teraelectronvolt" << std::endl;
345 oss <<
" - \"PeV\": petaelectronvolt" << std::endl;
359 template <
typename T>
362 T new_value =
static_cast<T>(0);
364 new_value =
static_cast<T>(value *
rad);
366 else if (unit ==
"mrad") {
367 new_value =
static_cast<T>(value *
mrad);
369 else if (unit ==
"deg") {
370 new_value =
static_cast<T>(value *
deg);
372 else if (unit ==
"sr") {
373 new_value =
static_cast<T>(value *
sr);
376 std::ostringstream oss(std::ostringstream::out);
377 oss <<
"Unknown unit!!! You have choice between:" << std::endl;
378 oss <<
" - \"rad\": radian" << std::endl;
379 oss <<
" - \"mrad\": milliradian" << std::endl;
380 oss <<
" - \"deg\": degree" << std::endl;
381 oss <<
" - \"sr\": steradian" << std::endl;
395 template <
typename T>
398 T new_value =
static_cast<T>(0);
399 if (unit ==
"g/cm3") {
400 new_value =
static_cast<T>(value *
g/
cm3);
402 else if (unit ==
"kg/m3") {
403 new_value =
static_cast<T>(value *
kg/
m3);
405 else if (unit ==
"mg/cm3") {
406 new_value =
static_cast<T>(value *
mg/
cm3);
409 std::ostringstream oss(std::ostringstream::out);
410 oss <<
"Unknown unit!!! You have choice between:" << std::endl;
411 oss <<
" - \"g/cm3\": gram per cubic centimeter" << std::endl;
412 oss <<
" - \"kg/m3\": kilogram per cubic meter" << std::endl;
413 oss <<
" - \"mg/cm3\": milligram per cubic centimeter" << std::endl;
427 std::string base_unit =
"B";
430 GGint index =
static_cast<GGint>(std::log(
static_cast<GGdouble>(value))/std::log(1000.0)) + 8;
431 index = (index < 8) ? 8 : index;
432 index = (index > 16) ? 16 : index;
434 if (value == 0) index = 8;
436 std::ostringstream oss(std::stringstream::out);
437 oss << static_cast<GGdouble>(value)/std::pow(1000, index - 8) <<
" " <<
::prefix_unit[index]+base_unit;
443 #endif // End of GUARD_GGEMS_TOOLS_GGEMSSYSTEMOFUNITS_HH