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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. std::string enum2String( const WINDOWTYPE& Type ) {
  140. std::string t;
  141. switch (Type) {
  142. case HAMMING:
  143. return std::string("HAMMING");
  144. case HANNING:
  145. return std::string("HANNING");
  146. case RECTANGULAR:
  147. return std::string("RECTANGULAR");
  148. default:
  149. throw( std::runtime_error( "In enum2String WINDOWTYPE, type not identified" ) );
  150. }
  151. }
  152. template<>
  153. FREQUENCYUNITS string2Enum<FREQUENCYUNITS>( const std::string& str ) {
  154. if (str == "HZ") return HZ;
  155. else if (str == "KHZ") return KHZ;
  156. else if (str == "MHZ") return MHZ;
  157. else if (str == "GHZ") return GHZ;
  158. else {
  159. throw std::runtime_error("string not recognized as FREUENCYUNIT");
  160. }
  161. }
  162. template<>
  163. HANKELTRANSFORMTYPE string2Enum<HANKELTRANSFORMTYPE>( const std::string& str ) {
  164. if (str == "ANDERSON801") return ANDERSON801;
  165. else if (str == "CHAVE") return CHAVE;
  166. else if (str == "QWEKEY") return QWEKEY;
  167. else if (str == "FHTKEY201") return FHTKEY201;
  168. else if (str == "FHTKEY51") return FHTKEY51;
  169. else if (str == "FHTKEY101") return FHTKEY101;
  170. else {
  171. throw std::runtime_error("string not recognized as HANKELTRANSFORMTYPE");
  172. }
  173. }
  174. template<>
  175. TIMEUNITS string2Enum<TIMEUNITS>( const std::string& str ) {
  176. if (str == "SEC") return SEC;
  177. else if (str == "MILLISEC") return MILLISEC;
  178. else if (str == "MICROSEC") return MICROSEC;
  179. else if (str == "NANOSEC") return NANOSEC;
  180. else if (str == "PICOSEC") return PICOSEC;
  181. else {
  182. throw std::runtime_error("string not recognized as TIMEUNIT");
  183. }
  184. }
  185. template<>
  186. FIELDCOMPONENT string2Enum<FIELDCOMPONENT>( const std::string& str) {
  187. if (str == "XCOMPONENT") return XCOMPONENT;
  188. else if (str == "YCOMPONENT") return YCOMPONENT;
  189. else if (str == "ZCOMPONENT") return ZCOMPONENT;
  190. else {
  191. throw std::runtime_error("string not recognized as FieldComponent");
  192. }
  193. }
  194. template<>
  195. WINDOWTYPE string2Enum<WINDOWTYPE>( const std::string& str ) {
  196. if (str == "HAMMING") return HAMMING;
  197. if (str == "HANNING") return HANNING;
  198. if (str == "RECTANGULAR") return RECTANGULAR;
  199. else {
  200. throw std::runtime_error("string not recognized as WindowType");
  201. }
  202. }
  203. } // ----- end of Lemma name -----