From e865e98698bec80284dd2c533c300a80d0dc9804 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Tue, 5 Nov 2024 15:27:29 +0000 Subject: [PATCH] Per #2966, reduce SonarQube findings --- src/tools/other/gen_vx_mask/gen_vx_mask.cc | 216 +++++++++++---------- 1 file changed, 113 insertions(+), 103 deletions(-) diff --git a/src/tools/other/gen_vx_mask/gen_vx_mask.cc b/src/tools/other/gen_vx_mask/gen_vx_mask.cc index 3a706a112..ffa7b121c 100644 --- a/src/tools/other/gen_vx_mask/gen_vx_mask.cc +++ b/src/tools/other/gen_vx_mask/gen_vx_mask.cc @@ -501,8 +501,9 @@ static bool get_gen_vx_mask_config_str(MetNcMetDataFile *mnmdf_ptr, // Read the first non-lat/lon variable config_str << cs_erase - << "'name=\"" << mnmdf_ptr->MetNc->Var[i].name - << "\"; level=\"(*,*)\";'"; + << R"('name=")" + << mnmdf_ptr->MetNc->Var[i].name + << R"_("; level="(*,*)";')_"; status = true; break; } @@ -512,7 +513,7 @@ static bool get_gen_vx_mask_config_str(MetNcMetDataFile *mnmdf_ptr, //////////////////////////////////////////////////////////////////////// -void get_shapefile_strings() { +static void get_shapefile_strings() { DbfFile f; StringArray rec_names; StringArray rec_values; @@ -543,13 +544,10 @@ void get_shapefile_strings() { << ").\n"; // Check that the attributes requested actually exist - map::const_iterator it; - for(it = shape_str_map.begin(); - it != shape_str_map.end(); it++) { - - if(!rec_names.has(it->first)) { + for(const auto& pair: shape_str_map) { + if(!rec_names.has(pair.first)) { mlog << Warning << "\nget_shapefile_strings() -> " - << "the \"-shape_str\" name \"" << it->first + << "the \"-shape_str\" name \"" << pair.first << "\" is not in the list of " << rec_names.n() << " shapefile attributes and will be ignored:\n" << write_css(rec_names) << "\n\n"; @@ -676,7 +674,7 @@ bool is_shape_str_match(const int i_shape, const StringArray &names, const Strin //////////////////////////////////////////////////////////////////////// -void apply_poly_mask(DataPlane & dp) { +static void apply_poly_mask(DataPlane & dp) { int n_in = 0; bool inside; double lat; @@ -721,10 +719,11 @@ void apply_poly_mask(DataPlane & dp) { //////////////////////////////////////////////////////////////////////// -void apply_poly_xy_mask(DataPlane & dp) { +static void apply_poly_xy_mask(DataPlane & dp) { int n_in = 0; bool inside; - double x_dbl, y_dbl; + double x_dbl; + double y_dbl; GridClosedPoly poly_xy; // Convert MaskPoly Lat/Lon coordinates to Grid X/Y @@ -769,15 +768,15 @@ void apply_poly_xy_mask(DataPlane & dp) { //////////////////////////////////////////////////////////////////////// -void apply_box_mask(DataPlane &dp) { - int i, x_ll, y_ll, x, y, n_in; - double cen_x, cen_y; - bool inside; +static void apply_box_mask(DataPlane &dp) { + int n_in = 0; + double cen_x; + double cen_y; // Process the height and width if(is_bad_data(height) && is_bad_data(width)) { mlog << Error << "\napply_box_mask() -> " - << "the \"-height\" and/or \"-width\" options must be " + << R"(the "-height" and/or "-width" options must be )" << "specified in grid units for box masking.\n\n"; exit(1); } @@ -789,19 +788,21 @@ void apply_box_mask(DataPlane &dp) { } // Process each lat/lon point - for(i=0; i= dp.nx()) continue; - for(y=y_ll; y= dp.ny()) continue; // Set the mask @@ -812,16 +813,16 @@ void apply_box_mask(DataPlane &dp) { } // end for i // Loop through the field, handle the complement, and count up points - for(x=0,n_in=0; x= 0 && mask_x < grid_mask.nx() && - mask_y >= 0 && mask_y < grid_mask.ny()); + bool inside = (mask_x >= 0 && mask_x < grid_mask.nx() && + mask_y >= 0 && mask_y < grid_mask.ny()); // Apply the complement if(complement) inside = !inside; // Increment count - n_in += inside; + if(inside) n_in++; // Store the current mask value dp.set(inside, x, y); @@ -1064,17 +1067,18 @@ void apply_grid_mask(DataPlane &dp) { //////////////////////////////////////////////////////////////////////// -void apply_data_mask(DataPlane &dp) { +static void apply_data_mask(DataPlane &dp) { int n_in = 0; - bool check; // Nothing to do without a threshold if(thresh.get_type() == thresh_na) { mlog << Debug(3) << "Write the raw inputs values for " << masktype_to_description(mask_type) - << " masking since no \"-thresh\" specified.\n"; - double dmin, dmax; + << R"( masking since no "-thresh" specified.)" + << "\n"; + double dmin; + double dmax; dp.data_range(dmin, dmax); mlog << Debug(3) << masktype_to_description(mask_type) @@ -1100,13 +1104,13 @@ void apply_data_mask(DataPlane &dp) { for(int y=0; y poly_list; - vector::const_iterator rec_it; - for(rec_it = shape_recs.begin(); - rec_it != shape_recs.end(); ++rec_it) { - poly.set(*rec_it, grid); + for(const auto& rec: shape_recs) { + poly.set(rec, grid); poly_list.push_back(poly); } @@ -1293,12 +1305,10 @@ void apply_shape_mask(DataPlane & dp) { for(int x=0; x<(grid.nx()); x++) { for(int y=0; y<(grid.ny()); y++) { - vector::const_iterator poly_it; - for(poly_it = poly_list.begin(); - poly_it != poly_list.end(); ++poly_it) { + for(const auto& poly: poly_list) { // Check if point is inside - status = poly_it->is_inside(x, y); + status = poly.is_inside(x, y); // Break after the first match if(status) break; @@ -1333,10 +1343,10 @@ void apply_shape_mask(DataPlane & dp) { //////////////////////////////////////////////////////////////////////// -DataPlane combine(const DataPlane &dp_data, const DataPlane &dp_mask, - SetLogic logic) { +static DataPlane combine(const DataPlane &dp_data, + const DataPlane &dp_mask, + SetLogic logic) { int n_in = 0; - bool v_data, v_mask; double v; DataPlane dp; @@ -1363,8 +1373,8 @@ DataPlane combine(const DataPlane &dp_data, const DataPlane &dp_mask, for(int y=0; y " << "the -type command line requirement can only be used once!\n" @@ -1745,79 +1755,79 @@ void set_type(const StringArray & a) { //////////////////////////////////////////////////////////////////////// -void set_input_field(const StringArray & a) { +static void set_input_field(const StringArray & a) { input_field_str = a[0]; } //////////////////////////////////////////////////////////////////////// -void set_mask_field(const StringArray & a) { +static void set_mask_field(const StringArray & a) { mask_field_str = a[0]; } //////////////////////////////////////////////////////////////////////// -void set_complement(const StringArray & a) { +static void set_complement(const StringArray &) { complement = true; } //////////////////////////////////////////////////////////////////////// -void set_union(const StringArray & a) { +static void set_union(const StringArray &) { set_logic = SetLogic::Union; } //////////////////////////////////////////////////////////////////////// -void set_intersection(const StringArray & a) { +static void set_intersection(const StringArray &) { set_logic = SetLogic::Intersection; } //////////////////////////////////////////////////////////////////////// -void set_symdiff(const StringArray & a) { +static void set_symdiff(const StringArray &) { set_logic = SetLogic::SymDiff; } //////////////////////////////////////////////////////////////////////// -void set_thresh(const StringArray & a) { +static void set_thresh(const StringArray & a) { thresh.set(a[0].c_str()); } //////////////////////////////////////////////////////////////////////// -void set_height(const StringArray & a) { +static void set_height(const StringArray & a) { height = atoi(a[0].c_str()); } //////////////////////////////////////////////////////////////////////// -void set_width(const StringArray & a) { +static void set_width(const StringArray & a) { width = atoi(a[0].c_str()); } //////////////////////////////////////////////////////////////////////// -void set_value(const StringArray & a) { +static void set_value(const StringArray & a) { mask_val = atof(a[0].c_str()); } //////////////////////////////////////////////////////////////////////// -void set_name(const StringArray & a) { +static void set_name(const StringArray & a) { mask_name = a[0]; } //////////////////////////////////////////////////////////////////////// -void set_compress(const StringArray & a) { +static void set_compress(const StringArray & a) { compress_level = atoi(a[0].c_str()); } //////////////////////////////////////////////////////////////////////// -void set_shapeno(const StringArray & a) { +static void set_shapeno(const StringArray & a) { NumArray cur_na; cur_na.add_css(a[0].c_str()); @@ -1839,7 +1849,7 @@ void set_shapeno(const StringArray & a) { //////////////////////////////////////////////////////////////////////// -void set_shape_str(const StringArray & a) { +static void set_shape_str(const StringArray & a) { StringArray sa; // Comma-separated list of matching strings, ignoring case