Lemma is an Electromagnetics API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

helper.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 10/02/2014 03:21:07 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2014, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2014, Trevor Irons
  16. */
  17. #include "helper.h"
  18. namespace Lemma {
  19. std::string enum2String(const FREQUENCYUNITS& FreqUnits) {
  20. std::string t;
  21. switch (FreqUnits) {
  22. case HZ:
  23. t = std::string("HZ");
  24. break;
  25. case KHZ:
  26. t = std::string("KHZ");
  27. break;
  28. case MHZ:
  29. t = std::string("MHZ");
  30. break;
  31. case GHZ:
  32. t = std::string("GHZ");
  33. break;
  34. }
  35. return t;
  36. }
  37. std::string enum2String(const TIMEUNITS& Units) {
  38. std::string t;
  39. switch (Units) {
  40. case SEC:
  41. t = std::string("SEC");
  42. break;
  43. case MILLISEC:
  44. t = std::string("MILLISEC");
  45. break;
  46. case MICROSEC:
  47. t = std::string("MICROSEC");
  48. break;
  49. case NANOSEC:
  50. t = std::string("NANOSEC");
  51. break;
  52. case PICOSEC:
  53. t = std::string("PICOSEC");
  54. break;
  55. }
  56. return t;
  57. }
  58. std::string enum2String(const MAGUNITS& Units) {
  59. std::string t;
  60. switch (Units) {
  61. case TESLA:
  62. t = std::string("TESLA");
  63. break;
  64. case NANOTESLA:
  65. t = std::string("NANOTESLA");
  66. break;
  67. case GAUSS:
  68. t = std::string("GAUSS");
  69. break;
  70. }
  71. return t;
  72. }
  73. std::string enum2String(const FIELDCALCULATIONS& Field) {
  74. std::string t;
  75. switch (Field) {
  76. case E:
  77. t = std::string("E");
  78. break;
  79. case H:
  80. t = std::string("H");
  81. break;
  82. case BOTH:
  83. t = std::string("BOTH");
  84. break;
  85. }
  86. return t;
  87. }
  88. std::string enum2String(const TEMPUNITS& Units) {
  89. std::string t;
  90. switch (Units) {
  91. case CELCIUS:
  92. t = std::string("CELCIUS");
  93. break;
  94. case KELVIN:
  95. t = std::string("KELVIN");
  96. break;
  97. }
  98. return t;
  99. }
  100. std::string enum2String(const FIELDCOMPONENT& Comp) {
  101. std::string t;
  102. switch (Comp) {
  103. case XCOMPONENT:
  104. t = std::string("XCOMPONENT");
  105. break;
  106. case YCOMPONENT:
  107. t = std::string("YCOMPONENT");
  108. break;
  109. case ZCOMPONENT:
  110. t = std::string("ZCOMPONENT");
  111. break;
  112. }
  113. return t;
  114. }
  115. std::string enum2String(const HANKELTRANSFORMTYPE& Type) {
  116. std::string t;
  117. switch (Type) {
  118. case ANDERSON801:
  119. t = std::string("ANDERSON801");
  120. break;
  121. case CHAVE:
  122. t = std::string("CHAVE");
  123. break;
  124. case QWEKEY:
  125. t = std::string("QWEKEY");
  126. break;
  127. case FHTKEY201:
  128. t = std::string("FHTKEY201");
  129. break;
  130. case FHTKEY101:
  131. t = std::string("FHTKEY101");
  132. break;
  133. case FHTKEY51:
  134. t = std::string("FHTKEY51");
  135. break;
  136. }
  137. return t;
  138. }
  139. template<>
  140. FREQUENCYUNITS string2Enum<FREQUENCYUNITS>( const std::string& str ) {
  141. if (str == "HZ") return HZ;
  142. else if (str == "KHZ") return KHZ;
  143. else if (str == "MHZ") return MHZ;
  144. else if (str == "GHZ") return GHZ;
  145. else {
  146. throw std::runtime_error("string not recognized as FREUENCYUNIT");
  147. }
  148. }
  149. template<>
  150. HANKELTRANSFORMTYPE string2Enum<HANKELTRANSFORMTYPE>( const std::string& str ) {
  151. if (str == "ANDERSON801") return ANDERSON801;
  152. else if (str == "CHAVE") return CHAVE;
  153. else if (str == "QWEKEY") return QWEKEY;
  154. else if (str == "FHTKEY201") return FHTKEY201;
  155. else if (str == "FHTKEY51") return FHTKEY51;
  156. else if (str == "FHTKEY101") return FHTKEY101;
  157. else {
  158. throw std::runtime_error("string not recognized as HANKELTRANSFORMTYPE");
  159. }
  160. }
  161. template<>
  162. TIMEUNITS string2Enum<TIMEUNITS>( const std::string& str ) {
  163. if (str == "SEC") return SEC;
  164. else if (str == "MILLISEC") return MILLISEC;
  165. else if (str == "MICROSEC") return MICROSEC;
  166. else if (str == "NANOSEC") return NANOSEC;
  167. else if (str == "PICOSEC") return PICOSEC;
  168. else {
  169. throw std::runtime_error("string not recognized as TIMEUNIT");
  170. }
  171. }
  172. template<>
  173. FIELDCOMPONENT string2Enum<FIELDCOMPONENT>( const std::string& str) {
  174. if (str == "XCOMPONENT") return XCOMPONENT;
  175. else if (str == "YCOMPONENT") return YCOMPONENT;
  176. else if (str == "ZCOMPONENT") return ZCOMPONENT;
  177. else {
  178. throw std::runtime_error("string not recognized as FieldComponent");
  179. }
  180. }
  181. } // ----- end of Lemma name -----