From f051fac88e9e5e2632d2c9ef38de8fa8a3315fc3 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Mon, 16 Oct 2023 17:53:03 -0600 Subject: [PATCH 1/9] #2687 Saved the PBL input into the vector --- src/tools/other/pb2nc/pb2nc.cc | 114 ++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/src/tools/other/pb2nc/pb2nc.cc b/src/tools/other/pb2nc/pb2nc.cc index 92fdc288df..c42fc1bdc7 100644 --- a/src/tools/other/pb2nc/pb2nc.cc +++ b/src/tools/other/pb2nc/pb2nc.cc @@ -372,8 +372,8 @@ static bool keep_level_category(int); static float derive_grib_code(int, float *, float *, double, float&); -static int combine_tqz_and_uv(map, - map, map &); +static int combine_tqz_and_uv(map, map, + vector &); static float compute_pbl(map pqtzuv_map_tq, map pqtzuv_map_uv); static void copy_pqtzuv(float *to_pqtzuv, float *from_pqtzuv, bool copy_all=true); @@ -2959,14 +2959,16 @@ void copy_pqtzuv(float *to_pqtzuv, float *from_pqtzuv, bool copy_all) { //////////////////////////////////////////////////////////////////////// int combine_tqz_and_uv(map pqtzuv_map_tq, - map pqtzuv_map_uv, map &pqtzuv_map_merged) { + map pqtzuv_map_uv, vector &pqtzuv_merged_array) { static const char *method_name = "combine_tqz_and_uv() "; int tq_count = pqtzuv_map_tq.size(); int uv_count = pqtzuv_map_uv.size(); + map pqtzuv_map_merged; + pqtzuv_merged_array.clear(); if (tq_count > 0 && uv_count > 0) { IntArray common_levels, tq_levels; float *pqtzuv_tq, *pqtzuv_uv; - float *pqtzuv_merged = (float *) 0; + float *pqtzuv_merged = (float *) nullptr; float *next_pqtzuv, *prev_pqtzuv; float tq_pres_max, tq_pres_min, uv_pres_max, uv_pres_min; map::iterator it, it_tq, it_uv; @@ -3055,9 +3057,10 @@ int combine_tqz_and_uv(map pqtzuv_map_tq, } interpolate_pqtzuv(prev_pqtzuv, pqtzuv_merged, next_pqtzuv); } - float first_pres = (pqtzuv_merged[0] == 0 ? bad_data_float : pqtzuv_merged[0]); + float first_pres = (pqtzuv_merged[0] < 0 || is_eq(pqtzuv_merged[0], 0.) + ? bad_data_float : pqtzuv_merged[0]); pqtzuv_map_merged[first_pres] = pqtzuv_merged; - mlog << Debug(9) << method_name << "Added " << first_pres << " to merged records\n"; + mlog << Debug(9) << method_name << "Added " << first_pres << " to merged records (first record)\n"; if (pqtzuv_merged != 0) { //Merge UV into TQZ records @@ -3065,6 +3068,12 @@ int combine_tqz_and_uv(map pqtzuv_map_tq, //Merge TQZ into UV records merge_records(pqtzuv_merged, pqtzuv_map_uv, pqtzuv_map_tq, pqtzuv_map_merged); } + for (map::iterator it=pqtzuv_map_merged.begin(); + it!=pqtzuv_map_merged.end(); ++it) { + float *new_pqtzuv = new float[mxr8vt]; + for (int i=0; isecond[i]; + pqtzuv_merged_array.push_back(new_pqtzuv); + } if(mlog.verbosity_level() >= PBL_DEBUG_LEVEL) { log_merged_tqz_uv(pqtzuv_map_tq, pqtzuv_map_uv, pqtzuv_map_merged, method_name); @@ -3072,7 +3081,7 @@ int combine_tqz_and_uv(map pqtzuv_map_tq, delete [] pqtzuv_merged; } - return pqtzuv_map_merged.size(); + return pqtzuv_merged_array.size(); } //////////////////////////////////////////////////////////////////////// @@ -3093,12 +3102,13 @@ float compute_pbl(map pqtzuv_map_tq, mlog << Debug(7) << method_name << "is called: TQZ: " << tq_count << " UV: " << uv_count << "\n"; if (tq_count > 0 || uv_count > 0) { + float *pqtzuv = nullptr; int hgt_cnt, spfh_cnt; IntArray selected_levels; - map pqtzuv_map_merged; + vector pqtzuv_merged_array; pbl_level = combine_tqz_and_uv(pqtzuv_map_tq, pqtzuv_map_uv, - pqtzuv_map_merged); + pqtzuv_merged_array); mlog << Debug(7) << method_name << "pbl_level= " << pbl_level << " from TQ (" << tq_count << ") and UV (" << uv_count << ")\n"; @@ -3112,60 +3122,62 @@ float compute_pbl(map pqtzuv_map_tq, << "Skip CALPBL because of only one available record after combining TQZ and UV\n"; } else { - // Order all observations by pressure from bottom to top - index = pbl_level - 1; + // Reverse the order all observations by pressure from bottom to top + index = 0; hgt_cnt = spfh_cnt = 0; - for (it=pqtzuv_map_merged.begin(); it!=pqtzuv_map_merged.end(); ++it) { - if (index < 0) { - mlog << Error << "\n" << method_name << "negative index: " << index << "\n\n"; - break; - } - - if (index < MAX_PBL_LEVEL) { - float *pqtzuv = it->second; - pbl_data_pres[index] = pqtzuv[0]; - pbl_data_spfh[index] = pqtzuv[1]; - pbl_data_temp[index] = pqtzuv[2]; - pbl_data_hgt[index] = pqtzuv[3]; - pbl_data_ugrd[index] = pqtzuv[4]; - pbl_data_vgrd[index] = pqtzuv[5]; - if (is_valid_pb_data(pbl_data_spfh[index])) spfh_cnt++; - if (is_valid_pb_data(pbl_data_hgt[index])) hgt_cnt++; - selected_levels.add(nint(it->first)); - } - - index--; - } - if (index != -1) { - mlog << Error << "\n" << method_name << "Missing some levels (" << index << ")\n"; - } - - if (pbl_level > MAX_PBL_LEVEL) { - it = pqtzuv_map_tq.begin(); + int start_offset = (MAX_PBL_LEVEL >= pbl_level) ? 0 : (pbl_level-MAX_PBL_LEVEL); + for (int i=(pbl_level-1); i>=start_offset; i--,index++) { + pqtzuv = pqtzuv_merged_array[i]; + pbl_data_pres[index] = pqtzuv[0]; + pbl_data_pres[index] = pqtzuv[0]; + pbl_data_spfh[index] = pqtzuv[1]; + pbl_data_temp[index] = pqtzuv[2]; + pbl_data_hgt[index] = pqtzuv[3]; + pbl_data_ugrd[index] = pqtzuv[4]; + pbl_data_vgrd[index] = pqtzuv[5]; + if (is_valid_pb_data(pbl_data_spfh[index])) spfh_cnt++; + if (is_valid_pb_data(pbl_data_hgt[index])) hgt_cnt++; + selected_levels.add(nint(pqtzuv[0])); + } + if (start_offset > 0) { + // Replace the interpolated records with common records. + mlog << Error << "\n" << method_name << "Excluded " << start_offset << " records\n"; // Find vertical levels with both data float highest_pressure = bad_data_float; - for (; it!=pqtzuv_map_tq.end(); ++it) { + for (it = pqtzuv_map_tq.begin(); it!=pqtzuv_map_tq.end(); ++it) { if (pqtzuv_map_uv.count(it->first) > 0) { highest_pressure = it->first; break; } } if (!is_bad_data(highest_pressure)) { + bool found; + int vector_idx = start_offset - 1; index = MAX_PBL_LEVEL - 1; for (; it!=pqtzuv_map_tq.end(); ++it) { int pres_level = nint(it->first); + // Stop replacing if already exists at input list if (selected_levels.has(pres_level)) break; - float *pqtzuv = pqtzuv_map_merged[it->first]; - pbl_data_pres[index] = pqtzuv[0]; - pbl_data_spfh[index] = pqtzuv[1]; - pbl_data_temp[index] = pqtzuv[2]; - pbl_data_hgt[index] = pqtzuv[3]; - pbl_data_ugrd[index] = pqtzuv[4]; - pbl_data_vgrd[index] = pqtzuv[5]; - mlog << Debug(6) << method_name << "Force to add " - << pres_level << " into " << index << "\n"; - index--; + found = false; + for (; vector_idx>=0; vector_idx--) { + if (is_eq(pqtzuv_merged_array[vector_idx][0], it->first)) { + pqtzuv = pqtzuv_merged_array[vector_idx]; + pbl_data_pres[index] = pqtzuv[0]; + pbl_data_spfh[index] = pqtzuv[1]; + pbl_data_temp[index] = pqtzuv[2]; + pbl_data_hgt[index] = pqtzuv[3]; + pbl_data_ugrd[index] = pqtzuv[4]; + pbl_data_vgrd[index] = pqtzuv[5]; + mlog << Debug(6) << method_name << "Force to add " + << pres_level << " into " << index << "\n"; + vector_idx--; + found = true; + break; + } + } + if (vector_idx < 0) break; + if(found) index--; } } } @@ -3205,9 +3217,11 @@ float compute_pbl(map pqtzuv_map_tq, if (!is_valid_pb_data(hpbl)) mlog << Debug(5) << method_name << " fail to compute PBL. TQ records: " << tq_count << " UV records: " << uv_count << " merged records: " - << pqtzuv_map_merged.size() << "\n"; + << pqtzuv_merged_array.size() << "\n"; } } + for (int i; i Date: Thu, 19 Oct 2023 10:17:16 -0600 Subject: [PATCH 2/9] #2673 Moved a code block under else for SonarQube scanning --- scripts/python/met/dataplane.py | 49 +++++++++++++++++---------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/scripts/python/met/dataplane.py b/scripts/python/met/dataplane.py index e11fc31d50..57c9ac367b 100644 --- a/scripts/python/met/dataplane.py +++ b/scripts/python/met/dataplane.py @@ -180,32 +180,33 @@ def validate_met_data(met_data, fill_value=None): from_ndarray = False if met_data is None: logger.quit(f"{method_name} The met_data is None") - - nx, ny = met_data.shape - met_fill_value = dataplane.MET_FILL_VALUE - if dataplane.is_xarray_dataarray(met_data): - from_xarray = True - attrs = met_data.attrs - met_data = met_data.data - modified_met_data = True - if isinstance(met_data, np.ndarray): - from_ndarray = True - met_data = np.ma.array(met_data) - - if isinstance(met_data, np.ma.MaskedArray): - is_int_data = dataplane.is_integer(met_data[0,0]) or dataplane.is_integer(met_data[int(nx/2),int(ny/2)]) - met_data = np.ma.masked_equal(met_data, float('nan')) - met_data = np.ma.masked_equal(met_data, float('inf')) - if fill_value is not None: - met_data = np.ma.masked_equal(met_data, fill_value) - met_data = met_data.filled(int(met_fill_value) if is_int_data else met_fill_value) else: - logger.log_msg(f"{method_name} unknown datatype {type(met_data)}") + nx, ny = met_data.shape + + met_fill_value = dataplane.MET_FILL_VALUE + if dataplane.is_xarray_dataarray(met_data): + from_xarray = True + attrs = met_data.attrs + met_data = met_data.data + modified_met_data = True + if isinstance(met_data, np.ndarray): + from_ndarray = True + met_data = np.ma.array(met_data) + + if isinstance(met_data, np.ma.MaskedArray): + is_int_data = dataplane.is_integer(met_data[0,0]) or dataplane.is_integer(met_data[int(nx/2),int(ny/2)]) + met_data = np.ma.masked_equal(met_data, float('nan')) + met_data = np.ma.masked_equal(met_data, float('inf')) + if fill_value is not None: + met_data = np.ma.masked_equal(met_data, fill_value) + met_data = met_data.filled(int(met_fill_value) if is_int_data else met_fill_value) + else: + logger.log_msg(f"{method_name} unknown datatype {type(met_data)}") - if dataplane.KEEP_XARRAY: - return xr.DataArray(met_data,attrs=attrs) if from_xarray else met_data - else: - return met_data + if dataplane.KEEP_XARRAY: + return xr.DataArray(met_data,attrs=attrs) if from_xarray else met_data + else: + return met_data def main(argv): From 723bff8cec9a5ab3213927cd574087fa1422a299 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 19 Oct 2023 10:18:42 -0600 Subject: [PATCH 3/9] #2673 Deleted a break statement which will never be executed --- src/basic/vx_util/ascii_table.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/basic/vx_util/ascii_table.cc b/src/basic/vx_util/ascii_table.cc index 9d1911f1de..326d53b978 100644 --- a/src/basic/vx_util/ascii_table.cc +++ b/src/basic/vx_util/ascii_table.cc @@ -1567,7 +1567,6 @@ switch ( just ) { default: mlog << Error << "\njustified_item() -> bad justification value\n\n"; exit ( 1 ); - break; } // switch From 65e2fef24c46c2912d274d27567a6b2a2e8b1aad Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 19 Oct 2023 11:06:15 -0600 Subject: [PATCH 4/9] #2673 Catch exception by reference (SonarQubue) --- src/libcode/vx_nc_util/nc_utils.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libcode/vx_nc_util/nc_utils.cc b/src/libcode/vx_nc_util/nc_utils.cc index 6350b6576a..b319fbabe9 100644 --- a/src/libcode/vx_nc_util/nc_utils.cc +++ b/src/libcode/vx_nc_util/nc_utils.cc @@ -8,21 +8,21 @@ //////////////////////////////////////////////////////////////////////// -using namespace std; - #include #include #include #include -using namespace netCDF; -using namespace netCDF::exceptions; #include "vx_log.h" #include "nc_utils.h" #include "util_constants.h" #include "vx_cal.h" +using namespace std; +using namespace netCDF; +using namespace netCDF::exceptions; + //////////////////////////////////////////////////////////////////////// void patch_nc_name(string *var_name) { @@ -172,7 +172,7 @@ bool get_att_value_chars(const NcAtt *att, ConcatString &value) { att->getValues(att_value); value = att_value; } - catch (exceptions::NcChar ex) { + catch (exceptions::NcChar &ex) { value = ""; // Handle netCDF::exceptions::NcChar: NetCDF: Attempt to convert between text & numbers mlog << Warning << "\n" << method_name @@ -188,7 +188,7 @@ bool get_att_value_chars(const NcAtt *att, ConcatString &value) { att->getValues(att_value); value = att_value; } - catch (exceptions::NcChar ex) { + catch (exceptions::NcChar &ex) { int num_elements_sub = 8096; int num_elements = att->getAttLength();; char *att_value[num_elements]; @@ -199,7 +199,7 @@ bool get_att_value_chars(const NcAtt *att, ConcatString &value) { att->getValues(att_value); value = att_value[0]; } - catch (exceptions::NcException ex) { + catch (exceptions::NcException &ex) { mlog << Warning << "\n" << method_name << "Exception: " << ex.what() << "\n" << "Fail to read " << GET_NC_NAME_P(att) << " attribute (" From 306b08884d44fe846f0de0c8f744bb95ae49bb0b Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 19 Oct 2023 11:07:49 -0600 Subject: [PATCH 5/9] #2673 Move down using statements below include directive. Changed 0 to nullptr (SonarQubue) --- src/tools/core/pcp_combine/pcp_combine.cc | 55 ++++++++++++----------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/tools/core/pcp_combine/pcp_combine.cc b/src/tools/core/pcp_combine/pcp_combine.cc index 0efcb42ac9..0e364d08cc 100644 --- a/src/tools/core/pcp_combine/pcp_combine.cc +++ b/src/tools/core/pcp_combine/pcp_combine.cc @@ -80,8 +80,6 @@ // //////////////////////////////////////////////////////////////////////// -using namespace std; - #include #include #include @@ -94,7 +92,6 @@ using namespace std; #include #include -using namespace netCDF; #include "main.h" #include "vx_log.h" @@ -107,6 +104,9 @@ using namespace netCDF; #include "vx_cal.h" #include "vx_math.h" +using namespace std; +using namespace netCDF; + //////////////////////////////////////////////////////////////////////// static ConcatString program_name; @@ -133,7 +133,7 @@ static StringArray req_out_var_name; static int i_out_var = 0; static int n_out_var; static MetConfig config; -static VarInfo * var_info = (VarInfo *) 0; +static VarInfo * var_info = (VarInfo *) nullptr; static double vld_thresh = 1.0; static int compress_level = -1; @@ -151,7 +151,7 @@ static StringArray field_list; static StringArray derive_list; // Output NetCDF file -NcFile *nc_out = (NcFile *) 0; +NcFile *nc_out = (NcFile *) nullptr; NcDim lat_dim; NcDim lon_dim; @@ -217,7 +217,7 @@ int met_main(int argc, char *argv[]) { // Reinitialize for the current loop. // field_string = req_field_list[i]; - if(var_info) { delete var_info; var_info = (VarInfo *) 0; } + if(var_info) { delete var_info; var_info = (VarInfo *) nullptr; } // // Reset when reading multiple fields from the same input files. @@ -241,7 +241,7 @@ int met_main(int argc, char *argv[]) { // close_nc(); - return(0); + return 0; } //////////////////////////////////////////////////////////////////////// @@ -561,9 +561,9 @@ void sum_data_files(Grid & grid, DataPlane & plane) { DataPlane part; double v_sum, v_part; Grid cur_grid; - unixtime * pcp_times = (unixtime *) 0; - int * pcp_recs = (int *) 0; - ConcatString * pcp_files = (ConcatString *) 0; + unixtime * pcp_times = (unixtime *) nullptr; + int * pcp_recs = (int *) nullptr; + ConcatString * pcp_files = (ConcatString *) nullptr; // // Compute the number of forecast precipitation files to be found, @@ -596,6 +596,7 @@ void sum_data_files(Grid & grid, DataPlane & plane) { // // Search in each directory for the current file time. // + if (0 == pcp_dir.n_elements()) pcp_recs[i] = -1; for(j=0; jd_name; Met2dDataFileFactory factory; - Met2dDataFile * mtddf = (Met2dDataFile *) 0; + Met2dDataFile * mtddf = (Met2dDataFile *) nullptr; VarInfoFactory var_fac; - VarInfo * cur_var = (VarInfo *) 0; + VarInfo * cur_var = (VarInfo *) nullptr; // // Create a data file object. @@ -767,7 +768,7 @@ int search_pcp_dir(const char *cur_dir, const unixtime cur_ut, // cur_var = var_fac.new_var_info(mtddf->file_type()); if(!cur_var) { - delete mtddf; mtddf = 0; + delete mtddf; mtddf = nullptr; mlog << Warning << "search_pcp_dir() -> " << "unable to determine filetype of \"" << cur_file << "\"\n"; @@ -796,8 +797,8 @@ int search_pcp_dir(const char *cur_dir, const unixtime cur_ut, // // Cleanup. // - if(mtddf) { delete mtddf; mtddf = (Met2dDataFile *) 0; } - if(cur_var) { delete cur_var; cur_var = (VarInfo *) 0; } + if(mtddf) { delete mtddf; mtddf = (Met2dDataFile *) nullptr; } + if(cur_var) { delete cur_var; cur_var = (VarInfo *) nullptr; } // check for a valid match if( -1 != i_rec ) { met_closedir(dp); break; } @@ -1168,7 +1169,7 @@ void get_field(const char *filename, const char *cur_field, const unixtime get_init_ut, const unixtime get_valid_ut, Grid & grid, DataPlane & plane) { Met2dDataFileFactory factory; - Met2dDataFile *mtddf = (Met2dDataFile *) 0; + Met2dDataFile *mtddf = (Met2dDataFile *) nullptr; GrdFileType ftype; VarInfoFactory var_fac; VarInfo *cur_var; @@ -1244,10 +1245,10 @@ void get_field(const char *filename, const char *cur_field, // // Cleanup. // - if(mtddf) { delete mtddf; mtddf = (Met2dDataFile *) 0; } - if(cur_var) { delete cur_var; cur_var = (VarInfo *) 0; } + if(mtddf) { delete mtddf; mtddf = (Met2dDataFile *) nullptr; } + if(cur_var) { delete cur_var; cur_var = (VarInfo *) nullptr; } - // if ( var ) { delete var; var = 0; } + // if ( var ) { delete var; var = nullptr; } return; @@ -1270,7 +1271,7 @@ void open_nc(const Grid &grid) { << "trouble opening output file " << out_filename << "\n\n"; delete nc_out; - nc_out = (NcFile *) 0; + nc_out = (NcFile *) nullptr; exit(1); } @@ -1452,8 +1453,8 @@ void close_nc() { // // Clean up. // - if(nc_out) { delete nc_out; nc_out = (NcFile *) 0; } - if(var_info ) { delete var_info; var_info = (VarInfo *) 0; } + if(nc_out) { delete nc_out; nc_out = (NcFile *) nullptr; } + if(var_info ) { delete var_info; var_info = (VarInfo *) nullptr; } return; } From 80fdc796c92d7b2ba1db77d5b42b89edcd8434d6 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 19 Oct 2023 11:08:14 -0600 Subject: [PATCH 6/9] #2673 Move down using statements below include directive. Changed 0 to nullptr (SonarQubue) --- src/tools/other/mode_time_domain/3d_conv.cc | 109 ++++++++++---------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/src/tools/other/mode_time_domain/3d_conv.cc b/src/tools/other/mode_time_domain/3d_conv.cc index 0dd0172f22..c2eeeddcfb 100644 --- a/src/tools/other/mode_time_domain/3d_conv.cc +++ b/src/tools/other/mode_time_domain/3d_conv.cc @@ -18,8 +18,6 @@ static const bool do_ppms = false; //////////////////////////////////////////////////////////////////////// -using namespace std; - #include #include #include @@ -29,7 +27,6 @@ using namespace std; #include #include -using namespace netCDF; #include "vx_cal.h" #include "vx_util.h" @@ -38,14 +35,17 @@ using namespace netCDF; #include "mtd_file.h" #include "mtd_nc_defs.h" +using namespace std; +using namespace netCDF; + //////////////////////////////////////////////////////////////////////// static int spatial_conv_radius = -1; -static double * sum_plane_buf = 0; -static bool * ok_sum_plane_buf = 0; +static double * sum_plane_buf = nullptr; +static bool * ok_sum_plane_buf = nullptr; //////////////////////////////////////////////////////////////////////// @@ -66,11 +66,11 @@ struct DataHandle { { - int j, k; + int k; k = 0; - for (j=0; j0) { + value /= n_good; - value *= scale; + value *= scale; - if ( value < min_conv_value ) min_conv_value = value; - if ( value > max_conv_value ) max_conv_value = value; + if ( value < min_conv_value ) min_conv_value = value; + if ( value > max_conv_value ) max_conv_value = value; + } } @@ -429,10 +432,10 @@ for (x=0; x Date: Thu, 19 Oct 2023 11:09:38 -0600 Subject: [PATCH 7/9] #2673 Added std namespace for vector (SonarQubue) --- src/tools/other/mode_time_domain/mtd_file_base.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/other/mode_time_domain/mtd_file_base.h b/src/tools/other/mode_time_domain/mtd_file_base.h index 82f7d40509..659dc784a1 100644 --- a/src/tools/other/mode_time_domain/mtd_file_base.h +++ b/src/tools/other/mode_time_domain/mtd_file_base.h @@ -88,7 +88,7 @@ class MtdFileBase { int DeltaT; // seconds, useful for constant time increments - vector ActualValidTimes; // useful for uneven time increments + std::vector ActualValidTimes; // useful for uneven time increments IntArray Lead_Times; @@ -117,7 +117,7 @@ class MtdFileBase { void set_delta_t (int); // seconds - void init_actual_valid_times(const vector &validTimes); + void init_actual_valid_times(const std::vector &validTimes); void set_lead_time(int index, int value); From 9738e587672514aa9f4cd2a4968e2526ea219904 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 19 Oct 2023 11:10:13 -0600 Subject: [PATCH 8/9] #2673 Changed 0 to nullptr (SonarQubue) --- .../other/mode_time_domain/mtd_file_float.cc | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/tools/other/mode_time_domain/mtd_file_float.cc b/src/tools/other/mode_time_domain/mtd_file_float.cc index f0c70f509f..dd407c5061 100644 --- a/src/tools/other/mode_time_domain/mtd_file_float.cc +++ b/src/tools/other/mode_time_domain/mtd_file_float.cc @@ -101,7 +101,7 @@ void MtdFloatFile::float_init_from_scratch() { -Data = 0; +Data = nullptr; clear(); @@ -119,7 +119,7 @@ void MtdFloatFile::clear() MtdFileBase::clear(); -if ( Data ) { delete [] Data; Data = 0; } +if ( Data ) { delete [] Data; Data = nullptr; } DataMin = DataMax = 0; @@ -218,7 +218,7 @@ void MtdFloatFile::set_size(int _nx, int _ny, int _nt) { -if ( Data ) { delete [] Data; Data = 0; } +if ( Data ) { delete [] Data; Data = nullptr; } int j; const int n3 = _nx*_ny*_nt; @@ -1011,18 +1011,6 @@ for (x=0; x Date: Thu, 19 Oct 2023 11:12:19 -0600 Subject: [PATCH 9/9] #2673 Changed a double pointer to vector (SonarQubue) --- src/libcode/vx_statistics/compute_stats.cc | 76 ++++++++++++---------- src/libcode/vx_statistics/compute_stats.h | 5 +- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/libcode/vx_statistics/compute_stats.cc b/src/libcode/vx_statistics/compute_stats.cc index 6a66c316b0..fc8a3fbdd2 100644 --- a/src/libcode/vx_statistics/compute_stats.cc +++ b/src/libcode/vx_statistics/compute_stats.cc @@ -1449,7 +1449,7 @@ void compute_aggregated_seeps(const PairDataPoint *pd, SeepsAggScore *seeps) { seeps_mprs.push_back(seeps_mpr); } if (count > 0) { - double *density_vector; + vector density_vector; double pvf[SEEPS_MATRIX_SIZE]; double weighted_score, weight_sum, weight[count]; @@ -1457,41 +1457,47 @@ void compute_aggregated_seeps(const PairDataPoint *pd, SeepsAggScore *seeps) { seeps->mean_fcst = fcst_sum / count; seeps->mean_obs = obs_sum / count; seeps->score = score_sum / count; - density_vector = compute_seeps_density_vector(pd, seeps); weighted_score = 0.; for (int i=0; iscore * weight[i]; - //IDL: svf(cat{i)) = svf(cat{i)) + c(4+cat(i) * w{i) - //IDL: pvf(cat{i)) = pvf(cat{i)) + w{i) - pvf[seeps_mpr->s_idx] += weight[i]; - } - else mlog << Debug(1) << method_name - << "the length of density vector (" << count << ") is less than MPR.\n"; + } + if (!is_eq(weight_sum, 0)) { + //IDL: w = w/sum(w) + for (int i=0; iscore * weight[i]; + //IDL: svf(cat{i)) = svf(cat{i)) + c(4+cat(i) * w{i) + //IDL: pvf(cat{i)) = pvf(cat{i)) + w{i) + pvf[seeps_mpr->s_idx] += weight[i]; + } + else { + mlog << Debug(1) << method_name + << "the length of density vector (" << density_cnt + << ") is less than SEEPS MPR (" << seeps_mprs.size() << ").\n"; + break; } } - - if (density_vector != nullptr) delete [] density_vector; } + + density_vector.clear(); + seeps_mprs.clear(); // The weight for s12 to s32 should come from climo file, but not available yet @@ -1707,7 +1713,7 @@ void compute_aggregated_seeps_grid(const DataPlane &fcst_dp, const DataPlane &ob // ; PV-WAVE prints: 2.00000 4.00000 //////////////////////////////////////////////////////////////////////// -double *compute_seeps_density_vector(const PairDataPoint *pd, SeepsAggScore *seeps) { +void compute_seeps_density_vector(const PairDataPoint *pd, SeepsAggScore *seeps, vector &density_vector) { int seeps_idx; SeepsScore *seeps_mpr; int seeps_cnt = seeps->n_obs; @@ -1725,12 +1731,11 @@ double *compute_seeps_density_vector(const PairDataPoint *pd, SeepsAggScore *see if (seeps_cnt == 0) { mlog << Debug(1) << method_name << "no SEEPS_MPR available.\n"; - return nullptr; + return; } // Get lat/lon & convert them to radian and get sin/cos values seeps_idx = 0; - double *density_vector = new double[seeps_cnt]; for(int i=0; in_obs; i++) { if (i >= pd->seeps_mpr.size()) break; seeps_mpr = pd->seeps_mpr[i]; @@ -1752,10 +1757,9 @@ double *compute_seeps_density_vector(const PairDataPoint *pd, SeepsAggScore *see // Initialize v_count = 0; if (seeps_idx < seeps_cnt) seeps_cnt = seeps_idx; - for(int i=0; i &density_vector); //////////////////////////////////////////////////////////////////////// //