Skip to content

Commit

Permalink
Clean up diagnostic file header writing
Browse files Browse the repository at this point in the history
Note: standard streams in C++ are right-justified by default (compared
to Python, where numbers are right-justified and strings are
left-justified).

* update the header printing code for gravity_diag.out to match the
  others (the column numbers were 26 characters long instead of 25, and
  number 8 was missing)
* simplify species formatting for species_diag.out (the previous code
  was just adding leading spaces)
* update the header field widths for amr_diag.out to match what's used
  for the data
  • Loading branch information
yut23 committed Dec 1, 2023
1 parent 02a2d50 commit f240694
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions Source/driver/sum_integrated_quantities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Castro::sum_integrated_quantities ()
header << std::endl;

data_log1 << std::setw(intwidth) << "# COLUMN 1";
data_log1 << std::setw(fixwidth) << " 2";
data_log1 << std::setw(fixwidth) << 2;

for (int icol = 3; icol <= n; ++icol) {
data_log1 << std::setw(datwidth) << icol;
Expand Down Expand Up @@ -482,28 +482,29 @@ Castro::sum_integrated_quantities ()

if (time == 0.0) {

log << std::setw(intwidth) << "# COLUMN 1";
log << std::setw(fixwidth) << " 2";
log << std::setw(fixwidth) << " 3";
log << std::setw(fixwidth) << " 4";
log << std::setw(fixwidth) << " 5";
log << std::setw(fixwidth) << " 6";
log << std::setw(fixwidth) << " 7";
int n = 0;

std::ostringstream header;

header << std::setw(intwidth) << "# TIMESTEP";
header << std::setw(fixwidth) << " TIME";
header << std::setw(intwidth) << "# TIMESTEP"; ++n;
header << std::setw(fixwidth) << " TIME"; ++n;

header << std::setw(datwidth) << " h_+ (x)";
header << std::setw(datwidth) << " h_x (x)";
header << std::setw(datwidth) << " h_+ (y)";
header << std::setw(datwidth) << " h_x (y)";
header << std::setw(datwidth) << " h_+ (z)";
header << std::setw(datwidth) << " h_x (z)";
header << std::setw(datwidth) << " h_+ (x)"; ++n;
header << std::setw(datwidth) << " h_x (x)"; ++n;
header << std::setw(datwidth) << " h_+ (y)"; ++n;
header << std::setw(datwidth) << " h_x (y)"; ++n;
header << std::setw(datwidth) << " h_+ (z)"; ++n;
header << std::setw(datwidth) << " h_x (z)"; ++n;

header << std::endl;

log << std::setw(intwidth) << "# COLUMN 1";
log << std::setw(fixwidth) << 2;

for (int i = 3; i <= n; ++i) {
log << std::setw(datwidth) << i;
}

log << std::endl;

log << header.str();
Expand Down Expand Up @@ -589,27 +590,17 @@ Castro::sum_integrated_quantities ()

std::ostringstream header;

header << std::setw(intwidth) << "# TIMESTEP"; ++n;
header << std::setw(fixwidth) << " TIME"; ++n;

// We need to be careful here since the species names have differing numbers of characters
header << std::setw(intwidth) << "# TIMESTEP"; ++n;
header << std::setw(fixwidth) << " TIME"; ++n;

for (int i = 0; i < NumSpec; i++) {
std::string outString{};
std::string massString{"Mass "};
std::string specString{species_names[i]};
while (static_cast<int>(outString.length() + specString.length() + massString.length()) < datwidth) {
outString += " ";
}
outString += massString;
outString += specString;
header << std::setw(datwidth) << outString; ++n;
header << std::setw(datwidth) << ("Mass " + species_names[i]); ++n;
}

header << std::endl;

log << std::setw(intwidth) << "# COLUMN 1";
log << std::setw(fixwidth) << " 2";
log << std::setw(fixwidth) << 2;

for (int i = 3; i <= n; ++i) {
log << std::setw(datwidth) << i;
Expand Down Expand Up @@ -694,19 +685,19 @@ Castro::sum_integrated_quantities ()
header << std::setw(fixwidth) << " DT"; ++n;
header << std::setw(intwidth) << " FINEST LEV"; ++n;
header << std::setw(fixwidth) << " MAX NUMBER OF SUBCYCLES"; ++n;
header << std::setw(fixwidth) << " COARSE TIMESTEP WALLTIME"; ++n;
header << std::setw(datwidth) << " COARSE TIMESTEP WALLTIME"; ++n;
#ifdef AMREX_USE_GPU
header << std::setw(fixwidth) << " MAXIMUM GPU MEMORY USED"; ++n;
header << std::setw(fixwidth) << " MINIMUM GPU MEMORY FREE"; ++n;
header << std::setw(datwidth) << " MAXIMUM GPU MEMORY USED"; ++n;
header << std::setw(datwidth) << " MINIMUM GPU MEMORY FREE"; ++n;
#endif

header << std::endl;

log << std::setw(intwidth) << "# COLUMN 1";
log << std::setw(fixwidth) << " 2";
log << std::setw(fixwidth) << 2;

for (int i = 3; i < 4; ++i) {
log << std::setw(datwidth) << i;
log << std::setw(fixwidth) << i;
}

log << std::setw(intwidth) << 4; // Handle the finest lev column
Expand Down

0 comments on commit f240694

Please sign in to comment.