Skip to content

Commit

Permalink
Per #2366, define is_req_level_match() utility function and update Po…
Browse files Browse the repository at this point in the history
…int-Stat and Grid-Stat to call it. Update logic to use the FIRST U/V match found and indicate that in the log message.
  • Loading branch information
JohnHalleyGotway committed Dec 7, 2022
1 parent f270743 commit 0553c57
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 52 deletions.
11 changes: 11 additions & 0 deletions src/libcode/vx_data2d/var_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -933,3 +933,14 @@ ConcatString raw_magic_str(Dictionary i_edict, GrdFileType file_type) {
}

////////////////////////////////////////////////////////////////////////

bool is_req_level_match(const ConcatString &s1, const ConcatString &s2) {
bool match = true;

// No match if either is non-empty and they are not equal.
if((s1.nonempty() || s2.nonempty()) && !(s1 == s2)) match = false;

return(match);
}

////////////////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions src/libcode/vx_data2d/var_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class EnsVarInfo {
////////////////////////////////////////////////////////////////////////

ConcatString raw_magic_str(Dictionary i_edict, GrdFileType file_type);
bool is_req_level_match(const ConcatString &, const ConcatString &);

///////////////////////////////////////////////////////////////////////////////

Expand Down
39 changes: 18 additions & 21 deletions src/tools/core/grid_stat/grid_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ void GridStatConfInfo::process_config(GrdFileType ftype,
vx_opt[i].obs_info->uv_index() >= 0) {
mlog << Warning << "\nGridStatConfInfo::process_config() -> "
<< "For U-wind, found multiple matching V-wind field array entries! "
<< "Set the \"level\" strings to differentiate between them.\n\n";
<< "Using the first match found. Set the \"level\" strings to "
<< "differentiate between them.\n\n";
}
else {
vx_opt[i].fcst_info->set_uv_index(j);
vx_opt[i].obs_info->set_uv_index(j);
}

vx_opt[i].fcst_info->set_uv_index(j);
vx_opt[i].obs_info->set_uv_index(j);
}
}

Expand Down Expand Up @@ -232,7 +234,8 @@ void GridStatConfInfo::process_config(GrdFileType ftype,
vx_opt[i].obs_info->uv_index() >= 0) {
mlog << Warning << "\nGridStatConfInfo::process_config() -> "
<< "For V-wind, found multiple matching U-wind field array entries! "
<< "Set the \"level\" strings to differentiate between them.\n\n";
<< "Using the first match found. Set the \"level\" strings to "
<< "differentiate between them.\n\n";
}

vx_opt[i].fcst_info->set_uv_index(j);
Expand Down Expand Up @@ -937,18 +940,8 @@ bool GridStatVxOpt::is_uv_match(const GridStatVxOpt &v) const {

//
// Check that requested forecast and observation levels match.
// Requested levels are empty for python embedding.
//
if( ( fcst_info->req_level_name().nonempty() ||
v.fcst_info->req_level_name().nonempty()) &&
!( fcst_info->req_level_name() ==
v.fcst_info->req_level_name())) match = false;

else if( ( obs_info->req_level_name().nonempty() ||
v.obs_info->req_level_name().nonempty()) &&
!( obs_info->req_level_name() ==
v.obs_info->req_level_name())) match = false;

// Requested levels are optional for python embedding and may be empty.
// Check that the masking regions and interpolation options match.
//
// The following do not impact matched pairs:
// desc, var_name, var_suffix,
Expand All @@ -962,10 +955,14 @@ bool GridStatVxOpt::is_uv_match(const GridStatVxOpt &v) const {
// hss_ec_value, rank_corr_flag, output_flag, nc_info
//

else if(!(mask_grid == v.mask_grid ) ||
!(mask_poly == v.mask_poly ) ||
!(mask_name == v.mask_name ) ||
!(interp_info == v.interp_info)) match = false;
if(!is_req_level_match( fcst_info->req_level_name(),
v.fcst_info->req_level_name()) ||
!is_req_level_match( obs_info->req_level_name(),
v.obs_info->req_level_name()) ||
!(mask_grid == v.mask_grid ) ||
!(mask_poly == v.mask_poly ) ||
!(mask_name == v.mask_name ) ||
!(interp_info == v.interp_info)) match = false;

return(match);
}
Expand Down
59 changes: 28 additions & 31 deletions src/tools/core/point_stat/point_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ void PointStatConfInfo::process_config(GrdFileType ftype) {
vx_opt[i].vx_pd.obs_info->uv_index() >= 0) {
mlog << Warning << "\nPointStatConfInfo::process_config() -> "
<< "For U-wind, found multiple matching V-wind field array entries! "
<< "Set the \"level\" strings to differentiate between them.\n\n";
<< "Using the first match found. Set the \"level\" strings to "
<< "differentiate between them.\n\n";
}

vx_opt[i].vx_pd.fcst_info->set_uv_index(j);
Expand Down Expand Up @@ -226,11 +227,13 @@ void PointStatConfInfo::process_config(GrdFileType ftype) {
vx_opt[i].vx_pd.obs_info->uv_index() >= 0) {
mlog << Warning << "\nPointStatConfInfo::process_config() -> "
<< "For U-wind, found multiple matching V-wind field array entries! "
<< "Set the \"level\" strings to differentiate between them.\n\n";
<< "Using the first match found. Set the \"level\" strings to "
<< "differentiate between them.\n\n";
}
else {
vx_opt[i].vx_pd.fcst_info->set_uv_index(j);
vx_opt[i].vx_pd.obs_info->set_uv_index(j);
}

vx_opt[i].vx_pd.fcst_info->set_uv_index(j);
vx_opt[i].vx_pd.obs_info->set_uv_index(j);
}
}

Expand Down Expand Up @@ -737,18 +740,8 @@ bool PointStatVxOpt::is_uv_match(const PointStatVxOpt &v) const {

//
// Check that requested forecast and observation levels match.
// Requested levels are empty for python embedding.
//
if( ( vx_pd.fcst_info->req_level_name().nonempty() ||
v.vx_pd.fcst_info->req_level_name().nonempty()) &&
!( vx_pd.fcst_info->req_level_name() ==
v.vx_pd.fcst_info->req_level_name())) match = false;

else if( ( vx_pd.obs_info->req_level_name().nonempty() ||
v.vx_pd.obs_info->req_level_name().nonempty()) &&
!( vx_pd.obs_info->req_level_name() ==
v.vx_pd.obs_info->req_level_name())) match = false;

// Requested levels are optional for python embedding and may be empty.
// Check that several other config options also match.
//
// The following do not impact matched pairs:
// fcat_ta, ocat_ta,
Expand All @@ -759,20 +752,24 @@ bool PointStatVxOpt::is_uv_match(const PointStatVxOpt &v) const {
// rank_corr_flag, output_flag
//

else if(!(beg_ds == v.beg_ds ) ||
!(end_ds == v.end_ds ) ||
!(land_flag == v.land_flag ) ||
!(topo_flag == v.topo_flag ) ||
!(mask_grid == v.mask_grid ) ||
!(mask_poly == v.mask_poly ) ||
!(mask_sid == v.mask_sid ) ||
!(mask_llpnt == v.mask_llpnt ) ||
!(mask_name == v.mask_name ) ||
!(interp_info == v.interp_info ) ||
!(msg_typ == v.msg_typ ) ||
!(duplicate_flag == v.duplicate_flag) ||
!(obs_summary == v.obs_summary ) ||
!(obs_perc == v.obs_perc )) match = false;
if(!is_req_level_match( vx_pd.fcst_info->req_level_name(),
v.vx_pd.fcst_info->req_level_name()) ||
!is_req_level_match( vx_pd.obs_info->req_level_name(),
v.vx_pd.obs_info->req_level_name()) ||
!(beg_ds == v.beg_ds ) ||
!(end_ds == v.end_ds ) ||
!(land_flag == v.land_flag ) ||
!(topo_flag == v.topo_flag ) ||
!(mask_grid == v.mask_grid ) ||
!(mask_poly == v.mask_poly ) ||
!(mask_sid == v.mask_sid ) ||
!(mask_llpnt == v.mask_llpnt ) ||
!(mask_name == v.mask_name ) ||
!(interp_info == v.interp_info ) ||
!(msg_typ == v.msg_typ ) ||
!(duplicate_flag == v.duplicate_flag) ||
!(obs_summary == v.obs_summary ) ||
!(obs_perc == v.obs_perc )) match = false;

return(match);
}
Expand Down

0 comments on commit 0553c57

Please sign in to comment.