Main Lemma Repository
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 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. case FHTKONG61:
  137. t = std::string("FHTKONG61");
  138. break;
  139. case FHTKONG121:
  140. t = std::string("FHTKONG121");
  141. break;
  142. case FHTKONG241:
  143. t = std::string("FHTKONG241");
  144. break;
  145. case IRONS:
  146. t = std::string("IRONS");
  147. break;
  148. }
  149. return t;
  150. }
  151. std::string enum2String( const WINDOWTYPE& Type ) {
  152. std::string t;
  153. switch (Type) {
  154. case HAMMING:
  155. return std::string("HAMMING");
  156. case HANNING:
  157. return std::string("HANNING");
  158. case RECTANGULAR:
  159. return std::string("RECTANGULAR");
  160. default:
  161. throw( std::runtime_error( "In enum2String WINDOWTYPE, type not identified" ) );
  162. }
  163. }
  164. std::string enum2String( const DIPOLESOURCETYPE& Type ) {
  165. switch (Type) {
  166. case NOSOURCETYPE:
  167. return std::string("NOSOURCETYPE");
  168. case GROUNDEDELECTRICDIPOLE:
  169. return std::string("GROUNDEDELECTRICDIPOLE");
  170. case UNGROUNDEDELECTRICDIPOLE:
  171. return std::string("UNGROUNDEDELECTRICDIPOLE");
  172. case MAGNETICDIPOLE:
  173. return std::string("MAGNETICDIPOLE");
  174. default:
  175. throw( std::runtime_error( "In enum2String DIPOLESOURCETYPE, type not identified" ) );
  176. }
  177. }
  178. template<>
  179. FREQUENCYUNITS string2Enum<FREQUENCYUNITS>( const std::string& str ) {
  180. if (str == "HZ") return HZ;
  181. else if (str == "KHZ") return KHZ;
  182. else if (str == "MHZ") return MHZ;
  183. else if (str == "GHZ") return GHZ;
  184. else {
  185. throw std::runtime_error("string not recognized as FREUENCYUNIT");
  186. }
  187. }
  188. template<>
  189. HANKELTRANSFORMTYPE string2Enum<HANKELTRANSFORMTYPE>( const std::string& str ) {
  190. if (str == "ANDERSON801") return ANDERSON801;
  191. else if (str == "CHAVE") return CHAVE;
  192. else if (str == "QWEKEY") return QWEKEY;
  193. else if (str == "FHTKEY201") return FHTKEY201;
  194. else if (str == "FHTKEY51") return FHTKEY51;
  195. else if (str == "FHTKEY101") return FHTKEY101;
  196. else if (str == "FHTKONG61") return FHTKONG61;
  197. else if (str == "FHTKONG121") return FHTKONG121;
  198. else if (str == "FHTKONG241") return FHTKONG241;
  199. else if (str == "IRONS") return IRONS;
  200. else {
  201. throw std::runtime_error("string not recognized as HANKELTRANSFORMTYPE");
  202. }
  203. }
  204. template<>
  205. TIMEUNITS string2Enum<TIMEUNITS>( const std::string& str ) {
  206. if (str == "SEC") return SEC;
  207. else if (str == "MILLISEC") return MILLISEC;
  208. else if (str == "MICROSEC") return MICROSEC;
  209. else if (str == "NANOSEC") return NANOSEC;
  210. else if (str == "PICOSEC") return PICOSEC;
  211. else {
  212. throw std::runtime_error("string not recognized as TIMEUNIT");
  213. }
  214. }
  215. template<>
  216. FIELDCOMPONENT string2Enum<FIELDCOMPONENT>( const std::string& str) {
  217. if (str == "XCOMPONENT") return XCOMPONENT;
  218. else if (str == "YCOMPONENT") return YCOMPONENT;
  219. else if (str == "ZCOMPONENT") return ZCOMPONENT;
  220. else {
  221. throw std::runtime_error("string not recognized as FieldComponent");
  222. }
  223. }
  224. template<>
  225. WINDOWTYPE string2Enum<WINDOWTYPE>( const std::string& str ) {
  226. if (str == "HAMMING") return HAMMING;
  227. if (str == "HANNING") return HANNING;
  228. if (str == "RECTANGULAR") return RECTANGULAR;
  229. else {
  230. throw std::runtime_error("string not recognized as WindowType");
  231. }
  232. }
  233. template<>
  234. DIPOLESOURCETYPE string2Enum<DIPOLESOURCETYPE>( const std::string& str ) {
  235. if (str == "NOSOURCETYPE") return NOSOURCETYPE;
  236. if (str == "GROUNDEDELECTRICDIPOLE") return GROUNDEDELECTRICDIPOLE;
  237. if (str == "UNGROUNDEDELECTRICDIPOLE") return UNGROUNDEDELECTRICDIPOLE;
  238. if (str == "MAGNETICDIPOLE") return MAGNETICDIPOLE;
  239. else {
  240. throw std::runtime_error("string not recognized as DipoleSource");
  241. }
  242. }
  243. } // ----- end of Lemma name -----