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.

RectilinearGridReader.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* This file is part of Lemma, a geophysical modelling and inversion API */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. */
  6. /**
  7. @file
  8. @date 09/23/2013 11:05:48 AM
  9. @version $Id$
  10. @author Trevor Irons (ti)
  11. @email Trevor.Irons@xri-geo.com
  12. @copyright Copyright (c) 2013, XRI Geophysics, LLC
  13. @copyright Copyright (c) 2013, Trevor Irons
  14. **/
  15. #include "RectilinearGridReader.h"
  16. namespace Lemma {
  17. // ==================== FRIEND METHODS =====================
  18. std::ostream &operator<<(std::ostream &stream, const RectilinearGridReader &ob) {
  19. stream << *(GridReader*)(&ob);
  20. return stream;
  21. }
  22. // ==================== LIFECYCLE =======================
  23. //--------------------------------------------------------------------------------------
  24. // Class: RectilinearGridReader
  25. // Method: RectilinearGridReader
  26. // Description: constructor (protected)
  27. //--------------------------------------------------------------------------------------
  28. RectilinearGridReader::RectilinearGridReader (const std::string& name) : GridReader(name),
  29. Grid(NULL), Parser(NULL) {
  30. } // ----- end of method RectilinearGridReader::RectilinearGridReader (constructor) -----
  31. //--------------------------------------------------------------------------------------
  32. // Class: RectilinearGridReader
  33. // Method: New()
  34. // Description: constructor
  35. //--------------------------------------------------------------------------------------
  36. RectilinearGridReader* RectilinearGridReader::New() {
  37. RectilinearGridReader* Obj = new RectilinearGridReader("RectilinearGridReader");
  38. Obj->AttachTo(Obj);
  39. return Obj;
  40. }
  41. //--------------------------------------------------------------------------------------
  42. // Class: RectilinearGridReader
  43. // Method: ~RectilinearGridReader
  44. // Description: destructor (protected)
  45. //--------------------------------------------------------------------------------------
  46. RectilinearGridReader::~RectilinearGridReader () {
  47. if (Grid) Grid->Delete();
  48. if (Parser) Parser->Delete();
  49. } // ----- end of method RectilinearGridReader::~RectilinearGridReader (destructor) -----
  50. //--------------------------------------------------------------------------------------
  51. // Class: RectilinearGridReader
  52. // Method: Delete
  53. // Description: destructor (protected)
  54. //--------------------------------------------------------------------------------------
  55. void RectilinearGridReader::Delete() {
  56. this->DetachFrom(this);
  57. }
  58. //--------------------------------------------------------------------------------------
  59. // Class: RectilinearGridReader
  60. // Method: Release
  61. // Description: destructor (protected)
  62. //--------------------------------------------------------------------------------------
  63. void RectilinearGridReader::Release() {
  64. delete this;
  65. }
  66. //--------------------------------------------------------------------------------------
  67. // Class: RectilinearGridReader
  68. // Method: ReadASCIIGridFile
  69. //--------------------------------------------------------------------------------------
  70. void RectilinearGridReader::ReadASCIIGridFile ( const std::string& name ) {
  71. if (Grid) Grid->Delete();
  72. Grid = RectilinearGrid::New();
  73. if (Parser) Parser->Delete();
  74. Parser = ASCIIParser::New();
  75. Parser->SetCommentString("//");
  76. Parser->Open(name);
  77. std::vector<int> vals = Parser->ReadInts(3);
  78. Grid->SetDimensions(vals[0], vals[1], vals[2]);
  79. std::vector<Real> rvals = Parser->ReadReals(3);
  80. Grid->SetOffset(rvals[0], rvals[1], rvals[2]);
  81. rvals.clear();
  82. rvals = Parser->ReadReals( vals[0] );
  83. VectorXr temp = VectorXr::Map(&rvals[0], vals[0]);
  84. VectorXr hx = temp;
  85. rvals.clear();
  86. rvals = Parser->ReadReals( vals[1] );
  87. VectorXr hy = VectorXr::Map(&rvals[0], vals[1]);
  88. rvals.clear();
  89. rvals = Parser->ReadReals( vals[2] );
  90. VectorXr hz = VectorXr::Map(&rvals[0], vals[2]);
  91. Grid->SetSpacing(hx, hy, hz);
  92. // Read in model(s)/data? Where should this be done?
  93. Parser->Close();
  94. return;
  95. } // ----- end of method RectilinearGridReader::ReadSCIIGridFile -----
  96. //--------------------------------------------------------------------------------------
  97. // Class: RectilinearGridReader
  98. // Method: GetGrid
  99. //--------------------------------------------------------------------------------------
  100. RectilinearGrid* RectilinearGridReader::GetGrid ( ) {
  101. return Grid;
  102. } // ----- end of method RectilinearGridReader::GetGrid -----
  103. } // ----- end of Lemma name -----