Skip to content

Commit

Permalink
Fix the handling of diagnostic name and units strings. Both are limited
Browse files Browse the repository at this point in the history
to 7 characters but the units are enclosed in parantheses, increasing
the field width to 9. If the strings are too long, truncate them and
print warnings like this:
WARNING: OutFileInfo::write_cira_diag_vals() -> long diagnostic name "850TANGXXX" truncated to "850TANG"!
WARNING: OutFileInfo::write_cira_diag_vals() -> long diagnostic units string "(10^7C/MXXX)" truncated to "(10^7C/M)"!
Pad the first 2 columns out to widths of 7 and 9 and set the
inter-column spacing between columns 2 and 3 to 0. This could
technically introduce parsing problems when the units are 7 characters
long and the values have 5 digits, but this is the logic needed to
exactly replicate the existing output.
  • Loading branch information
JohnHalleyGotway committed Jan 26, 2024
1 parent f593599 commit 5db10ce
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/tools/tc_utils/tc_diag/tc_diag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,9 @@ void OutFileInfo::write_cira_diag_vals(vector<string> &k,

if(!cira_diag_out) return;

// Store lead time information
const char *method_name = "OutFileInfo::write_cira_diag_vals()";

// Store lead time information for standard storm and sounding data sections
if(write_time) {
NumArray times;
for(int i=0; i<trk_ptr->n_points(); i++) {
Expand All @@ -1950,6 +1952,7 @@ void OutFileInfo::write_cira_diag_vals(vector<string> &k,

// Variables write AsciiTable output
ConcatString cs;
string str;
AsciiTable at;
int n_row = m.size();
int n_col = bad_data_int;
Expand All @@ -1964,6 +1967,10 @@ void OutFileInfo::write_cira_diag_vals(vector<string> &k,
n_col = 2 + m.at(*it).n();
at.set_size(n_row, n_col);

// Set spacing after the second column to 0
// since the units column is right-padded
at.set_ics(1, 0);

// Justify columns
at.set_column_just(0, LeftJust);
at.set_column_just(1, LeftJust);
Expand All @@ -1977,12 +1984,30 @@ void OutFileInfo::write_cira_diag_vals(vector<string> &k,
c = 0;

// Diagnostic name
at.set_entry(r, c++, *it);

// Units
cs << cs_erase << "("
<< get_diag_units(*it) << ")";
at.set_entry(r, c++, cs);
str = *it;

// Truncate or pad diagnostic names
if(str.length() > cira_diag_name_width) {
str = (*it).substr(0, cira_diag_name_width);
mlog << Warning << "\n" << method_name << " -> "
<< "long diagnostic name \"" << (*it)
<< "\" truncated to \"" << str << "\"!\n\n";
}
str.append(cira_diag_name_width - str.length(), ' ');
at.set_entry(r, c++, str);

// Units string
str = "(" + get_diag_units(*it) + ")";

// Truncate or pad units strings
if(str.length() > cira_diag_units_width) {
str = "(" + get_diag_units(*it).substr(0, cira_diag_units_width - 2) + ")";
mlog << Warning << "\n" << method_name << " -> "
<< "long diagnostic units string \"(" << get_diag_units(*it)
<< ")\" truncated to \"" << str << "\"!\n\n";
}
str.append(cira_diag_units_width - str.length(), ' ');
at.set_entry(r, c++, str);

// Diagnostic values
for(int i=0; i<m.at(*it).n(); i++) {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/tc_utils/tc_diag/tc_diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static const char* default_out_prefix = "";
// Diagnostics bad data value
static const double diag_bad_data_double = 9999.0;

// Maximum string lengths
static const int cira_diag_name_width = 7;
static const int cira_diag_units_width = 9;

////////////////////////////////////////////////////////////////////////
//
// Variables for Command Line Arguments
Expand Down

0 comments on commit 5db10ce

Please sign in to comment.