Main Lemma Repository
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

datareadertem.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. @file
  7. @author M. Andy Kass
  8. @date 12/28/2011
  9. @version $Id: datareadertem.cpp 87 2013-09-05 22:44:05Z tirons $
  10. **/
  11. #include "datareadertem.h"
  12. namespace Lemma {
  13. std::ostream &operator<<(std::ostream &stream,
  14. const DataReaderTem &ob) {
  15. stream << *(DataReaderTem*)(&ob);
  16. return stream;
  17. }
  18. DataReaderTem::DataReaderTem(const std::string &name) :
  19. DataReader(name), InputData(NULL) {
  20. }
  21. DataReaderTem::~DataReaderTem() {
  22. if (NumberOfReferences != 0) {
  23. throw DeleteObjectWithReferences(this);
  24. }
  25. }
  26. DataReaderTem* DataReaderTem::New() {
  27. DataReaderTem* Obj = new DataReaderTem("DataReaderTem");
  28. Obj->AttachTo(Obj);
  29. return Obj;
  30. }
  31. void DataReaderTem::Delete() {
  32. this->DetachFrom(this);
  33. }
  34. void DataReaderTem::Release() {
  35. delete this;
  36. }
  37. DataTEM* DataReaderTem::GetData() {
  38. return this->InputData;
  39. }
  40. void DataReaderTem::SetDataTEM(DataTEM* inputtemp) {
  41. if (this->InputData != NULL) {
  42. this->InputData->DetachFrom(this);
  43. }
  44. inputtemp->AttachTo(this);
  45. this->InputData=inputtemp;
  46. }
  47. void DataReaderTem::ReadData(const std::string &datafile) {
  48. std::string temp;
  49. std::string temp2;
  50. int obs;
  51. int gates;
  52. MatrixXr datamatrix;
  53. Vector3Xr positions;
  54. std::fstream infile(datafile.c_str(),std::ios::in);
  55. if (infile.fail()) {
  56. std::cout << "Data file I/O error." << std::endl;
  57. /// \TODO thow some kind of stoppage error
  58. }
  59. // file format will be:
  60. // nObs nGates
  61. // x1 y1 d1 d2 d3 etc
  62. infile >> obs;
  63. infile >> gates;
  64. this->InputData->SetSize(obs,gates);
  65. //set dimensions and finish reading in data
  66. datamatrix.resize(obs,gates);
  67. positions.resize(Eigen::NoChange,obs);
  68. for (int ii=0;ii<obs;ii++) {
  69. infile >> positions(0,ii);
  70. infile >> positions(1,ii);
  71. infile >> positions(2,ii);
  72. for (int jj=0;jj<gates;jj++) {
  73. infile >> datamatrix(ii,jj);
  74. }
  75. }
  76. this->InputData->SetData(datamatrix);
  77. this->InputData->SetPositions(positions);
  78. infile.close();
  79. }
  80. } // end namespace Lemma