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

Generated on Fri Jul 4 15:30:20 2008 for GPLIB++ by  doxygen 1.5.5