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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
  20. return stream;
  21. }
  22. // ==================== LIFECYCLE =======================
  23. //--------------------------------------------------------------------------------------
  24. // Class: RectilinearGridReader
  25. // Method: RectilinearGridReader
  26. // Description: constructor (protected)
  27. //--------------------------------------------------------------------------------------
  28. RectilinearGridReader::RectilinearGridReader ( ) : GridReader( ),
  29. rGrid( nullptr ), Parser( nullptr ) {
  30. } // ----- end of method RectilinearGridReader::RectilinearGridReader (constructor) -----
  31. //--------------------------------------------------------------------------------------
  32. // Class: RectilinearGridReader
  33. // Method: NewSP()
  34. // Description: constructor
  35. //--------------------------------------------------------------------------------------
  36. std::shared_ptr< RectilinearGridReader > RectilinearGridReader::NewSP() {
  37. std::shared_ptr<RectilinearGridReader> sp(new RectilinearGridReader( ), LemmaObjectDeleter() );
  38. return sp;
  39. }
  40. //--------------------------------------------------------------------------------------
  41. // Class: RectilinearGridReader
  42. // Method: ~RectilinearGridReader
  43. // Description: destructor (protected)
  44. //--------------------------------------------------------------------------------------
  45. RectilinearGridReader::~RectilinearGridReader () {
  46. } // ----- end of method RectilinearGridReader::~RectilinearGridReader (destructor) -----
  47. //--------------------------------------------------------------------------------------
  48. // Class: RectilinearGridReader
  49. // Method: ReadASCIIGridFile
  50. //--------------------------------------------------------------------------------------
  51. void RectilinearGridReader::ReadASCIIGridFile ( const std::string& name ) {
  52. rGrid = RectilinearGrid::NewSP();
  53. Parser = ASCIIParser::NewSP();
  54. Parser->SetCommentString("//");
  55. Parser->Open(name);
  56. std::vector<int> vals = Parser->ReadInts(3);
  57. rGrid->SetDimensions(vals[0], vals[1], vals[2]);
  58. std::vector<Real> rvals = Parser->ReadReals(3);
  59. rGrid->SetOffset(rvals[0], rvals[1], rvals[2]);
  60. rvals.clear();
  61. rvals = Parser->ReadReals( vals[0] );
  62. VectorXr temp = VectorXr::Map(&rvals[0], vals[0]);
  63. VectorXr hx = temp;
  64. rvals.clear();
  65. rvals = Parser->ReadReals( vals[1] );
  66. VectorXr hy = VectorXr::Map(&rvals[0], vals[1]);
  67. rvals.clear();
  68. rvals = Parser->ReadReals( vals[2] );
  69. VectorXr hz = VectorXr::Map(&rvals[0], vals[2]);
  70. rGrid->SetSpacing(hx, hy, hz);
  71. // Read in model(s)/data? Where should this be done?
  72. Parser->Close();
  73. return;
  74. } // ----- end of method RectilinearGridReader::ReadSCIIGridFile -----
  75. //--------------------------------------------------------------------------------------
  76. // Class: RectilinearGridReader
  77. // Method: GetGrid
  78. //--------------------------------------------------------------------------------------
  79. std::shared_ptr<Grid> RectilinearGridReader::GetGrid ( ) {
  80. return std::static_pointer_cast<Grid> (rGrid);
  81. } // ----- end of method RectilinearGridReader::GetGrid -----
  82. } // ----- end of Lemma name -----