diff --git a/Src/Base/AMReX_ParmParse.H b/Src/Base/AMReX_ParmParse.H index cc19946fc4..cc9588793d 100644 --- a/Src/Base/AMReX_ParmParse.H +++ b/Src/Base/AMReX_ParmParse.H @@ -1352,6 +1352,10 @@ public: //! Write the contents of the table in ASCII to the ostream. static void dumpTable (std::ostream& os, bool prettyPrint = false); + //! Write the table in a pretty way to the ostream. If there are + //! duplicates, only the last one is printed. + static void prettyPrintTable (std::ostream& os); + //! Add keys and values from a file to the end of the PP table. static void addfile (std::string const& filename); diff --git a/Src/Base/AMReX_ParmParse.cpp b/Src/Base/AMReX_ParmParse.cpp index 61e3ffc1e7..df1e18e9b0 100644 --- a/Src/Base/AMReX_ParmParse.cpp +++ b/Src/Base/AMReX_ParmParse.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -1209,6 +1210,32 @@ ParmParse::dumpTable (std::ostream& os, bool prettyPrint) } } +void +ParmParse::prettyPrintTable (std::ostream& os) +{ + std::vector sorted_names; + sorted_names.reserve(g_table.size()); + for (auto const& [name, entry] : g_table) { + sorted_names.push_back(name); + } + std::sort(sorted_names.begin(), sorted_names.end()); + + for (auto const& name : sorted_names) { + auto const& entry = g_table[name]; + std::vector value_string; + std::unordered_map count; + for (auto const& vals : entry.m_vals) { + value_string.emplace_back(pp_to_pretty_string(name, vals)); + ++count[value_string.back()]; + } + for (auto const& s : value_string) { + if (--count[s] == 0) { + os << s << '\n'; + } + } + } +} + int ParmParse::countval (const char* name, int n) const