Skip to content

Wrap deck output at 132 characters - #5335

Open
kriben wants to merge 1 commit into
OPM:masterfrom
CeetronSolutions:deckoutput-line-width
Open

Wrap deck output at 132 characters#5335
kriben wants to merge 1 commit into
OPM:masterfrom
CeetronSolutions:deckoutput-line-width

Conversation

@kriben

@kriben kriben commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

DeckOutput broke a record into lines by counting items only, so keywords whose records hold more than fmt.columns items were split, while data keywords such as SWOF or PVTO were written as one line per record. A rel. perm. table with 40 rows became a single line of more than a thousand characters, and Eclipse 100 rejects lines longer than 132 characters. Decks written by FileDeck could therefore not be run by that simulator.

Track the width of the line being written and break the record before it grows past fmt.max_line_width, which defaults to 132 and disables the check when set to zero. A value is measured before it is written, so a break never falls inside a quoted string. Values are formatted through format_value() and written by write_token() to make the width known before anything reaches the stream.

DeckOutput broke a record into lines by counting items only, so keywords
whose records hold more than fmt.columns items were split, while data
keywords such as SWOF or PVTO were written as one line per record.  A
rel. perm. table with 40 rows became a single line of more than a
thousand characters, and Eclipse 100 rejects lines longer than 132
characters.  Decks written by FileDeck could therefore not be run by
that simulator.

Track the width of the line being written and break the record before it
grows past fmt.max_line_width, which defaults to 132 and disables the
check when set to zero.  A value is measured before it is written, so a
break never falls inside a quoted string.  Values are formatted through
format_value() and written by write_token() to make the width known
before anything reaches the stream.
@bska
bska requested a lite review from Copilot September 7, 2026 08:49
@bska bska added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Sep 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

current_width tracking can become incorrect when write_string() outputs newline-containing strings, and format_value(double) does not preserve the output stream locale, both of which can lead to incorrect or inconsistent wrapping/formatting.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates DeckOutput to enforce a maximum output line width (defaulting to 132 characters to satisfy Eclipse 100 constraints) by pre-formatting tokens to measure their width before writing, and wrapping records before they exceed the configured limit.

Changes:

  • Add fmt.max_line_width (default 132, 0 disables) and track current_width while writing.
  • Refactor record writing to format tokens first (format_value) and write via write_token so wrapping decisions can be made before streaming.
  • Add regression tests covering bounded width wrapping, unlimited width, and round-trip parsing of a wrapped deck.
File summaries
File Description
tests/parser/DeckTests.cpp Adds tests for max line width wrapping, unlimited width mode, and deck round-trip parsing under 132-char constraints.
opm/input/eclipse/Deck/DeckOutput.hpp Extends formatting options with max_line_width and adds internal width tracking/hooks for tokenized writing.
opm/input/eclipse/Deck/DeckOutput.cpp Implements width tracking/wrapping and token pre-formatting before writing to the stream.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 55 to 58
void DeckOutput::write_string(const std::string& s) {
this->os << s;
this->current_width += s.size();
}
Comment on lines 86 to 93
template <>
void DeckOutput::write_value( const double& value ) {
this->os << value;
std::string DeckOutput::format_value( const double& value ) {
std::ostringstream ss;
ss.flags( this->os.flags() );
ss.precision( this->os.precision() );
ss << value;
return ss.str();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants