Skip to content

Commit edd077a

Browse files
committed
ParmParse: pretty_print_table
Print to python output.
1 parent 3088ea1 commit edd077a

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/Base/ParmParse.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <AMReX_IntVect.H>
1010
#include <AMReX_ParmParse.H>
1111

12+
#include <iostream>
1213
#include <string>
1314
#include <vector>
1415

@@ -77,16 +78,29 @@ void init_ParmParse(py::module &m)
7778
return ref;
7879
},
7980
"parses input values", py::arg("name"), py::arg("ival")=0
80-
)
81+
)
8182

82-
.def("query_int",
83-
[](ParmParse &pp, std::string name, int ival) {
84-
int ref;
85-
bool exist = pp.query(name.c_str(), ref, ival);
86-
return std::make_tuple(exist,ref);
87-
},
88-
"queries input values", py::arg("name"), py::arg("ival")=0
89-
)
83+
.def("query_int",
84+
[](ParmParse &pp, std::string name, int ival) {
85+
int ref;
86+
bool exist = pp.query(name.c_str(), ref, ival);
87+
return std::make_tuple(exist,ref);
88+
},
89+
"queries input values", py::arg("name"), py::arg("ival")=0
90+
)
91+
92+
.def(
93+
"pretty_print_table",
94+
[](ParmParse &pp) {
95+
py::scoped_ostream_redirect stream(
96+
std::cout, // std::ostream&
97+
py::module_::import("sys").attr("stdout") // Python output
98+
);
99+
pp.prettyPrintTable(std::cout);
100+
},
101+
"Write the table in a pretty way to the ostream. If there are "
102+
"duplicates, only the last one is printed."
103+
)
90104

91105
// TODO: dumpTable, hasUnusedInputs, getUnusedInputs, getEntries
92106
;

src/pyAMReX.H

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <pybind11/pybind11.h>
1212
#include <pybind11/functional.h>
13+
#include <pybind11/iostream.h>
1314
#include <pybind11/numpy.h>
1415
#include <pybind11/operators.h>
1516
#include <pybind11/stl.h>

tests/test_parmparse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ def test_parmparse():
1616
assert dopml
1717
assert dt == 1.0e-5
1818
assert ncell == 100
19+
20+
pp.pretty_print_table()

0 commit comments

Comments
 (0)