OGS
anonymous_namespace{Dump.cpp} Namespace Reference

Functions

std::vector< std::string > parseDumpContent (std::istream &in, std::size_t const num_chemical_systems, std::size_t const start_id=0)

Function Documentation

◆ parseDumpContent()

std::vector< std::string > anonymous_namespace{Dump.cpp}::parseDumpContent ( std::istream & in,
std::size_t const num_chemical_systems,
std::size_t const start_id = 0 )

Parse a PHREEQC dump stream and return accumulated SOLUTION_RAW blocks. Each block's ID is remapped to num_chemical_systems + (start_id + index) + 1, matching the convention expected by the next timestep's PHREEQC input.

Definition at line 15 of file Dump.cpp.

19{
20 std::vector<std::string> results;
21 std::string line;
22 std::string current;
23 std::size_t id = start_id;
24
25 while (std::getline(in, line))
26 {
27 // Strip trailing \r for robustness when the stream was produced on a
28 // platform with CRLF line endings.
29 if (!line.empty() && line.back() == '\r')
30 {
31 line.pop_back();
32 }
33 if (line.find("USE reaction_pressure none") != std::string::npos)
34 {
35 break;
36 }
37 if (line.find("SOLUTION_RAW") != std::string::npos)
38 {
39 current = "SOLUTION_RAW " +
40 std::to_string(num_chemical_systems + id + 1) + "\n";
41 continue;
42 }
43 current += line;
44 current += "\n";
45 if (line.find("-gammas") != std::string::npos)
46 {
47 results.push_back(std::move(current));
48 current.clear();
49 ++id;
50 }
51 }
52 return results;
53}