Sdisp96Model.cpp

Go to the documentation of this file.
00001 #include "Sdisp96Model.h"
00002 #include <iostream>
00003 #include <fstream>
00004 #include <cassert>
00005 #include <iterator>
00006 #include <iomanip>
00007 #include <boost/filesystem.hpp>
00008 #include "FatalException.h"
00009 using namespace std;
00010 
00011 namespace gplib
00012   {
00013     Sdisp96Model::Sdisp96Model() :
00014       isSpherical(true)
00015       {
00016       }
00017 
00018     Sdisp96Model::~Sdisp96Model()
00019       {
00020       }
00021 
00022     Sdisp96Model& Sdisp96Model::operator=(const Sdisp96Model& source)
00023       {
00024         if (this == &source)
00025           return *this;
00026         SurfaceWaveModel::operator=(source);
00027         isSpherical = source.isSpherical;
00028         return *this;
00029       }
00030 
00031     Sdisp96Model::Sdisp96Model(const Sdisp96Model &Old) :
00032       SurfaceWaveModel(Old), isSpherical(Old.isSpherical)
00033       {
00034 
00035       }
00036 
00037     void Sdisp96Model::ReadModel(const std::string &filename)
00038       {
00039 
00040       }
00041 
00042     void Sdisp96Model::WriteModel(const std::string &filename) const
00043       {
00044         CheckConsistency();
00045         ofstream outfile(filename.c_str());
00046         outfile << "MODEL" << endl;
00047         outfile << GetName() << endl;
00048         outfile << "ISOTROPIC" << endl;
00049         outfile << "KGS" << endl;
00050         if (isSpherical)
00051           {
00052             outfile << "SPHERICAL EARTH" << endl;
00053           }
00054         else
00055           {
00056             outfile << "FLAT EARTH" << endl;
00057           }
00058         outfile << "1-D" << endl;
00059         outfile << "CONSTANT VELOCITY" << endl;
00060         outfile << "LINE08" << endl;
00061         outfile << "LINE09" << endl;
00062         outfile << "LINE10" << endl;
00063         outfile << "LINE11" << endl;
00064         outfile
00065             << "HR         VP         VS     RHO    QP    QS   ETAP    ETAS    FREFP    FREFS"
00066             << endl;
00067         const int nlayers = GetPvVelocities().size();
00068         for (int i = 0; i < nlayers; ++i)
00069           {
00070             outfile << setw(7) << setprecision(2) << GetThicknesses().at(i);
00071             outfile << setw(7) << setprecision(3) << GetPvVelocities().at(i);
00072             outfile << setw(7) << setprecision(3) << GetSvVelocities().at(i);
00073             outfile << setw(7) << setprecision(3) << GetDensities().at(i);
00074             outfile << setw(7) << setprecision(3) << GetQkappa().at(i);
00075             outfile << setw(7) << setprecision(3) << GetQmu().at(i);
00076             outfile << setw(7) << setprecision(3) << GetEta().at(i);
00077             outfile << setw(7) << setprecision(3) << GetEta().at(i);
00078             outfile << " 1.0  1.0" << endl;
00079           }
00080         if (!outfile.good())
00081           throw FatalException("Problem writing to file: " + filename);
00082       }
00083 
00084     void Sdisp96Model::WriteRunFile(const std::string &filename,
00085         const std::vector<double> periods) const
00086       {
00087         CheckConsistency();
00088         assert(periods.size() > 0);
00089         ofstream runfile(filename.c_str());
00090         ofstream periodfile((filename + ".per").c_str());
00091         copy(periods.begin(), periods.end(), ostream_iterator<double> (
00092             periodfile, "\n"));
00093         boost::filesystem::path Path(filename);
00094         string dirname(filename + "_dir");
00095         runfile << "#!/bin/bash" << endl;
00096         runfile << "mkdir " << dirname << endl;
00097         runfile << "mv " << filename << ".* " << dirname << endl;
00098         runfile << "cd " << dirname << endl;
00099         runfile << "sprep96  -M " << Path.leaf() << ".mod" << " -R -PARR "
00100             << Path.leaf() << ".per -NMOD 1 2>&1> /dev/null" << endl;
00101         runfile << "sdisp96 2>&1> /dev/null" << endl;
00102         runfile << "sdpsrf96 -R -ASC 2>&1> /dev/null" << endl;
00103         runfile << "cp SDISPR.ASC ../" << filename + ".asc96" << endl;
00104 
00105         if (!runfile.good())
00106           throw FatalException("Problem writing to file: " + filename);
00107       }
00108   }

Generated on Tue May 4 16:52:15 2010 for GPLIB++ by  doxygen 1.5.8