From 6231c1e323d77076237a0ccc28c3d8d19358e3e6 Mon Sep 17 00:00:00 2001 From: johnhg Date: Tue, 23 Feb 2021 14:28:08 -0700 Subject: [PATCH] Per #1439, add check_mask_names() utility function which errors out if the list of masking region names is non-unique. Update Point-Stat and Grid-Stat to call it. (#1679) --- met/src/basic/vx_config/config_util.cc | 16 ++++++++++++++++ met/src/basic/vx_config/config_util.h | 2 ++ met/src/basic/vx_log/string_array.cc | 2 +- met/src/basic/vx_log/string_array.h | 2 +- .../tools/core/grid_stat/grid_stat_conf_info.cc | 3 +++ .../core/point_stat/point_stat_conf_info.cc | 3 +++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/met/src/basic/vx_config/config_util.cc b/met/src/basic/vx_config/config_util.cc index d48941bf3d..084c3a593e 100644 --- a/met/src/basic/vx_config/config_util.cc +++ b/met/src/basic/vx_config/config_util.cc @@ -2170,6 +2170,22 @@ void parse_conf_range_double(Dictionary *dict, double &beg, double &end) { /////////////////////////////////////////////////////////////////////////////// +void check_mask_names(const StringArray &sa) { + StringArray sa_uniq = sa.uniq(); + + // Check for unique mask names + if(sa_uniq.n() < sa.n()) { + mlog << Error << "\ncheck_mask_names() -> " + << "found non-unique strings in the list of masking region names (" + << write_css(sa) << ")!\n\n"; + exit(1); + } + + return; +} + +/////////////////////////////////////////////////////////////////////////////// + void check_climo_n_vx(Dictionary *dict, const int n_vx) { int n; diff --git a/met/src/basic/vx_config/config_util.h b/met/src/basic/vx_config/config_util.h index f526165a93..d09a154c4c 100644 --- a/met/src/basic/vx_config/config_util.h +++ b/met/src/basic/vx_config/config_util.h @@ -73,6 +73,8 @@ extern map extern void parse_conf_range_int(Dictionary *dict, int &beg, int &end); extern void parse_conf_range_double(Dictionary *dict, double &beg, double &end); +extern void check_mask_names(const StringArray &); + extern void check_climo_n_vx(Dictionary *dict, const int); extern InterpMthd int_to_interpmthd(int); diff --git a/met/src/basic/vx_log/string_array.cc b/met/src/basic/vx_log/string_array.cc index 10f2660320..e48a46e2b3 100644 --- a/met/src/basic/vx_log/string_array.cc +++ b/met/src/basic/vx_log/string_array.cc @@ -615,7 +615,7 @@ return; //////////////////////////////////////////////////////////////////////// -StringArray StringArray::uniq() +StringArray StringArray::uniq() const { diff --git a/met/src/basic/vx_log/string_array.h b/met/src/basic/vx_log/string_array.h index ada442282b..8cec395275 100644 --- a/met/src/basic/vx_log/string_array.h +++ b/met/src/basic/vx_log/string_array.h @@ -115,7 +115,7 @@ class StringArray { // return a unique subset of strings // - StringArray uniq(); + StringArray uniq() const; }; diff --git a/met/src/tools/core/grid_stat/grid_stat_conf_info.cc b/met/src/tools/core/grid_stat/grid_stat_conf_info.cc index a97c9a6693..a5702ca06f 100644 --- a/met/src/tools/core/grid_stat/grid_stat_conf_info.cc +++ b/met/src/tools/core/grid_stat/grid_stat_conf_info.cc @@ -353,6 +353,9 @@ void GridStatConfInfo::process_masks(const Grid &grid) { exit(1); } + // Check for unique mask names + check_mask_names(vx_opt[i].mask_name); + } // end for i return; diff --git a/met/src/tools/core/point_stat/point_stat_conf_info.cc b/met/src/tools/core/point_stat/point_stat_conf_info.cc index f00072f837..0d8dd3fa43 100644 --- a/met/src/tools/core/point_stat/point_stat_conf_info.cc +++ b/met/src/tools/core/point_stat/point_stat_conf_info.cc @@ -363,6 +363,9 @@ void PointStatConfInfo::process_masks(const Grid &grid) { } // end for j + // Check for unique mask names + check_mask_names(vx_opt[i].mask_name); + } // end for i return;