GPLIB++
Sdisp96Model.cpp
Go to the documentation of this file.
1 #include "Sdisp96Model.h"
2 #include <iostream>
3 #include <fstream>
4 #include <cassert>
5 #include <iterator>
6 #include <iomanip>
7 #include <boost/filesystem.hpp>
8 #include "FatalException.h"
9 using namespace std;
10 
11 namespace gplib
12  {
13  Sdisp96Model::Sdisp96Model() :
14  isSpherical(true)
15  {
16  }
17 
19  {
20  }
21 
23  {
24  if (this == &source)
25  return *this;
27  isSpherical = source.isSpherical;
28  return *this;
29  }
30 
32  SurfaceWaveModel(Old), isSpherical(Old.isSpherical)
33  {
34 
35  }
36 
37  void Sdisp96Model::ReadModel(const std::string &filename)
38  {
39 
40  }
41 
42  void Sdisp96Model::WriteModel(const std::string &filename) const
43  {
45  ofstream outfile(filename.c_str());
46  outfile << "MODEL" << endl;
47  outfile << GetName() << endl;
48  outfile << "ISOTROPIC" << endl;
49  outfile << "KGS" << endl;
50  if (isSpherical)
51  {
52  outfile << "SPHERICAL EARTH" << endl;
53  }
54  else
55  {
56  outfile << "FLAT EARTH" << endl;
57  }
58  outfile << "1-D" << endl;
59  outfile << "CONSTANT VELOCITY" << endl;
60  outfile << "LINE08" << endl;
61  outfile << "LINE09" << endl;
62  outfile << "LINE10" << endl;
63  outfile << "LINE11" << endl;
64  outfile
65  << "HR VP VS RHO QP QS ETAP ETAS FREFP FREFS"
66  << endl;
67  const int nlayers = GetPvVelocities().size();
68  for (int i = 0; i < nlayers; ++i)
69  {
70  outfile << setw(7) << setprecision(2) << GetThicknesses().at(i);
71  outfile << setw(7) << setprecision(3) << GetPvVelocities().at(i);
72  outfile << setw(7) << setprecision(3) << GetSvVelocities().at(i);
73  outfile << setw(7) << setprecision(3) << GetDensities().at(i);
74  outfile << setw(7) << setprecision(3) << GetQkappa().at(i);
75  outfile << setw(7) << setprecision(3) << GetQmu().at(i);
76  outfile << setw(7) << setprecision(3) << GetEta().at(i);
77  outfile << setw(7) << setprecision(3) << GetEta().at(i);
78  outfile << " 1.0 1.0" << endl;
79  }
80  if (!outfile.good())
81  throw FatalException("Problem writing to file: " + filename);
82  }
83 
84  void Sdisp96Model::WriteRunFile(const std::string &filename,
85  const std::vector<double> periods) const
86  {
88  assert(periods.size() > 0);
89  ofstream runfile(filename.c_str());
90  ofstream periodfile((filename + ".per").c_str());
91  copy(periods.begin(), periods.end(), ostream_iterator<double> (
92  periodfile, "\n"));
93  boost::filesystem::path Path(filename);
94  string dirname(filename + "_dir");
95  runfile << "#!/bin/bash" << endl;
96  runfile << "mkdir " << dirname << endl;
97  runfile << "mv " << filename << ".* " << dirname << endl;
98  runfile << "cd " << dirname << endl;
99  runfile << "sprep96 -M " << Path.leaf() << ".mod" << " -R -PARR "
100  << Path.leaf() << ".per -NMOD 1 2>&1> /dev/null" << endl;
101  runfile << "sdisp96 2>&1> /dev/null" << endl;
102  runfile << "sdpsrf96 -R -ASC 2>&1> /dev/null" << endl;
103  runfile << "cp SDISPR.ASC ../" << filename + ".asc96" << endl;
104 
105  if (!runfile.good())
106  throw FatalException("Problem writing to file: " + filename);
107  }
108  }
const trealdata & GetPvVelocities() const
const trealdata & GetSvVelocities() const
A class to store 1D model for calculation of synthetic surface wave data.
This class can write files specific for the synthetic surface wave codes that are part of the compute...
Definition: Sdisp96Model.h:12
const trealdata & GetQmu() const
std::string GetName() const
SurfaceWaveModel & operator=(const SurfaceWaveModel &source)
virtual void WriteModel(const std::string &filename) const
Write them model to a file so that the forward codes can use it.
virtual void WriteRunFile(const std::string &filename, const std::vector< double > periods) const
Write out a script file that when run creates synthetic data with the name filename+'.asc'.
Sdisp96Model & operator=(const Sdisp96Model &source)
const trealdata & GetDensities() const
const trealdata & GetEta() const
virtual void ReadModel(const std::string &filename)
Read the model from a file.
const trealdata & GetThicknesses() const
const trealdata & GetQkappa() const
The basic exception class for all errors that arise in gplib.