1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
/***********************************************/
/**
* @file groops.cpp
*
* @brief main.
*
* @author Torsten Mayer-Guerr
* @date 2007
*
*/
/***********************************************/
/**
* @mainpage
*
@verbatim
Gravity Recovery Object Oriented Programming System (GROOPS)
Usage: groops [--log <logfile.txt>] [--settings <groopsDefaults.xml>] [--silent] [--global name=value] <configfile.xml>
groops --write-settings <groopsDefaults.xml>
groops --xsd <schemafile.xsd>
groops --doc <documentation/>
-h, --help this text
-l, --log append messages to logfile. If a directory is given, one time-stamped logfile will be created inside for each groops script.
-g, --global pass a global variable to config files as name=value pair
-c, --settings read constants from file (default search: groopsDefaults.xml)
-s, --silent runs silently
-d, --doc generate documentation files (latex/html/...)
-x, --xsd write xsd-schema of xml-configfile options
-C, --write-settings write the users current settings to file
GitHub repository: https://github.com/groops-devs/groops
@endverbatim
*/
/** @defgroup base Base
* @brief Basic functions and classes. */
/** @defgroup parserGroup Parser
* @brief XML, mathematical expression and string parser. */
/** @defgroup inputOutputGroup Input/Output
* @brief Low level input/output. */
/** @defgroup parallelGroup Parallel
* @brief Wrapper for Message Passing Interface (MPI). */
/** @defgroup filesGroup File formats
* @brief Definition of groops file formats. */
/** @defgroup configGroup Config
* @brief Config and documentation. */
/** @defgroup classesGroup Classes
* @brief Abstract interfaces. */
/** @defgroup gnssGroup GNSS
* @brief Global Navigation Satellite Systems. */
/** @defgroup slrGroup SLR
* @brief Satellite Laser Ranging. */
/** @defgroup plotGroup Plots
* @brief Classes and functions for plotting. */
/** @defgroup miscGroup Misc
* @brief Classes and functions which do not fit into other groups. */
/** @defgroup programsGroup Programs
* @brief The Apps. */
/** @defgroup programsConversionGroup Programs/conversion
* @ingroup programsGroup
* @brief Programs for conversion of strange formats. */
/***********************************************/
#include "programs/program.h"
#include "inputOutput/settings.h"
#include "inputOutput/system.h"
#include "config/generateDocumentation.h"
/***********************************************/
static void groopsHelp(const std::string &progName, Parallel::CommunicatorPtr comm)
{
if(Parallel::isMaster(comm))
{
std::cout<<"Gravity Recovery Object Oriented Programming System (GROOPS)"<<std::endl;
std::cout<<"Usage: "<<progName<<" [--log <logfile.txt>] [--settings <groopsDefaults.xml>] [--silent] [--global name=value] <configfile.xml>"<<std::endl;
std::cout<<" "<<progName<<" --write-settings <groopsDefaults.xml>"<<std::endl;
std::cout<<" "<<progName<<" --xsd <schemafile.xsd>"<<std::endl;
std::cout<<" "<<progName<<" --doc <documentation/>"<<std::endl;
std::cout<<std::endl;
std::cout<<" -h, --help this text"<<std::endl;
std::cout<<" -l, --log append messages to logfile. If a directory is given, one time-stamped logfile will be created inside for each groops script."<<std::endl;
std::cout<<" -g, --global pass a global variable to config files as name=value pair"<<std::endl;
std::cout<<" -c, --settings read constants from file (default search: groopsDefaults.xml)"<<std::endl;
std::cout<<" -s, --silent runs silently"<<std::endl;
std::cout<<" -d, --doc generate documentation files (latex/html/...)"<<std::endl;
std::cout<<" -x, --xsd write xsd-schema of xml-configfile options"<<std::endl;
std::cout<<" -C, --write-settings write the users current settings to file"<<std::endl;
std::cout<<""<<std::endl;
std::cout<<"GitHub repository: https://github.com/groops-devs/groops"<<std::endl;
std::cout<<"(Compiled: "<<__DATE__<<" "<<__TIME__<<")"<<std::endl;
}
exit(EXIT_FAILURE);
}
/***********************************************/
int main(int argc, char *argv[])
{
Parallel::CommunicatorPtr comm = Parallel::init(argc, argv);
// init parallel logging
Log::init(Parallel::myRank(comm), Parallel::size(comm), Parallel::addChannel(Log::getReceive(), comm));
Log::GroupPtr groupPtr;
try
{
Parallel::broadCastExceptions(comm, [&](Parallel::CommunicatorPtr comm)
{
// handle commandline options
// --------------------------
FileName logFileName;
FileName schemaFileName;
FileName docFileName;
FileName settingsFileName;
FileName writeSettingsFileName;
Bool silent = FALSE;
Bool workDone = FALSE;
std::map<std::string, std::string> commandlineGlobals;
std::vector<FileName> configFileNames;
for(int i=1; i<argc; i++)
{
auto optArg = [&]()
{
if((i+1 >= argc) || (argv[i+1][0] == '-'))
{
logWarningOnce<<"Expected argument for: '"<<argv[i]<<"'"<<Log::endl;
groopsHelp(argv[0], comm);
return std::string();
}
return std::string(argv[++i]);
};
const std::string opt(argv[i]);
if ((opt == "-l") || (opt == "--log")) {logFileName = FileName(optArg());}
else if((opt == "-x") || (opt == "--xsd")) {schemaFileName = FileName(optArg());}
else if((opt == "-d") || (opt == "--doc")) {docFileName = FileName(optArg());}
else if((opt == "-c") || (opt == "--settings")) {settingsFileName = FileName(optArg());}
else if((opt == "-C") || (opt == "--write-settings")) {writeSettingsFileName = FileName(optArg());}
else if((opt == "-s") || (opt == "--silent")) {silent = TRUE;}
else if((opt == "-h") || (opt == "--help")) {groopsHelp(argv[0], comm);}
else if((opt == "-g") || (opt == "--global"))
{
std::string keyVal(optArg());
std::size_t delim = keyVal.find("=");
if(delim == std::string::npos || delim+1 == keyVal.size())
{
logWarningOnce<<"Unable to parse key-value pair <"<<keyVal<<"> for option '-g'."<<Log::endl;
groopsHelp(argv[0], comm);
}
else
commandlineGlobals[keyVal.substr(0, delim)] = keyVal.substr(delim+1);
}
else if(opt[0] == '-')
{
logWarningOnce<<"Unknown option: '"<<opt<<"'"<<Log::endl;
groopsHelp(argv[0], comm);
}
else
{
configFileNames.push_back(FileName(opt));
}
}
// ============================================
// start logging
// -------------
groupPtr = Log::group(Parallel::isMaster(comm), silent);
if(!System::isDirectory(logFileName))
Log::setLogFile(logFileName);
if(Parallel::size(comm) > 1)
logStatus<<"=== Starting GROOPS with "<<Parallel::size(comm)<<" processes ==="<<Log::endl;
else
logStatus<<"=== Starting GROOPS ==="<<Log::endl;
// read default settings and constants
// -----------------------------------
if(!settingsFileName.empty())
{
logInfo<<"settings: <"<<settingsFileName<<">"<<Log::endl;
readFileSettings(settingsFileName);
}
else // exists groopsDefaults.xml?
{
settingsFileName = "groopsDefaults.xml";
if(System::exists(settingsFileName))
{
logInfo<<"settings: <"<<settingsFileName<<">"<<Log::endl;
readFileSettings(settingsFileName);
}
}
// writing xsd schema file
// ------------------------
if(!schemaFileName.empty())
{
workDone = TRUE;
logStatus<<"writing xsd schema file: <"<<schemaFileName<<">"<<Log::endl;
if(Parallel::isMaster(comm))
Config::writeSchema(schemaFileName);
}
// generate documentation
// ----------------------
if(!docFileName.empty())
{
workDone = TRUE;
logStatus<<"generate documentation files in <"<<docFileName<<">"<<Log::endl;
if(Parallel::isMaster(comm))
Documentation::write(docFileName);
}
// write settings
// --------------
if(!writeSettingsFileName.empty())
{
workDone = TRUE;
logStatus<<"writing settings file: <"<<writeSettingsFileName<<">"<<Log::endl;
if(Parallel::isMaster(comm))
writeFileSettings(writeSettingsFileName);
}
// Starting Programs
// -----------------
for(auto &configFileName : configFileNames)
{
// If the user specifies a directory as the logging target,
// a time-stamped log file is created under that directory for each groops script,
// and log output for that script is redirected there.
if(System::isDirectory(logFileName))
{
FileName thisLogFileName = logFileName.append(configFileName.stripDirectory().str()+"_"+System::now().dateTimeStr()+".log");
logInfo<<"Future logs are written to file <"<<thisLogFileName<<">"<<Log::endl;
Log::setLogFile(thisLogFileName);
}
logInfo<<"Config file: <"<<configFileName<<">"<<Log::endl;
Config config(configFileName, commandlineGlobals);
ProgramConfig programs;
readConfig(config, "program", programs, Config::OPTIONAL, "", "");
VariableList varList;
programs.run(varList, comm);
workDone = TRUE;
}
// ============================================
if(!workDone)
groopsHelp(argv[0], comm);
Parallel::barrier(comm);
logStatus<<"=== Finished GROOPS ==="<<Log::endl;
Parallel::barrier(comm);
}); // Parallel::broadCastExceptions()
}
catch(std::exception &e)
{
if(Parallel::isMaster(comm))
{
logError<<"****** Error ******"<<Log::endl;
logError<<e.what()<<Log::endl;
logStatus<<"=== Finished GROOPS with error ==="<<Log::endl;
}
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/***********************************************/
|