15 #include "eckit/config/LocalConfiguration.h"
16 #include "eckit/config/YAMLConfiguration.h"
17 #include "eckit/exception/Exceptions.h"
20 #include "oops/util/LibOOPS.h"
21 #include "oops/util/Logger.h"
22 #include "oops/util/ObjectCountHelper.h"
23 #include "oops/util/TimerHelper.h"
30 int getEnv(
const std::string& env,
int default_value) {
31 if (::getenv(env.c_str())) {
return eckit::Translator<std::string, int>()(::getenv(env.c_str()));}
35 std::string
getEnv(
const std::string& env, std::string default_value) {
36 if ((::getenv(env.c_str()))) {return ::getenv(env.c_str());}
44 Run::Run(
int argc,
char** argv) :
eckit::Main(argc, argv,
"OOPS_HOME"), config_(), timer_() {
47 int do_profile =
getEnv(
"OOPS_PROFILE", 0);
54 std::string utr =
getEnv(
"OOPS_UNDERLYING_TIMER",
"nanotime");
55 if (utr ==
"nanotime") {
56 ret = GPTLsetutr(GPTLnanotime);
57 }
else if (utr ==
"gettimeofday") {
58 ret = GPTLsetutr(GPTLgettimeofday);
60 Log::warning() <<
"OOPS_UNDERLYING_TIMER=" << utr <<
" is invalid: ignoring" << std::endl;
64 ret = GPTLsetoption(GPTLprint_method, GPTLmost_frequent);
68 int sync_mpi =
getEnv(
"OOPS_SYNC_MPI", 1);
70 ret = GPTLsetoption(GPTLsync_mpi, 1);
73 int dopr_memusage =
getEnv(
"OOPS_MEMUSAGE", 0);
75 ret = GPTLsetoption(GPTLdopr_memusage, 1);
77 ret = GPTLinitialize();
81 LibOOPS::instance().initialise();
85 eckit::PathName configfile = argv[1];
87 eckit::PathName outputfile;
89 LibOOPS::instance().teeOutput(outputfile);
93 config_.reset(
new eckit::YAMLConfiguration(configfile));
95 Log::info() <<
"Configuration input file is: " << configfile << std::endl;
96 Log::info() <<
"Full configuration is:" << *
config_ << std::endl;
99 util::ObjectCountHelper::start();
100 util::TimerHelper::start();
106 LibOOPS::instance().finalise();
107 Log::trace() <<
"Oops::Run destructed" << std::endl;
114 Log::info() <<
"Run: Starting " << app << std::endl;
118 catch(
const eckit::Exception & e) {
120 Log::error() << e.what() <<
" caught in " << Here() << std::endl;
121 Log::error() <<
"Exception: " << app <<
" terminating..." << std::endl;
124 catch(
const std::exception & e) {
126 Log::error() <<
"Exception: " << e.what() << std::endl;
127 Log::error() <<
"Exception: " << app <<
" terminating..." << std::endl;
131 Log::error() <<
"Unknown exception: " << app <<
" terminating..." << std::endl;
133 Log::info() <<
"Run: Finishing " << app << std::endl;
136 util::ObjectCountHelper::stop();
137 util::TimerHelper::stop();
139 Log::info() <<
"Run: Finishing " << app <<
" with status = " <<
status << std::endl;