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 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. template<>
  165. FREQUENCYUNITS string2Enum<FREQUENCYUNITS>( const std::string& str ) {
  166. if (str == "HZ") return HZ;
  167. else if (str == "KHZ") return KHZ;
  168. else if (str == "MHZ") return MHZ;
  169. else if (str == "GHZ") return GHZ;
  170. else {
  171. throw std::runtime_error("string not recognized as FREUENCYUNIT");
  172. }
  173. }
  174. template<>
  175. HANKELTRANSFORMTYPE string2Enum<HANKELTRANSFORMTYPE>( const std::string& str ) {
  176. if (str == "ANDERSON801") return ANDERSON801;
  177. else if (str == "CHAVE") return CHAVE;
  178. else if (str == "QWEKEY") return QWEKEY;
  179. else if (str == "FHTKEY201") return FHTKEY201;
  180. else if (str == "FHTKEY51") return FHTKEY51;
  181. else if (str == "FHTKEY101") return FHTKEY101;
  182. else if (str == "FHTKONG61") return FHTKONG61;
  183. else if (str == "FHTKONG121") return FHTKONG121;
  184. else if (str == "FHTKONG241") return FHTKONG241;
  185. else if (str == "IRONS") return IRONS;
  186. else {
  187. throw std::runtime_error("string not recognized as HANKELTRANSFORMTYPE");
  188. }
  189. }
  190. template<>
  191. TIMEUNITS string2Enum<TIMEUNITS>( const std::string& str ) {
  192. if (str == "SEC") return SEC;
  193. else if (str == "MILLISEC") return MILLISEC;
  194. else if (str == "MICROSEC") return MICROSEC;
  195. else if (str == "NANOSEC") return NANOSEC;
  196. else if (str == "PICOSEC") return PICOSEC;
  197. else {
  198. throw std::runtime_error("string not recognized as TIMEUNIT");
  199. }
  200. }
  201. template<>
  202. FIELDCOMPONENT string2Enum<FIELDCOMPONENT>( const std::string& str) {
  203. if (str == "XCOMPONENT") return XCOMPONENT;
  204. else if (str == "YCOMPONENT") return YCOMPONENT;
  205. else if (str == "ZCOMPONENT") return ZCOMPONENT;
  206. else {
  207. throw std::runtime_error("string not recognized as FieldComponent");
  208. }
  209. }
  210. template<>
  211. WINDOWTYPE string2Enum<WINDOWTYPE>( const std::string& str ) {
  212. if (str == "HAMMING") return HAMMING;
  213. if (str == "HANNING") return HANNING;
  214. if (str == "RECTANGULAR") return RECTANGULAR;
  215. else {
  216. throw std::runtime_error("string not recognized as WindowType");
  217. }
  218. }
  219. } // ----- end of Lemma name -----