149 namespace fs = std::filesystem;
159 H5SetVerbosityLevel(1);
171 std::cout.precision(16);
172 std::cout.setf(std::ios::scientific, std::ios::floatfield);
173 std::cerr.precision(16);
174 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
188 std::error_code error_code;
190 std::cerr << error_code.message() << std::endl;
197 std::cerr <<
"unable to create directory; aborting" << std::endl;
208 char *startup = getenv(
"HOME");
209 std::filesystem::path p = strncat(startup,
"/init.opal", 20);
210 if (startup !=
nullptr && is_regular_file(p)) {
219 ERRORMSG(
"Could not open startup file '" << startup <<
"'\n"
220 <<
"Note: this is not mandatory for an OPAL simulation!\n");
224 *
gmsg <<
"Reading startup file '" << startup <<
"'" <<
endl;
226 *
gmsg <<
"Finished reading startup file." <<
endl;
231 <<
"Couldn't find startup file '" << startup <<
"'\n"
232 <<
"Note: this is not mandatory for an OPAL simulation!\n" <<
endl;
239 int inputFileArgument = -1;
241 std::string restartFileName;
243 for(
int ii = 1; ii < argc; ++ ii) {
244 std::string argStr = std::string(argv[ii]);
245 if (argStr == std::string(
"-h") ||
246 argStr == std::string(
"-help") ||
247 argStr == std::string(
"--help")) {
250 }
else if (argStr == std::string(
"--help-command")) {
255 ::printStdoutHeader();
260 *
gmsg <<
"\nOpalParser::printHelp(): Unknown object \""
261 << cmdName <<
"\".\n" <<
endl;
265 object->printHelp(std::cout);
267 }
else if (argStr == std::string(
"--version")) {
269 std::cout << OPAL_PROJECT_VERSION << std::endl;
272 }
else if (argStr == std::string(
"--version-full")) {
273 ::printStdoutHeader();
278 std::string(OPAL_COMPILE_OPTIONS) +
280 std::set<std::string> uniqOptions;
281 while (options.length() > 0) {
282 size_t n = options.find_first_of(
' ');
284 options = options.substr(n + 1);
285 n = options.find_first_of(
' ');
288 uniqOptions.insert(options.substr(0, n));
289 options = options.substr(n + 1);
291 for (
auto it: uniqOptions) {
295 std::string header(
"Compile-time options: ");
296 while (options.length() > 58) {
297 std::string line = options.substr(0, 58);
298 size_t n = line.find_last_of(
' ');
299 INFOMSG(header << line.substr(0, n) <<
"\n");
301 header = std::string(22,
' ');
302 options = options.substr(n + 1);
306 }
else if (argStr == std::string(
"--git-revision")) {
311 }
else if (argStr == std::string(
"--input")) {
313 inputFileArgument = ii;
315 }
else if (argStr == std::string(
"-restart") ||
316 argStr == std::string(
"--restart")) {
320 }
else if (argStr == std::string(
"-restartfn") ||
321 argStr == std::string(
"--restartfn")) {
322 restartFileName = std::string(argv[++ ii]);
324 }
else if ( argStr.find(
"noInitAMR") != std::string::npos) {
327 if (inputFileArgument == -1 &&
328 (ii == 1 || ii + 1 == argc) &&
329 argv[ii][0] !=
'-') {
330 inputFileArgument = ii;
333 INFOMSG(
"Unknown argument \"" << argStr <<
"\"" <<
endl);
340 ::printStdoutHeader();
341 if (inputFileArgument == -1) {
346 fname = std::string(argv[inputFileArgument]);
347 if (!fs::exists(fname)) {
348 INFOMSG(
"Input file '" << fname <<
"' doesn't exist!" <<
endl);
355 if (restartFileName.empty()) {
358 if (!fs::exists(restartFileName)) {
359 INFOMSG(
"Restart file '" << restartFileName <<
"' doesn't exist!" <<
endl);
371 *
gmsg <<
"Input file '" << fname <<
"' not found." <<
endl;
375 *
gmsg <<
"* Reading input stream '" << fname <<
"'" <<
endl;
377 *
gmsg <<
"* End of input stream '" << fname <<
"'" <<
endl;
381 std::ifstream errormsg(
"errormsg.txt");
382 if(errormsg.good()) {
384 std::string closure(
" *\n");
386 <<
"* **********************************************************************************\n"
387 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S *********************\n"
388 <<
"* **********************************************************************************"
390 errormsg.getline(buffer, 256);
391 while(errormsg.good()) {
393 if(errormsg.gcount() == 1) {
395 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
396 ERRORMSG(buffer << closure.substr(errormsg.gcount() - 1));
400 errormsg.getline(buffer, 256);
403 <<
"* **********************************************************************************\n"
404 <<
"* **********************************************************************************"
414 errorMsg <<
"\n*** User error detected by function \""
415 << ex.
where() <<
"\"\n";
417 std::string what = ex.
what();
418 size_t pos = what.find_first_of(
'\n');
420 errorMsg <<
" " << what.substr(0, pos) <<
endl;
421 what = what.substr(pos + 1, std::string::npos);
422 pos = what.find_first_of(
'\n');
423 }
while (pos != std::string::npos);
424 errorMsg <<
" " << what <<
endl;
426 MPI_Abort(MPI_COMM_WORLD, -100);
429 errorMsg <<
"\n*** User error detected by function \""
430 << ex.
where() <<
"\"\n";
432 std::string what = ex.
what();
433 size_t pos = what.find_first_of(
'\n');
435 errorMsg <<
" " << what.substr(0, pos) <<
endl;
436 what = what.substr(pos + 1, std::string::npos);
437 pos = what.find_first_of(
'\n');
438 }
while (pos != std::string::npos);
439 errorMsg <<
" " << what <<
endl;
441 MPI_Abort(MPI_COMM_WORLD, -100);
445 errorMsg <<
"\n*** Error detected by function \""
446 << ex.
where() <<
"\"\n";
447 std::string what = ex.
what();
448 size_t pos = what.find_first_of(
'\n');
450 errorMsg <<
" " << what.substr(0, pos) <<
endl;
451 what = what.substr(pos + 1, std::string::npos);
452 pos = what.find_first_of(
'\n');
453 }
while (pos != std::string::npos);
454 errorMsg <<
" " << what <<
endl;
456 MPI_Abort(MPI_COMM_WORLD, -100);
460 errorMsg <<
"\n*** Error detected by function \""
461 << ex.
where() <<
"\"\n";
462 std::string what = ex.
what();
463 size_t pos = what.find_first_of(
'\n');
465 errorMsg <<
" " << what.substr(0, pos) <<
endl;
466 what = what.substr(pos + 1, std::string::npos);
467 pos = what.find_first_of(
'\n');
468 }
while (pos != std::string::npos);
469 errorMsg <<
" " << what <<
endl;
471 MPI_Abort(MPI_COMM_WORLD, -100);
472 }
catch(std::bad_alloc &ex) {
474 errorMsg <<
"\n*** Error:\n";
475 errorMsg <<
" Sorry, virtual memory exhausted.\n"
479 MPI_Abort(MPI_COMM_WORLD, -100);
482 errorMsg <<
"\n*** Runtime-error ******************\n";
483 std::string what = ex.
what();
484 size_t pos = what.find_first_of(
'\n');
486 errorMsg <<
" " << what.substr(0, pos) <<
endl;
487 what = what.substr(pos + 1, std::string::npos);
488 pos = what.find_first_of(
'\n');
489 }
while (pos != std::string::npos);
490 errorMsg <<
" " << what <<
endl;
492 errorMsg <<
"\n************************************\n" <<
endl;
493 throw std::runtime_error(
"in Parser");
494 }
catch(std::exception &ex) {
498 <<
" Internal OPAL error: \n";
499 std::string what = ex.
what();
500 size_t pos = what.find_first_of(
'\n');
502 errorMsg <<
" " << what.substr(0, pos) <<
endl;
503 what = what.substr(pos + 1, std::string::npos);
504 pos = what.find_first_of(
'\n');
505 }
while (pos != std::string::npos);
506 errorMsg <<
" " << what <<
endl;
508 MPI_Abort(MPI_COMM_WORLD, -100);
511 errorMsg <<
"\n*** Error:\n"
512 <<
" Unexpected exception caught.\n" <<
endl;
514 MPI_Abort(MPI_COMM_WORLD, -100);
532 amrex::Finalize(
true);