FkModel.cpp

Go to the documentation of this file.
00001 #include "FkModel.h"
00002 
00003 #include <fstream>
00004 #include <iomanip>
00005 using namespace std;
00006 namespace gplib
00007   {
00008     FkModel::FkModel():
00009       SeismicModel()
00010       {
00011       }
00012     FkModel::~FkModel()
00013       {
00014       }
00015 
00016     void FkModel::WriteModel(const std::string filename)
00017       {
00018         ofstream neu(filename.c_str()); //the file to write the model to
00019         int sourceindex = 0; // the index of the source layer
00020         double sourcethickness = 0; //thickness of the layer above the source (FK needs dummy layer)
00021         double totalthickness = 0; // counter to add up thicknesses to calculate sourcethickness
00022         unsigned int totallayers = GetThickness().size();
00023 
00024         sourceindex = FindLayer(GetSourceDepth()); //find out in which layer the source lies
00025         for (int i = 0; i < sourceindex; ++i)
00026           totalthickness += GetThickness().at(i); // add up the thickness of all layers above the source (without sourcelayer)
00027         sourcethickness = GetSourceDepth() - totalthickness; //calculate the thickness of the sourcelayer so that source lies
00028         // at lower boundary
00029         neu
00030             << ".F.                                                                             \n"; //write File header
00031         neu
00032             << "    0   64                                                                      \n"; //FK-Code is VERY
00033         neu << "GREEN.1\n"; //picky about spaces etc. !!
00034         neu << "    6.0      " << setprecision(1) << setiosflags(
00035             ios::scientific) << GetSourceDepth() << resetiosflags(
00036             ios::scientific) << "    1" << setw(5) << setfill(' ')
00037             << setprecision(8) << GetNpts() / 2 << setw(5) << setfill(' ')
00038             << GetNpts() << "    " << setprecision(3)
00039             << setiosflags(ios::fixed) << GetDt() << resetiosflags(ios::fixed)
00040             << setfill(' ') << setw(6) << totallayers << "    1\n"; //see documentation
00041         // of FK for meaning
00042         neu
00043             << "    1    1    1    1    1    1    1    1    1    1    0                         \n";
00044 
00045         for (unsigned int i = 0; i < totallayers; ++i) //write all layers
00046           {
00047             neu << setprecision(4) << setiosflags(ios::scientific) << " "
00048                 << GetThickness().at(i) << " " << GetPVelocity().at(i) << " ";
00049             neu << GetSVelocity().at(i) << " " << GetDensity().at(i) << " "
00050                 << GetQp().at(i) << " " << GetQs().at(i) << endl;
00051           }
00052 
00053         neu << "   " << sourceindex + 1
00054             << "                                                                           \n";
00055         neu << "  0.4000000E+03  1.500000E+00         0\n"; //write epilogue for FK-Code
00056         neu << setw(5) << setfill(' ') << GetRecDist().size()
00057             << "  10000.0     30.0      0.4       0.3\n";
00058         for (unsigned int i = 0; i < GetRecDist().size(); ++i)
00059           neu << "   " << setw(3) << setprecision(3) << setiosflags(ios::fixed
00060               | ios::showpoint) << GetRecDist().at(i)
00061               << "       0.0    9999.0 \n";
00062         neu << "    " << flush;
00063         neu << "\n";
00064       }
00065 
00066     void FkModel::ReadModel(const std::string filename)
00067       {
00068         ifstream infile(filename.c_str());
00069         char dummy[255];
00070         double number;
00071         int nlayers, nstat;
00072         double SourceDepth, dt;
00073         int npts;
00074         infile.getline(dummy, 255);
00075         infile.getline(dummy, 255);
00076         infile.getline(dummy, 255);
00077         infile >> number >> SourceDepth >> number >> number >> npts >> dt
00078             >> nlayers >> number;
00079         infile.getline(dummy, 255);
00080         infile.getline(dummy, 255);
00081         SetSourceDepth(SourceDepth);
00082         SetNpts(npts);
00083         SetDt(dt);
00084         Init(nlayers);
00085         for (int i = 0; i < nlayers; ++i)
00086           infile >> SetThickness().at(i) >> SetPVelocity().at(i)
00087               >> SetSVelocity().at(i) >> SetDensity().at(i) >> SetQp().at(i)
00088               >> SetQs().at(i);
00089         infile >> number;
00090         infile.getline(dummy, 255);
00091         infile.getline(dummy, 255);
00092         infile >> nstat >> number >> number >> number >> number;
00093         SetRecDist().assign(nstat, 0);
00094         for (int i = 0; i < nstat; ++i)
00095           infile >> SetRecDist().at(i) >> number >> number;
00096       }
00097   }

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