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.

AEMSurveyReader.cpp 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 09/24/2013 04:36:14 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2013, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2013, Trevor Irons
  16. */
  17. #include "AEMSurveyReader.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. std::ostream &operator<<(std::ostream &stream, const AEMSurveyReader &ob) {
  21. stream << *(LemmaObject*)(&ob);
  22. return stream;
  23. }
  24. // ==================== LIFECYCLE =======================
  25. //--------------------------------------------------------------------------------------
  26. // Class: AEMSurveyReader
  27. // Method: AEMSurveyReader
  28. // Description: constructor (protected)
  29. //--------------------------------------------------------------------------------------
  30. AEMSurveyReader::AEMSurveyReader (const std::string& name) :
  31. LemmaObject(name), Survey(NULL) {
  32. } // ----- end of method AEMSurveyReader::AEMSurveyReader (constructor) -----
  33. //--------------------------------------------------------------------------------------
  34. // Class: AEMSurveyReader
  35. // Method: New()
  36. // Description: public constructor
  37. //--------------------------------------------------------------------------------------
  38. AEMSurveyReader* AEMSurveyReader::New() {
  39. AEMSurveyReader* Obj = new AEMSurveyReader("AEMSurveyReader");
  40. Obj->AttachTo(Obj);
  41. return Obj;
  42. }
  43. //--------------------------------------------------------------------------------------
  44. // Class: AEMSurveyReader
  45. // Method: ~AEMSurveyReader
  46. // Description: destructor (protected)
  47. //--------------------------------------------------------------------------------------
  48. AEMSurveyReader::~AEMSurveyReader () {
  49. if (Survey) Survey->Delete();
  50. } // ----- end of method AEMSurveyReader::~AEMSurveyReader (destructor) -----
  51. //--------------------------------------------------------------------------------------
  52. // Class: AEMSurveyReader
  53. // Method: Delete
  54. // Description: public destructor
  55. //--------------------------------------------------------------------------------------
  56. void AEMSurveyReader::Delete() {
  57. this->DetachFrom(this);
  58. }
  59. //--------------------------------------------------------------------------------------
  60. // Class: AEMSurveyReader
  61. // Method: Release
  62. // Description: destructor (protected)
  63. //--------------------------------------------------------------------------------------
  64. void AEMSurveyReader::Release() {
  65. delete this;
  66. }
  67. //--------------------------------------------------------------------------------------
  68. // Class: AEMSurveyReader
  69. // Method: GetSurvey
  70. //--------------------------------------------------------------------------------------
  71. AEMSurvey* AEMSurveyReader::GetSurvey ( ) {
  72. return Survey;
  73. } // ----- end of method AEMSurveyReader::GetSurvey -----
  74. //--------------------------------------------------------------------------------------
  75. // Class: AEMSurveyReader
  76. // Method: ReadASCIIAEMFile
  77. //--------------------------------------------------------------------------------------
  78. void AEMSurveyReader::ReadASCIIAEMFile ( const std::string& fname ) {
  79. if (Survey) Survey->Delete();
  80. Survey = AEMSurvey::New();
  81. ASCIIParser* Parser = ASCIIParser::New();
  82. Parser->SetCommentString("//");
  83. Parser->Open(fname);
  84. // Sanity check
  85. std::vector<int> ivals = Parser->ReadInts(1);
  86. std::vector<Real> freqs;
  87. for (int isc=0; isc<ivals[0]; ++isc) {
  88. Real df = Parser->ReadReals(1)[0]; // frequency Hz
  89. bool unique = true;
  90. for (unsigned int ifreq=0; ifreq<freqs.size(); ++ifreq) {
  91. if (df - freqs[ifreq] < 1e-2) {
  92. unique = false;
  93. }
  94. }
  95. if (unique) freqs.push_back(df);
  96. std::string DT = Parser->ReadStrings(1)[0];
  97. if (DT == "MD" || DT == "ED") {
  98. } else {
  99. std::cerr << "In AEMSurveyReader::ReadASCIIAEMFile. The source type: "
  100. << DT << " is not supported.\n";
  101. std::exit(EXIT_FAILURE);
  102. }
  103. Parser->ReadReals(4); // position and moment
  104. }
  105. Survey->Freqs = VectorXr::Map(&freqs[0], freqs.size());
  106. // OK, now get cracking, those sources at every location
  107. int nb = Parser->ReadInts(1)[0]; // number of locations
  108. for (int ib=0; ib<nb; ++ib) {
  109. std::vector<Real> rvals = Parser->ReadReals(6); // position and moment
  110. int bp = Parser->GetFileLocation( );
  111. Parser->JumpToLocation( 0 );
  112. //std::vector<int> ivals = Parser->ReadInts(1); // number of frequencies
  113. int nf = Parser->ReadInts(1)[0]; // number of frequencies
  114. for (int isc=0; isc<nf; ++isc) {
  115. Survey->Sources.push_back(DipoleSource::New());
  116. int cnt = Survey->Sources.size() - 1; //
  117. // and now set it
  118. Survey->Sources[cnt]->SetNumberOfFrequencies(1);
  119. Survey->Sources[cnt]->SetFrequency(0, Parser->ReadReals(1)[0]);
  120. std::string DT = Parser->ReadStrings(1)[0];
  121. if (DT == "MD") {
  122. Survey->Sources[cnt]->SetType(MAGNETICDIPOLE);
  123. } else if (DT == "ED") {
  124. Survey->Sources[cnt]->SetType(UNGROUNDEDELECTRICDIPOLE);
  125. } else {
  126. std::cerr << "In AEMSurveyReader::ReadASCIIAEMFile. The source type: "
  127. << DT << " is not supported.\n";
  128. std::exit(EXIT_FAILURE);
  129. }
  130. std::vector<Real> irvals = Parser->ReadReals(4); // position and moment
  131. Survey->Sources[cnt]->SetMoment(irvals[3]);
  132. Survey->Sources[cnt]->SetLocation(rvals[0] + irvals[0], rvals[1] + irvals[1],
  133. rvals[2] + irvals[2]);
  134. Survey->Sources[cnt]->SetPolarisation(rvals[3], rvals[4], rvals[5]);
  135. }
  136. Parser->JumpToLocation(bp);
  137. }
  138. Parser->Delete();
  139. return ;
  140. } // ----- end of method AEMSurveyReader::ReadASCIIAEMFile -----
  141. } // ----- end of Lemma name -----