Skip to content

Commit

Permalink
Re-written the reading of command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqing committed May 29, 2018
1 parent bbb93f5 commit 89ed00d
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 108 deletions.
2 changes: 1 addition & 1 deletion FEM/files0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static bool checkFormatOfInputFiles(const std::string& basename)
last modified: OK 16.10.2002
*/
/**************************************************************************/
int ReadData(char* dateiname, GEOLIB::GEOObjects& geo_obj, std::string& unique_name)
int ReadData(const char* dateiname, GEOLIB::GEOObjects& geo_obj, std::string& unique_name)
{
#if defined(USE_MPI) // WW
if (myrank == 0)
Expand Down
4 changes: 2 additions & 2 deletions FEM/problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/*------------------------------------------------------------------------*/
// Data file
// OK411
extern int ReadData(char*, GEOLIB::GEOObjects& geo_obj, std::string& unique_name);
extern int ReadData(const char*, GEOLIB::GEOObjects& geo_obj, std::string& unique_name);
/* PCS */
#include "pcs_dm.h"
#include "rf_pcs.h"
Expand Down Expand Up @@ -112,7 +112,7 @@ using process::CRFProcessDeformation;
PreTimeloop
Modification:
***************************************************************************/
Problem::Problem (char* filename) :
Problem::Problem (const char* filename) :
dt0(0.), print_result(true),
_linear_shapefunction_pool(NULL), _quadr_shapefunction_pool(NULL),
_geo_obj (new GEOLIB::GEOObjects), _geo_name (filename),
Expand Down
2 changes: 1 addition & 1 deletion FEM/problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef double (Problem::*ProblemMemFn)(void);
class Problem
{
public:
Problem(char* filename = NULL);
Problem(const char* filename = NULL);
~Problem();
void Euler_TimeDiscretize();
void RosenBrock_TimeDiscretize(){};
Expand Down
234 changes: 130 additions & 104 deletions OGS/rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* */
#include "BuildInfo.h"

#include <iostream>

#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \
|| defined(USE_MPI_KRC)
#include "par_ddc.h"
Expand Down Expand Up @@ -104,91 +106,10 @@ double elapsed_time_mpi;
/**************************************************************************/
int main(int argc, char* argv[])
{
/* parse command line arguments */
std::string anArg;
std::string modelRoot;
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \
|| defined(USE_MPI_KRC)
int nb_ddc = 0; // number of cores for DDC related processes
#endif

for (int i = 1; i < argc; i++)
{
anArg = std::string(argv[i]);
if (anArg == "--help" || anArg == "-h")
{
std::cout << "Usage: ogs [MODEL_ROOT] [OPTIONS]\n"
<< "Where OPTIONS are:\n"
<< " -h [--help] print this message and exit\n"
<< " -b [--build-info] print build info and exit\n"
<< " --output-directory DIR put output files into DIR\n"
<< " --version print ogs version and exit"
<< "\n";
continue;
}
if (anArg == "--build-info" || anArg == "-b")
{
std::cout << "ogs version: " << BuildInfo::OGS_VERSION << "\n"
<< "ogs date: " << BuildInfo::OGS_DATE << "\n";
std::cout << "git commit info: " << BuildInfo::GIT_COMMIT_INFO << "\n";
std::cout << "build timestamp: " << BuildInfo::BUILD_TIMESTAMP << "\n";
continue;
}
if (anArg == "--version")
{
std::cout << BuildInfo::OGS_VERSION << "\n";
continue;
}
if (anArg == "--model-root" || anArg == "-m")
{
if (i + 1 >= argc)
{
std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl;
std::exit(EXIT_FAILURE);
}
modelRoot = std::string(argv[++i]);
continue;
}
if (anArg == "--output-directory")
{
if (i + 1 >= argc)
{
std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl;
std::exit(EXIT_FAILURE);
}
std::string path = argv[++i];

if (!path.empty())
defaultOutputPath = path;
continue;
}
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \
|| defined(USE_MPI_KRC)
std::string decompositions;
if (anArg == "--domain-decomposition" || anArg == "-ddc")
{
decompositions = std::string(argv[++i]);
nb_ddc = atoi(decompositions.c_str());
continue;
}
#endif
// anything left over must be the model root, unless already found
if (modelRoot == "")
modelRoot = std::string(argv[i]);
} // end of parse argc loop

if (argc > 1 && modelRoot == "") // non-interactive mode and no model given
exit(0); // e.g. just wanted the build info

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)
{
std::cout << "\nWarning: " << solver_pkg_name << " other than the OGS default one is in use." << std::endl;
std::cout << " The solver setting may need to be adjusted for the solution accuracy!" << std::endl;
}

char* dateiname(NULL);
#ifdef SUPERCOMPUTER
// *********************************************************************
// buffered output ... important for performance on cray
Expand Down Expand Up @@ -249,36 +170,122 @@ int main(int argc, char* argv[])
// Initialization of the lis solver.
lis_initialize(&argc, &argv);
#endif
/*========================================================================*/
/* Kommunikation mit Betriebssystem */
/* Timer fuer Gesamtzeit starten */
#ifdef TESTTIME
TStartTimer(0);
#endif
/* Intro ausgeben */

std::vector<std::string> arg_strings;
if (argc > 1)
{
for (int i = 1; i < argc; i++)
{
arg_strings.push_back(std::string(argv[i]));
}
}
else
{
#if defined(USE_MPI) // WW
if (myrank == 0)
if (myrank == 0)
#endif
#ifdef USE_PETSC
if (rank == 0)
#endif
DisplayStartMsg();

DisplayStartMsg();
std::string s_buff;
std::stringstream ss;
getline(std::cin, s_buff);
ss.str(s_buff);
while (!ss.eof())
{
ss >> s_buff;
arg_strings.push_back(s_buff);
}
}

// LB Check if file exists
std::string tmpFilename = dateiname;
tmpFilename.append(".pcs");
if (!IsFileExisting(tmpFilename))
for (std::size_t i = 0; i < arg_strings.size(); i++)
{
std::cout << " Error: Cannot find file " << dateiname << "\n";
return 1;
}
const std::string anArg = arg_strings[i];
if (anArg == "--help" || anArg == "-h")
{
std::cout << "Usage: ogs [MODEL_ROOT] [OPTIONS]\n"
<< "Where OPTIONS are:\n"
<< " -h [--help] print this message and exit\n"
<< " -b [--build-info] print build info and exit\n"
<< " --output-directory DIR put output files into DIR\n"
<< " --version print ogs version and exit"
<< "\n";
exit(0);
}
if (anArg == "--build-info" || anArg == "-b")
{
std::cout << "ogs version: " << BuildInfo::OGS_VERSION << "\n"
<< "ogs date: " << BuildInfo::OGS_DATE << "\n";
std::cout << "git commit info: " << BuildInfo::GIT_COMMIT_INFO << "\n";
std::cout << "build timestamp: " << BuildInfo::BUILD_TIMESTAMP << "\n";
exit(0);
}
if (anArg == "--version")
{
std::cout << BuildInfo::OGS_VERSION << "\n";
exit(0);
}
if (anArg == "--model-root" || anArg == "-m")
{
if (i + 1 >= arg_strings.size())
{
std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl;
std::exit(EXIT_FAILURE);
}
// modelRoot = std::string(arg_strings[++i]);
continue;
}
if (anArg == "--output-directory")
{
if (i + 1 >= arg_strings.size())
{
std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl;
std::exit(EXIT_FAILURE);
}
std::string path = arg_strings[++i];

// If no option is given, output files are placed in the same directory as the input files
if (defaultOutputPath.empty())
defaultOutputPath = pathDirname(std::string(dateiname));
if (!path.empty())
defaultOutputPath = path;
continue;
}
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \
|| defined(USE_MPI_KRC)
std::string decompositions;
if (anArg == "--domain-decomposition" || anArg == "-ddc")
{
if (i + 1 >= arg_strings.size())
{
std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl;
std::exit(EXIT_FAILURE);
}
decompositions = std::string(arg_strings[++i]);
nb_ddc = atoi(decompositions.c_str());
continue;
}
#endif
else
{
FileName = arg_strings[i];
}
} // end of parse argc loop

if (argc > 1)
{
#if defined(USE_MPI) // WW
if (myrank == 0)
#endif
#ifdef USE_PETSC
if (rank == 0)
#endif
DisplayStartMsg();
}

#ifdef TESTTIME
TStartTimer(0);
#endif

FileName = dateiname;
size_t indexChWin, indexChLinux;
indexChWin = indexChLinux = 0;
indexChWin = FileName.find_last_of('\\');
Expand All @@ -288,8 +295,29 @@ int main(int argc, char* argv[])
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
if (defaultOutputPath.empty())
defaultOutputPath = FilePath;

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)
{
std::cout << "\nWarning: " << solver_pkg_name << " other than the OGS default one is in use." << std::endl;
std::cout << " The solver setting may need to be adjusted for the solution accuracy!" << std::endl;
}

// LB Check if file exists
std::string tmpFilename = FileName;
tmpFilename.append(".pcs");
if (!IsFileExisting(tmpFilename))
{
std::cout << " Error: Cannot find file " << FileName << "\n";
return 1;
}

// ---------------------------WW
Problem* aproblem = new Problem(dateiname);
Problem* aproblem = new Problem(FileName.data());
#ifdef USE_PETSC
aproblem->setRankandSize(rank, r_size);
#endif
Expand Down Expand Up @@ -350,8 +378,6 @@ int main(int argc, char* argv[])
#endif
/*--------- LIS Finalize ------------------*/

free(dateiname);

#ifdef USE_PETSC
// kg44 quick fix to compile PETSC with version PETSCV3.4
#if (PETSC_VERSION_NUMBER > 3030)
Expand Down

0 comments on commit 89ed00d

Please sign in to comment.