1 #ifndef ERF_DIAGNOSTICS_LOG_H
2 #define ERF_DIAGNOSTICS_LOG_H
10 #include <AMReX_ParallelDescriptor.H>
11 #include <AMReX_Utility.H>
22 inline bool open_log (std::ofstream& out,
const std::string& fname,
bool truncate)
24 const auto slash = fname.rfind(
'/');
25 if (slash != std::string::npos && !amrex::UtilCreateDirectory(fname.substr(0, slash), 0755)) {
26 amrex::Abort(
"cannot create the directory of the diagnostics file '" + fname +
"'");
28 bool need_header = truncate;
30 std::ifstream probe(fname, std::ios::ate);
31 need_header = !probe || probe.tellg() <= 0;
33 out.open(fname, truncate ? std::ios::trunc : std::ios::app);
34 if (!out) { amrex::Abort(
"cannot open moving-bodies diagnostics file '" + fname +
"'"); }
45 int exists = amrex::ParallelDescriptor::IOProcessor() ? (amrex::FileExists(fname) ? 1 : 0) : 0;
46 amrex::ParallelDescriptor::Bcast(&exists, 1, amrex::ParallelDescriptor::IOProcessorNumber());
Definition: ERF_ActuatorDeviceBuffers.H:14
bool file_exists_everywhere(const std::string &fname)
Definition: ERF_DiagnosticsLog.H:43
bool open_log(std::ofstream &out, const std::string &fname, bool truncate)
Definition: ERF_DiagnosticsLog.H:22