Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced the piece of source code for finding path with an existing function #95

Merged
merged 3 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Base/FileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool HasCRInLineEnding(std::string const& strFilename)
return foundCR;
}

inline char getDirSep()
char getDirSep()
{
#ifdef WIN32
return '\\';
Expand Down
2 changes: 2 additions & 0 deletions Base/FileTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ std::string pathJoin(const std::string& path1, const std::string& path2);
/// returns the current process working directory
std::string getCwd();

char getDirSep();

#endif // FILETOOLS_H
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use pathJoin() in FileTools.h?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a commit to replace FilePath + name with pathJoin but I removed it soon. With that replacement, "#include "FileTools"" were added in several files and many places were changed. Later on I thought that using FilePath + name is more straightforward than calling pathJoin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see

//-------------------------------------------------------------------
rfr_file.open(restart_file_name.c_str(), ios::in);
if (!rfr_file.good())
Expand Down
68 changes: 5 additions & 63 deletions FEM/rf_mmp_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +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 +375,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 +383,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,34 +1768,15 @@ 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);
std::ifstream mmp_file(permeability_file.data(), std::ios::in);
if (!mmp_file.good())
std::cout << "Fatal error in MMPRead: no PERMEABILITY_DISTRIBUTION file"
<< "\n";
Expand All @@ -1832,29 +1794,9 @@ 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);
ifstream mmp_file(porosity_file.data(), ios::in);
if (!mmp_file.good())
std::cout << "Fatal error in MMPRead: no POROSITY_DISTRIBUTION file"
<< "\n";
Expand Down
18 changes: 1 addition & 17 deletions GEO/geo_sfc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,23 +1086,7 @@ void Surface::ReadTIN(const std::string& tin_file_name)
CTriangle* m_triangle = NULL;
//----------------------------------------------------------------------
// File handling
string tin_file_name_path;
/* //11.08.2011 WW
// tin_file_name_path = FileName; //WW/JOD // LB: commented out to compile GEO without dependency on FEM
basic_string <char>::size_type indexCh1a;
indexCh1a = tin_file_name_path.find_last_of("\\");

if( indexCh1a < tin_file_name_path.size()) { // JOD 4.7.10, \ exists in path, DEBUG case
string stra = tin_file_name_path.substr (0, indexCh1a);
tin_file_name_path.clear();
tin_file_name_path = stra+"\\"+tin_file_name;

}
else // \ does not exist, RELEASE case
tin_file_name_path = tin_file_name;
*/

tin_file_name_path = FilePath + tin_file_name; // 11.08.2011. WW
const string tin_file_name_path = FilePath + tin_file_name; // 11.08.2011. WW
ifstream tin_file(tin_file_name_path.data(), ios::in);
if (!tin_file.good())
return;
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
15 changes: 5 additions & 10 deletions OGS/rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,14 @@ 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;

FilePath = FilePath + getDirSep();

std::string solver_pkg_name = BuildInfo::SOLVER_PACKAGE_NAME;
// No default linear solver package is in use.
if (solver_pkg_name.find("Default") == std::string::npos)
Expand Down