PsDoublModel.cpp
Go to the documentation of this file.00001 #include "PsDoublModel.h"
00002 #include <fstream>
00003 #include <stdio.h>
00004 #include <iostream>
00005 #include <cstdlib>
00006 #include "CFatalException.h"
00007
00008 using namespace std;
00009 PsDoublModel::PsDoublModel()
00010 {}
00011 PsDoublModel::~PsDoublModel()
00012 {}
00013
00014
00015 int PsDoublModel::SetupInsertPoints(const int nexpected)
00016 {
00017 InsertPoints.clear();
00018 const int size = GetPVelocity().size();
00019 for (int i = 0; i < size; ++i)
00020 {
00021 if (GetThickness().at(i) < 0)
00022 InsertPoints.push_back(&(SetThickness().at(i)));
00023 if (GetPVelocity().at(i) < 0)
00024 InsertPoints.push_back(&(SetPVelocity().at(i)));
00025 if (GetSVelocity().at(i) < 0)
00026 InsertPoints.push_back(&(SetSVelocity().at(i)));
00027 if (GetDensity().at(i) < 0)
00028 InsertPoints.push_back(&(SetDensity().at(i)));
00029 if (GetQp().at(i) < 0)
00030 InsertPoints.push_back(&(SetQp().at(i)));
00031 if (GetQs().at(i) < 0)
00032 InsertPoints.push_back(&(SetQs().at(i)));
00033 }
00034 return 0;
00035 }
00036
00037 void PsDoublModel::GetData(const std::string filename)
00038 {
00039 double thick,pvel,svel,dens,qp,qs;
00040 int flag;
00041
00042 if (!GetPVelocity().empty())
00043 {
00044 SetPVelocity().clear();
00045 SetThickness().clear();
00046 SetSVelocity().clear();
00047 SetDensity().clear();
00048 Flags.clear();
00049 SetQp().clear();
00050 SetQs().clear();
00051 }
00052 ifstream infile(filename.c_str());
00053 if (!infile)
00054 {
00055 throw CFatalException("Error opening file: "+filename);
00056 }
00057 while (infile.good())
00058 {
00059 infile >> thick >> pvel >> svel >> dens >> qp >> qs >>flag;
00060 if (infile.good())
00061 {
00062 SetThickness().push_back(thick);
00063 SetPVelocity().push_back(pvel);
00064 SetSVelocity().push_back(svel);
00065 SetDensity().push_back(dens);
00066 SetQp().push_back(qp);
00067 SetQs().push_back(qs);
00068 Flags.push_back(flag);
00069 }
00070 }
00071 }
00072 void PsDoublModel::WriteData(const std::string filename)
00073 {
00074 const unsigned int size = GetPVelocity().size();
00075
00076 FILE *outfile;
00077
00078 outfile = fopen((filename+".mod").c_str(),"w");
00079
00080 for (int i =0; i < size; ++i)
00081 fprintf(outfile,"%10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %5d \n",
00082 GetThickness().at(i),GetPVelocity().at(i),GetSVelocity().at(i),GetDensity().at(i),GetQp().at(i),GetQs().at(i),Flags.at(i));
00083 fclose(outfile);
00084 }
00085 void PsDoublModel::WriteRunFile(const std::string &filename)
00086 {
00087 ofstream runfile;
00088
00089 runfile.open(filename.c_str());
00090 runfile << "#!/bin/bash" << endl;
00091 runfile << "cp psfui_file "<< filename+"_dir" <<endl;
00092 runfile << "cd " << filename+"_dir" << endl;
00093 runfile << "../psfui -f ./psfui_file > ./psdoubl.dat" << endl;
00094 runfile << "../inf2zero ./psdoubl.dat" << endl;
00095 runfile << "../psdoubl13" << endl;
00096 runfile << "cd .." << endl;
00097 runfile.close();
00098 system(("chmod u+x "+filename).c_str());
00099 }