Skip to content

Commit

Permalink
Replaced the piece of source code for finding path with existing func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
wenqing committed May 31, 2018
1 parent d62e320 commit 5495da5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 100 deletions.
22 changes: 1 addition & 21 deletions FEM/rf_ic_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,27 +861,7 @@ void CInitialCondition::SetDomain(int nidx)
return;
}
std::ifstream rfr_file;
std::string restart_file_name;
restart_file_name = rfr_file_name;
basic_string<char>::size_type indexChWin, indexChLinux;
indexChWin = indexChLinux = 0;
indexChWin = FileName.find_last_of('\\');
indexChLinux = FileName.find_last_of('/');
//
string funfname;
if (indexChWin == string::npos && indexChLinux == string::npos)
funfname = rfr_file_name;
else if (indexChWin != string::npos)
{
funfname = FileName.substr(0, indexChWin);
funfname = funfname + "\\" + rfr_file_name;
}
else if (indexChLinux != string::npos)
{
funfname = FileName.substr(0, indexChLinux);
funfname = funfname + "/" + rfr_file_name;
}
restart_file_name = funfname;
std::string restart_file_name = FilePath + rfr_file_name;
//-------------------------------------------------------------------
rfr_file.open(restart_file_name.c_str(), ios::in);
if (!rfr_file.good())
Expand Down
63 changes: 3 additions & 60 deletions FEM/rf_mmp_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file)
char seps[] = "+\n";
char seps1[] = "*";
double f_buff;
size_t indexChWin, indexChLinux; // JT, DEC 2009
std::string funfname; // JT, DEC 2009

while (!new_keyword)
Expand Down Expand Up @@ -377,7 +376,6 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file)
// ToDo to GeoLib
// 2ii..GEOMETRY_AREA
//------------------------------------------------------------------------
indexChWin = indexChLinux = 0; // JT, DEC 2009
// subkeyword found
if (line_string.find("$GEOMETRY_AREA") != std::string::npos)
{
Expand All @@ -386,23 +384,7 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file)
if (line_string.find("FILE") != string::npos)
{
in >> geo_area_file;
// JT, Dec. 16, 2009, added lines below to correct and globalize the read of geometry area file
std::string file_name = geo_area_file;
indexChWin = FileName.find_last_of('\\');
indexChLinux = FileName.find_last_of('/');
if (indexChWin == string::npos && indexChLinux == std::string::npos)
funfname = file_name;
else if (indexChWin != string::npos)
{
funfname = FileName.substr(0, indexChWin);
funfname = funfname + "\\" + file_name;
}
else if (indexChLinux != string::npos)
{
funfname = FileName.substr(0, indexChLinux);
funfname = funfname + "/" + file_name;
}
geo_area_file = funfname;
geo_area_file = FilePath + geo_area_file;
// End of new lines
}
else
Expand Down Expand Up @@ -1787,31 +1769,12 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file)
//------------------------------------------------------------------------
// 11..PERMEABILITY_DISTRIBUTION
//------------------------------------------------------------------------
size_t indexChWin, indexChLinux; // WW
indexChWin = indexChLinux = 0;
std::string funfname;
// subkeyword found
if (line_string.find("$PERMEABILITY_DISTRIBUTION") != std::string::npos)
{
in.str(GetLineFromFile1(mmp_file));
in >> permeability_file;
string file_name = permeability_file;
//-------WW
indexChWin = FileName.find_last_of('\\');
indexChLinux = FileName.find_last_of('/');
if (indexChWin == string::npos && indexChLinux == std::string::npos)
funfname = file_name;
else if (indexChWin != string::npos)
{
funfname = FileName.substr(0, indexChWin);
funfname = funfname + "\\" + file_name;
}
else if (indexChLinux != string::npos)
{
funfname = FileName.substr(0, indexChLinux);
funfname = funfname + "/" + file_name;
}
permeability_file = funfname;
permeability_file = FilePath + permeability_file;
//--------------------------------------
// WW
std::ifstream mmp_file(funfname.data(), std::ios::in);
Expand All @@ -1832,27 +1795,7 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file)
{
in.str(GetLineFromFile1(mmp_file));
in >> porosity_file;
string file_name = porosity_file;
// else{ //CB this is to get the correct path in case the exe is not run from within the project folder
// pos = (int)FileName.find_last_of('\\', -1) + 1;
// file_name = FileName.substr(0,pos) + porosity_file;
//}
//-------CB as above by WW
indexChWin = FileName.find_last_of('\\');
indexChLinux = FileName.find_last_of('/');
if (indexChWin == string::npos && indexChLinux == std::string::npos)
funfname = file_name;
else if (indexChWin != string::npos)
{
funfname = FileName.substr(0, indexChWin);
funfname = funfname + "\\" + file_name;
}
else if (indexChLinux != string::npos)
{
funfname = FileName.substr(0, indexChLinux);
funfname = funfname + "/" + file_name;
}
porosity_file = funfname;
porosity_file = FilePath + porosity_file;
// WW
ifstream mmp_file(funfname.data(), ios::in);
if (!mmp_file.good())
Expand Down
12 changes: 3 additions & 9 deletions MSH/msh_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "memory.h"
#include "Histogram.h"

#include "FileTools.h"

// GEOLib
//#include "geo_pnt.h"
//#include "geo_ply.h"
Expand Down Expand Up @@ -4070,16 +4072,8 @@ void CFEMesh::mHM2NeumannBC()
infiltration_files = *_geo_name + ".ifl";
std::ofstream infil(infiltration_files.c_str(), std::ios::trunc);

std::basic_string<char>::size_type indexChWin, indexChLinux;
indexChWin = indexChLinux = 0;
indexChWin = _geo_name->find_last_of('\\');
indexChLinux = _geo_name->find_last_of('/');
//
std::string file_path;
if (indexChWin != std::string::npos)
file_path = _geo_name->substr(0, indexChWin) + "\\";
else if (indexChLinux != std::string::npos)
file_path = _geo_name->substr(0, indexChLinux) + "/";
std::string file_path = pathDirname(*_geo_name);;

while (!ins.eof())
{
Expand Down
13 changes: 3 additions & 10 deletions OGS/rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,9 @@ int main(int argc, char* argv[])
TStartTimer(0);
#endif

size_t indexChWin, indexChLinux;
indexChWin = indexChLinux = 0;
indexChWin = FileName.find_last_of('\\');
indexChLinux = FileName.find_last_of('/');
//
if (indexChWin != std::string::npos)
FilePath = FileName.substr(0, indexChWin) + "\\";
else if (indexChLinux != std::string::npos)
FilePath = FileName.substr(0, indexChLinux) + "/";
// If no option is given, output files are placed in the same directory as the input files
FilePath = pathDirname(FileName);

// If no option is given, output files are placed in the same directory as the input files
if (defaultOutputPath.empty())
defaultOutputPath = FilePath;

Expand Down

0 comments on commit 5495da5

Please sign in to comment.