150 namespace fs = std::filesystem;
160 H5SetVerbosityLevel(1);
172 std::cout.precision(16);
173 std::cout.setf(std::ios::scientific, std::ios::floatfield);
174 std::cerr.precision(16);
175 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
189 std::error_code error_code;
191 std::cerr << error_code.message() << std::endl;
198 std::cerr <<
"unable to create directory; aborting" << std::endl;
209 char *startup = getenv(
"HOME");
210 std::filesystem::path p = strncat(startup,
"/init.opal", 20);
211 if (startup !=
nullptr && is_regular_file(p)) {
220 ERRORMSG(
"Could not open startup file '" << startup <<
"'\n"
221 <<
"Note: this is not mandatory for an OPAL simulation!\n");
225 *
gmsg <<
"Reading startup file '" << startup <<
"'" <<
endl;
227 *
gmsg <<
"Finished reading startup file." <<
endl;
232 <<
"Couldn't find startup file '" << startup <<
"'\n"
233 <<
"Note: this is not mandatory for an OPAL simulation!\n" <<
endl;
240 int inputFileArgument = -1;
242 std::string restartFileName;
244 for(
int ii = 1; ii < argc; ++ ii) {
245 std::string argStr = std::string(argv[ii]);
246 if (argStr == std::string(
"-h") ||
247 argStr == std::string(
"-help") ||
248 argStr == std::string(
"--help")) {
251 }
else if (argStr == std::string(
"--help-command")) {
256 ::printStdoutHeader();
261 *
gmsg <<
"\nOpalParser::printHelp(): Unknown object \""
262 << cmdName <<
"\".\n" <<
endl;
268 }
else if (argStr == std::string(
"--version")) {
270 std::cout << OPAL_PROJECT_VERSION << std::endl;
273 }
else if (argStr == std::string(
"--version-full")) {
274 ::printStdoutHeader();
279 std::string(OPAL_COMPILE_OPTIONS) +
281 std::set<std::string> uniqOptions;
282 while (options.length() > 0) {
283 size_t n = options.find_first_of(
' ');
285 options = options.substr(n + 1);
286 n = options.find_first_of(
' ');
289 uniqOptions.insert(options.substr(0, n));
290 options = options.substr(n + 1);
292 for (
auto it: uniqOptions) {
296 std::string header(
"Compile-time options: ");
297 while (options.length() > 58) {
298 std::string line = options.substr(0, 58);
299 size_t n = line.find_last_of(
' ');
300 INFOMSG(header << line.substr(0, n) <<
"\n");
302 header = std::string(22,
' ');
303 options = options.substr(n + 1);
307 }
else if (argStr == std::string(
"--git-revision")) {
312 }
else if (argStr == std::string(
"--input")) {
314 inputFileArgument = ii;
316 }
else if (argStr == std::string(
"-restart") ||
317 argStr == std::string(
"--restart")) {
321 }
else if (argStr == std::string(
"-restartfn") ||
322 argStr == std::string(
"--restartfn")) {
323 restartFileName = std::string(argv[++ ii]);
325 }
else if ( argStr.find(
"noInitAMR") != std::string::npos) {
328 if (inputFileArgument == -1 &&
329 (ii == 1 || ii + 1 == argc) &&
330 argv[ii][0] !=
'-') {
331 inputFileArgument = ii;
334 INFOMSG(
"Unknown argument \"" << argStr <<
"\"" <<
endl);
341 ::printStdoutHeader();
342 if (inputFileArgument == -1) {
347 fname = std::string(argv[inputFileArgument]);
348 if (!fs::exists(fname)) {
349 INFOMSG(
"Input file '" << fname <<
"' doesn't exist!" <<
endl);
356 if (restartFileName.empty()) {
359 if (!fs::exists(restartFileName)) {
360 INFOMSG(
"Restart file '" << restartFileName <<
"' doesn't exist!" <<
endl);
372 *
gmsg <<
"Input file '" << fname <<
"' not found." <<
endl;
376 *
gmsg <<
"* Reading input stream '" << fname <<
"'" <<
endl;
378 *
gmsg <<
"* End of input stream '" << fname <<
"'" <<
endl;
382 std::ifstream errormsg(
"errormsg.txt");
383 if(errormsg.good()) {
385 std::string closure(
" *\n");
387 <<
"* **********************************************************************************\n"
388 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S *********************\n"
389 <<
"* **********************************************************************************"
391 errormsg.getline(buffer, 256);
392 while(errormsg.good()) {
394 if(errormsg.gcount() == 1) {
396 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
397 ERRORMSG(buffer << closure.substr(errormsg.gcount() - 1));
401 errormsg.getline(buffer, 256);
404 <<
"* **********************************************************************************\n"
405 <<
"* **********************************************************************************"
415 errorMsg <<
"\n*** User error detected by function \""
416 << ex.
where() <<
"\"\n";
418 std::string what = ex.
what();
419 size_t pos = what.find_first_of(
'\n');
421 errorMsg <<
" " << what.substr(0, pos) <<
endl;
422 what = what.substr(pos + 1, std::string::npos);
423 pos = what.find_first_of(
'\n');
424 }
while (pos != std::string::npos);
425 errorMsg <<
" " << what <<
endl;
427 MPI_Abort(MPI_COMM_WORLD, -100);
430 errorMsg <<
"\n*** User error detected by function \""
431 << ex.
where() <<
"\"\n";
433 std::string what = ex.
what();
434 size_t pos = what.find_first_of(
'\n');
436 errorMsg <<
" " << what.substr(0, pos) <<
endl;
437 what = what.substr(pos + 1, std::string::npos);
438 pos = what.find_first_of(
'\n');
439 }
while (pos != std::string::npos);
440 errorMsg <<
" " << what <<
endl;
442 MPI_Abort(MPI_COMM_WORLD, -100);
446 errorMsg <<
"\n*** Error detected by function \""
447 << ex.
where() <<
"\"\n";
448 std::string what = ex.
what();
449 size_t pos = what.find_first_of(
'\n');
451 errorMsg <<
" " << what.substr(0, pos) <<
endl;
452 what = what.substr(pos + 1, std::string::npos);
453 pos = what.find_first_of(
'\n');
454 }
while (pos != std::string::npos);
455 errorMsg <<
" " << what <<
endl;
457 MPI_Abort(MPI_COMM_WORLD, -100);
461 errorMsg <<
"\n*** Error detected by function \""
462 << ex.
where() <<
"\"\n";
463 std::string what = ex.
what();
464 size_t pos = what.find_first_of(
'\n');
466 errorMsg <<
" " << what.substr(0, pos) <<
endl;
467 what = what.substr(pos + 1, std::string::npos);
468 pos = what.find_first_of(
'\n');
469 }
while (pos != std::string::npos);
470 errorMsg <<
" " << what <<
endl;
472 MPI_Abort(MPI_COMM_WORLD, -100);
473 }
catch(std::bad_alloc &ex) {
475 errorMsg <<
"\n*** Error:\n";
476 errorMsg <<
" Sorry, virtual memory exhausted.\n"
480 MPI_Abort(MPI_COMM_WORLD, -100);
483 errorMsg <<
"\n*** Runtime-error ******************\n";
484 std::string what = ex.
what();
485 size_t pos = what.find_first_of(
'\n');
487 errorMsg <<
" " << what.substr(0, pos) <<
endl;
488 what = what.substr(pos + 1, std::string::npos);
489 pos = what.find_first_of(
'\n');
490 }
while (pos != std::string::npos);
491 errorMsg <<
" " << what <<
endl;
493 errorMsg <<
"\n************************************\n" <<
endl;
494 throw std::runtime_error(
"in Parser");
495 }
catch(std::exception &ex) {
499 <<
" Internal OPAL error: \n";
500 std::string what = ex.
what();
501 size_t pos = what.find_first_of(
'\n');
503 errorMsg <<
" " << what.substr(0, pos) <<
endl;
504 what = what.substr(pos + 1, std::string::npos);
505 pos = what.find_first_of(
'\n');
506 }
while (pos != std::string::npos);
507 errorMsg <<
" " << what <<
endl;
509 MPI_Abort(MPI_COMM_WORLD, -100);
512 errorMsg <<
"\n*** Error:\n"
513 <<
" Unexpected exception caught.\n" <<
endl;
515 MPI_Abort(MPI_COMM_WORLD, -100);
533 amrex::Finalize(
true);