152 namespace fs = std::filesystem;
162 H5SetVerbosityLevel(1);
174 std::cout.precision(16);
175 std::cout.setf(std::ios::scientific, std::ios::floatfield);
176 std::cerr.precision(16);
177 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
191 std::error_code error_code;
193 std::cerr << error_code.message() << std::endl;
200 std::cerr <<
"unable to create directory; aborting" << std::endl;
211 char *startup = getenv(
"HOME");
212 std::filesystem::path p = strncat(startup,
"/init.opal", 20);
213 if (startup !=
nullptr && is_regular_file(p)) {
222 ERRORMSG(
"Could not open startup file '" << startup <<
"'\n"
223 <<
"Note: this is not mandatory for an OPAL simulation!\n");
227 *
gmsg <<
"Reading startup file '" << startup <<
"'" <<
endl;
229 *
gmsg <<
"Finished reading startup file." <<
endl;
234 <<
"Couldn't find startup file '" << startup <<
"'\n"
235 <<
"Note: this is not mandatory for an OPAL simulation!\n" <<
endl;
242 int inputFileArgument = -1;
244 std::string restartFileName;
246 for(
int ii = 1; ii < argc; ++ ii) {
247 std::string argStr = std::string(argv[ii]);
248 if (argStr == std::string(
"-h") ||
249 argStr == std::string(
"-help") ||
250 argStr == std::string(
"--help")) {
253 }
else if (argStr == std::string(
"--help-command")) {
258 ::printStdoutHeader();
263 *
gmsg <<
"\nOpalParser::printHelp(): Unknown object \""
264 << cmdName <<
"\".\n" <<
endl;
268 object->printHelp(std::cout);
270 }
else if (argStr == std::string(
"--version")) {
272 std::cout << OPAL_PROJECT_VERSION << std::endl;
275 }
else if (argStr == std::string(
"--version-full")) {
276 ::printStdoutHeader();
281 std::string(OPAL_COMPILE_OPTIONS) +
283 std::set<std::string> uniqOptions;
284 while (options.length() > 0) {
285 size_t n = options.find_first_of(
' ');
287 options = options.substr(n + 1);
288 n = options.find_first_of(
' ');
291 uniqOptions.insert(options.substr(0, n));
292 options = options.substr(n + 1);
294 for (
auto it: uniqOptions) {
298 std::string header(
"Compile-time options: ");
299 while (options.length() > 58) {
300 std::string line = options.substr(0, 58);
301 size_t n = line.find_last_of(
' ');
302 INFOMSG(header << line.substr(0, n) <<
"\n");
304 header = std::string(22,
' ');
305 options = options.substr(n + 1);
309 }
else if (argStr == std::string(
"--git-revision")) {
314 }
else if (argStr == std::string(
"--input")) {
316 inputFileArgument = ii;
318 }
else if (argStr == std::string(
"-restart") ||
319 argStr == std::string(
"--restart")) {
323 }
else if (argStr == std::string(
"-restartfn") ||
324 argStr == std::string(
"--restartfn")) {
325 restartFileName = std::string(argv[++ ii]);
327 }
else if ( argStr.find(
"noInitAMR") != std::string::npos) {
330 if (inputFileArgument == -1 &&
331 (ii == 1 || ii + 1 == argc) &&
332 argv[ii][0] !=
'-') {
333 inputFileArgument = ii;
336 INFOMSG(
"Unknown argument \"" << argStr <<
"\"" <<
endl);
343 ::printStdoutHeader();
344 if (inputFileArgument == -1) {
349 fname = std::string(argv[inputFileArgument]);
350 if (!fs::exists(fname)) {
351 INFOMSG(
"Input file '" << fname <<
"' doesn't exist!" <<
endl);
358 if (restartFileName.empty()) {
361 if (!fs::exists(restartFileName)) {
362 INFOMSG(
"Restart file '" << restartFileName <<
"' doesn't exist!" <<
endl);
374 *
gmsg <<
"Input file '" << fname <<
"' not found." <<
endl;
378 *
gmsg <<
"* Reading input stream '" << fname <<
"'" <<
endl;
380 *
gmsg <<
"* End of input stream '" << fname <<
"'" <<
endl;
384 std::ifstream errormsg(
"errormsg.txt");
385 if(errormsg.good()) {
387 std::string closure(
" *\n");
389 <<
"* **********************************************************************************\n"
390 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S *********************\n"
391 <<
"* **********************************************************************************"
393 errormsg.getline(buffer, 256);
394 while(errormsg.good()) {
396 if(errormsg.gcount() == 1) {
398 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
399 ERRORMSG(buffer << closure.substr(errormsg.gcount() - 1));
403 errormsg.getline(buffer, 256);
406 <<
"* **********************************************************************************\n"
407 <<
"* **********************************************************************************"
417 errorMsg <<
"\n*** User error detected by function \""
418 << ex.
where() <<
"\"\n";
420 std::string what = ex.
what();
421 size_t pos = what.find_first_of(
'\n');
423 errorMsg <<
" " << what.substr(0, pos) <<
endl;
424 what = what.substr(pos + 1, std::string::npos);
425 pos = what.find_first_of(
'\n');
426 }
while (pos != std::string::npos);
427 errorMsg <<
" " << what <<
endl;
429 MPI_Abort(MPI_COMM_WORLD, -100);
432 errorMsg <<
"\n*** User error detected by function \""
433 << ex.
where() <<
"\"\n";
435 std::string what = ex.
what();
436 size_t pos = what.find_first_of(
'\n');
438 errorMsg <<
" " << what.substr(0, pos) <<
endl;
439 what = what.substr(pos + 1, std::string::npos);
440 pos = what.find_first_of(
'\n');
441 }
while (pos != std::string::npos);
442 errorMsg <<
" " << what <<
endl;
444 MPI_Abort(MPI_COMM_WORLD, -100);
448 errorMsg <<
"\n*** Error detected by function \""
449 << ex.
where() <<
"\"\n";
450 std::string what = ex.
what();
451 size_t pos = what.find_first_of(
'\n');
453 errorMsg <<
" " << what.substr(0, pos) <<
endl;
454 what = what.substr(pos + 1, std::string::npos);
455 pos = what.find_first_of(
'\n');
456 }
while (pos != std::string::npos);
457 errorMsg <<
" " << what <<
endl;
459 MPI_Abort(MPI_COMM_WORLD, -100);
463 errorMsg <<
"\n*** Error detected by function \""
464 << ex.
where() <<
"\"\n";
465 std::string what = ex.
what();
466 size_t pos = what.find_first_of(
'\n');
468 errorMsg <<
" " << what.substr(0, pos) <<
endl;
469 what = what.substr(pos + 1, std::string::npos);
470 pos = what.find_first_of(
'\n');
471 }
while (pos != std::string::npos);
472 errorMsg <<
" " << what <<
endl;
474 MPI_Abort(MPI_COMM_WORLD, -100);
475 }
catch(std::bad_alloc &ex) {
477 errorMsg <<
"\n*** Error:\n";
478 errorMsg <<
" Sorry, virtual memory exhausted.\n"
482 MPI_Abort(MPI_COMM_WORLD, -100);
485 errorMsg <<
"\n*** Runtime-error ******************\n";
486 std::string what = ex.
what();
487 size_t pos = what.find_first_of(
'\n');
489 errorMsg <<
" " << what.substr(0, pos) <<
endl;
490 what = what.substr(pos + 1, std::string::npos);
491 pos = what.find_first_of(
'\n');
492 }
while (pos != std::string::npos);
493 errorMsg <<
" " << what <<
endl;
495 errorMsg <<
"\n************************************\n" <<
endl;
496 throw std::runtime_error(
"in Parser");
497 }
catch(std::exception &ex) {
501 <<
" Internal OPAL error: \n";
502 std::string what = ex.
what();
503 size_t pos = what.find_first_of(
'\n');
505 errorMsg <<
" " << what.substr(0, pos) <<
endl;
506 what = what.substr(pos + 1, std::string::npos);
507 pos = what.find_first_of(
'\n');
508 }
while (pos != std::string::npos);
509 errorMsg <<
" " << what <<
endl;
511 MPI_Abort(MPI_COMM_WORLD, -100);
514 errorMsg <<
"\n*** Error:\n"
515 <<
" Unexpected exception caught.\n" <<
endl;
517 MPI_Abort(MPI_COMM_WORLD, -100);
531#ifndef DONT_DEFINE_IPPL_GMSG
540 amrex::Finalize(
true);
546#ifndef DONT_DEFINE_IPPL_GMSG