From b6360c5298e3cb99cc004473bfa830dc1af8776d Mon Sep 17 00:00:00 2001 From: MET Tools Test Account Date: Fri, 13 Dec 2024 23:37:11 +0000 Subject: [PATCH] Per #2709, updates to fix SonarQube code smells. --- src/libcode/vx_shapedata/mode_conf_info.cc | 127 ++++---- src/tools/core/mode/mode_exec.cc | 322 +++++++++++---------- src/tools/core/mode/mode_exec.h | 17 +- src/tools/core/mode/mode_superobject.cc | 21 +- src/tools/core/mode/mode_superobject.h | 3 +- src/tools/core/mode/multivar_frontend.cc | 72 ++--- src/tools/core/mode/multivar_frontend.h | 11 +- src/tools/core/mode/simple_objects.cc | 6 +- src/tools/core/mode/simple_objects.hh | 2 - 9 files changed, 282 insertions(+), 299 deletions(-) diff --git a/src/libcode/vx_shapedata/mode_conf_info.cc b/src/libcode/vx_shapedata/mode_conf_info.cc index 097d2c898..410d47174 100644 --- a/src/libcode/vx_shapedata/mode_conf_info.cc +++ b/src/libcode/vx_shapedata/mode_conf_info.cc @@ -74,11 +74,11 @@ void ModeConfInfo::init_from_scratch() Field_Index_f = 0; Field_Index_o = 0; - fcst_array = 0; - obs_array = 0; + fcst_array = nullptr; + obs_array = nullptr; - fcst_array = 0; - obs_array = 0; + fcst_array = nullptr; + obs_array = nullptr; clear(); @@ -115,8 +115,8 @@ void ModeConfInfo::assign( const ModeConfInfo &m) complexity_ratio_wt = m.complexity_ratio_wt; inten_perc_ratio_wt = m.inten_perc_ratio_wt; - fcst_array = 0; - Fcst = 0; + fcst_array = nullptr; + Fcst = nullptr; if (N_fields_f > 0) { fcst_array = new Mode_Field_Info[N_fields_f]; for (int i=0; i 0) { obs_array = new Mode_Field_Info[N_fields_o]; for (int i=0; ilookup_int(conf_key_shift_right); if (field_index == 0) { @@ -643,11 +634,8 @@ void ModeConfInfo::process_config_fcst(GrdFileType ftype, int field_index) void ModeConfInfo::process_config_obs(GrdFileType otype, int field_index) { - int j, k, n; - - Dictionary * obs_dict = (Dictionary *) nullptr; - obs_dict = conf.lookup_dictionary(conf_key_obs); + Dicationary * obs_dict = conf.lookup_dictionary(conf_key_obs); shift_right = obs_dict->lookup_int(conf_key_shift_right); if (field_index == 0) { @@ -688,7 +676,8 @@ void ModeConfInfo::config_set_all_percentile_thresholds(const std::vector fcst_freq, obs_freq; + vector fcst_freq; + vector obs_freq; // indices (common to forecast and obs) that require both inputs (fcst and obs) // which is either frequency bias, or sample obs with a forecast input, or sample fcst @@ -776,9 +765,8 @@ void ModeConfInfo::config_set_all_percentile_thresholds(const std::vectoris_array() ) { - int j, k; - const DictionaryEntry * e = 0; + const DictionaryEntry * e = nullptr; const Dictionary & D = *field; - if (data_type == ModeDataType::Traditional) { - // traditional mode, extra test - if ( (N_fields_f > 0) && (N != N_fields_f) ) { - mlog << Error - << "\nModeConfInfo::read_fields() -> fcst and obs dictionaries have different number of entries in traditional mode" - << ", not allowed\n\n"; - exit ( 1 ); + // traditional mode, extra test + if ( (data_type == ModeDataType::Traditional) && + (N_fields_f > 0) && + (N != N_fields_f) ) { + mlog << Error + << "\nModeConfInfo::read_fields() -> fcst and obs dictionaries have different number of entries in traditional mode" + << ", not allowed\n\n"; + + exit ( 1 ); - } } if (_fo == 'F') { @@ -958,7 +944,7 @@ if ( field->is_array() ) { } else { N_fields_o = N; } - for (j=0; jdict(); -const int N = ( (field->is_array()) ? (field->n_entries()) : 1 ); - if ( field->is_array() ) { - const DictionaryEntry * e = 0; + const DictionaryEntry * e = nullptr; const Dictionary & D = *field; e = D[field_index]; @@ -1175,7 +1159,8 @@ void ModeConfInfo::set_perc_thresh(const DataPlane &f_dp, // // Sort the input arrays // - NumArray fsort, osort; + NumArray fsort; + NumArray osort; int nxy = f_dp.nx() * f_dp.ny(); fsort.extend(nxy); @@ -1276,7 +1261,7 @@ void ModeConfInfo::parse_nc_info() { -const DictionaryEntry * e = (const DictionaryEntry *) nullptr; +const DictionaryEntry * e = nullptr; e = conf.lookup(conf_key_nc_pairs_flag); @@ -1371,16 +1356,6 @@ void ModeConfInfo::set_conv_radius_by_index(int k) void ModeConfInfo::set_obs_conv_radius_by_index(int k) { - // if (data_type != ModeDataType::MvMode_Obs) { - // if ( (k < 0) || (k >= Fcst->conv_radius_array.n_elements()) ) { - // mlog << Error - // << "\nModeConfInfo::set_conv_radius_by_index(int) -> " - // << "range check error\n\n"; - // exit ( 1 ); - // } - // Fcst->conv_radius = Fcst->conv_radius_array[k]; - // } - // if (data_type != ModeDataType::MvMode_Fcst) { if ( (k < 0) || (k >= Obs->conv_radius_array.n_elements()) ) { mlog << Error << "\nModeConfInfo::set_conv_radius_by_index(int) -> " @@ -1522,11 +1497,11 @@ void ModeConfInfo::set_fcst_conv_thresh_by_index(int k) void ModeConfInfo::set_merge_thresh_by_index(int k) { - if (data_type != ModeDataType::MvMode_Fcst) { - if ( Obs->need_merge_thresh () ) set_obs_merge_thresh_by_index (k); + if ( data_type != ModeDataType::MvMode_Fcst && + Obs->need_merge_thresh() ) set_obs_merge_thresh_by_index (k); } - if (data_type != ModeDataType::MvMode_Obs) { - if ( Fcst->need_merge_thresh () ) set_fcst_merge_thresh_by_index (k); + if ( data_type != ModeDataType::MvMode_Obs && + Fcst->need_merge_thresh() ) set_fcst_merge_thresh_by_index (k); } } @@ -1556,11 +1531,11 @@ void ModeConfInfo::set_fcst_merge_thresh_by_index(int k) void ModeConfInfo::set_conv_thresh_by_merge_index(int k) { - if (data_type != ModeDataType::MvMode_Fcst) { - if (Obs->need_merge_thresh()) set_obs_conv_thresh_by_merge_index (k); + if ( data_type != ModeDataType::MvMode_Fcst && + Obs->need_merge_thresh() ) set_obs_conv_thresh_by_merge_index (k); } - if (data_type != ModeDataType::MvMode_Obs) { - if (Fcst->need_merge_thresh()) set_fcst_conv_thresh_by_merge_index (k); + if ( data_type != ModeDataType::MvMode_Obs && + Fcst->need_merge_thresh() ) set_fcst_conv_thresh_by_merge_index (k); } } @@ -1692,7 +1667,7 @@ GrdFileType ModeConfInfo::file_type_for_field(bool isFcst, int field_index) // look at the dictionary for the obs or forecast at index, with // parents - Dictionary * dict = (Dictionary *) nullptr; + Dictionary * dict = nullptr; if (isFcst) { dict = conf.lookup_dictionary(conf_key_fcst); } else { @@ -1787,7 +1762,7 @@ void ModeConfInfo::get_multivar_programs() { -Dictionary * dict = (Dictionary *) nullptr; +Dictionary * dict = nullptr; fcst_multivar_logic.clear(); obs_multivar_logic.clear(); @@ -1930,8 +1905,8 @@ void ModeConfInfo::check_multivar_not_implemented() PercThreshType ModeConfInfo::perctype(const Mode_Field_Info &f) const { - PercThreshType pm=no_perc_thresh_type;; - PercThreshType pc=no_perc_thresh_type;; + PercThreshType pm=no_perc_thresh_type; + PercThreshType pc=no_perc_thresh_type; if (f.merge_thresh_array.n() > 0) { pm = f.merge_thresh_array[0].get_ptype(); } diff --git a/src/tools/core/mode/mode_exec.cc b/src/tools/core/mode/mode_exec.cc index 467773968..c2532c2cc 100644 --- a/src/tools/core/mode/mode_exec.cc +++ b/src/tools/core/mode/mode_exec.cc @@ -203,7 +203,7 @@ void ModeExecutive::init_traditional(int n_files) /////////////////////////////////////////////////////////////////////// void ModeExecutive::init_multivar_simple(int rIndex, int tIndex, - int j, int n_files, ModeDataType dtype, + int j, ModeDataType dtype, const ModeConfInfo &conf) { @@ -216,8 +216,6 @@ void ModeExecutive::init_multivar_simple(int rIndex, int tIndex, engine.conf_info.set_field_index(j); - // engine.conf_info.nc_info.compress_level = engine.conf_info.get_compression_level(); - return; } @@ -238,8 +236,6 @@ void ModeExecutive::init_multivar_intensities(const ModeConfInfo &conf) // check one again for multivar problems engine.conf_info.check_multivar_not_implemented(); - // engine.conf_info.nc_info.compress_level = engine.conf_info.get_compression_level(); - return; } @@ -252,8 +248,10 @@ void ModeExecutive::setup_traditional_fcst_obs_data() { - // ShapeData fcst_sd, obs_sd; - double fmin, omin, fmax, omax; + double fmin; + double omin; + double fmax; + double omax; Fcst_sd.clear(); Obs_sd.clear(); @@ -443,7 +441,8 @@ void ModeExecutive::setup_multivar_fcst_data(const Grid &verification_grid, const ModeInputData &input) { - double fmin, fmax; + double fmin; + double fmax; Fcst_sd.clear(); Fcst_sd.data = input._dataPlane; @@ -506,8 +505,8 @@ void ModeExecutive::setup_multivar_obs_data(const Grid &verification_grid, const ModeInputData &input) { - // ShapeData fcst_sd, obs_sd; - double omin, omax; + double omin; + double omax; Obs_sd.clear(); @@ -572,7 +571,10 @@ void ModeExecutive::setup_multivar_obs_data(const Grid &verification_grid, void ModeExecutive::setup_multivar_fcst_obs_data_intensities(const MultiVarData &mvdf, const MultiVarData &mvdo) { - double fmin, fmax, omin, omax; + double fmin; + double fmax; + double omin; + double omax; bool simple = true; Fcst_sd = *(mvdf.shapedata_ptr(simple)); @@ -674,9 +676,11 @@ void ModeExecutive::setup_multivar_fcst_obs_data_super(const ShapeData &f_super, const ShapeData &o_super, const Grid &igrid) { - double fmin, omin, fmax, omax; + double fmin; + double omin; + double fmax; + double omax; - bool simple = true; Fcst_sd = f_super; Fcst_sd.debug_examine(); Obs_sd = o_super; @@ -816,7 +820,7 @@ void ModeExecutive::do_conv_thresh_traditional(const int r_index, const int t_in /////////////////////////////////////////////////////////////////////// void ModeExecutive::do_conv_thresh_multivar_super(int rIndexF, int tIndexF, - int rIndexO, int tIndexO) + int, int) { ModeConfInfo & conf = engine.conf_info; @@ -828,10 +832,9 @@ void ModeExecutive::do_conv_thresh_multivar_super(int rIndexF, int tIndexF, conf.set_fcst_conv_thresh(s); conf.set_fcst_conv_radius(0.0); conf.set_fcst_merge_thresh(s); - //conf.set_fcst_merge_thresh_by_index(0); conf.set_obs_conv_thresh(s); conf.set_obs_conv_radius(0.0); - conf.set_obs_merge_thresh(s);//_by_index(0); + conf.set_obs_merge_thresh(s); // // Set up the engine with these raw fields @@ -903,7 +906,7 @@ void ModeExecutive::do_conv_thresh_multivar_intensity_compare(int rIndexF, int t /////////////////////////////////////////////////////////////////////// -void ModeExecutive::do_conv_thresh_multivar_simple(Processing_t p, int rIndex, int tIndex) +void ModeExecutive::do_conv_thresh_multivar_simple(Processing_t p, int rIndex, int) { ModeConfInfo & conf = engine.conf_info; bool obs = conf.data_type == ModeDataType::MvMode_Obs; @@ -1072,7 +1075,8 @@ void ModeExecutive::process_masks(ShapeData & fcst_sd, ShapeData & obs_sd) { - ShapeData grid_mask_sd, poly_mask_sd; + ShapeData grid_mask_sd; + ShapeData poly_mask_sd; ConcatString name; mlog << Debug(2) @@ -1129,7 +1133,8 @@ void ModeExecutive::process_fcst_masks(ShapeData & fcst_sd) { - ShapeData grid_mask_sd, poly_mask_sd; + ShapeData grid_mask_sd; + ShapeData poly_mask_sd; ConcatString name; mlog << Debug(3) << "Processing masking regions.\n"; @@ -1173,7 +1178,8 @@ void ModeExecutive::process_obs_masks(ShapeData & obs_sd) { - ShapeData grid_mask_sd, poly_mask_sd; + ShapeData grid_mask_sd; + ShapeData poly_mask_sd; ConcatString name; mlog << Debug(3) << "Processing masking regions.\n"; @@ -1287,21 +1293,22 @@ void ModeExecutive::process_output_multivar_intensity_compare(const MultiVarData double fmax = mvdf->_data_max; double omin = mvdo->_data_min; double omax = mvdo->_data_max; - double data_min, data_max; - if (!is_bad_data(fmin) && !is_bad_data(omin)) data_min = min(fmin, omin); - else if(!is_bad_data(fmin) && is_bad_data(omin)) data_min = fmin; - else if( is_bad_data(fmin) && !is_bad_data(omin)) data_min = omin; - - if (!is_bad_data(fmax) && !is_bad_data(omax)) data_max = max(fmax, omax); - else if(!is_bad_data(fmax) && is_bad_data(omax)) data_max = fmax; - else if( is_bad_data(fmax) && !is_bad_data(omax)) data_max = omax; + double dmin; + double dmax; + if (!is_bad_data(fmin) && !is_bad_data(omin)) dmin = min(fmin, omin); + else if(!is_bad_data(fmin) && is_bad_data(omin)) dmin = fmin; + else if( is_bad_data(fmin) && !is_bad_data(omin)) dmin = omin; + + if (!is_bad_data(fmax) && !is_bad_data(omax)) dmax = max(fmax, omax); + else if(!is_bad_data(fmax) && is_bad_data(omax)) dmax = fmax; + else if( is_bad_data(fmax) && !is_bad_data(omax)) dmax = omax; set_raw_to_full(mvdf->_simple->_raw_data,mvdo->_simple->_raw_data, - mvdf->_nx, mvdf->_ny, data_min, data_max); + mvdf->_nx, mvdf->_ny, dmin, dmax); write_obj_netcdf(engine.conf_info.nc_info); - if ( engine.conf_info.ps_plot_flag ) plot_engine(); + if ( engine.conf_info.ps_plot_flag ) plot_engine(); return; @@ -1338,13 +1345,13 @@ void ModeExecutive::compute_ct_stats() { - int i, x, y; - ShapeData fcst_mask, obs_mask; + ShapeData fcst_mask; + ShapeData obs_mask; mlog << Debug(2) << "Computing contingency table statistics...\n"; - for(i=0; iis_bad_data(x, y) || @@ -1517,7 +1524,9 @@ void ModeExecutive::write_obj_stats() { - AsciiTable obj_at, fcst_merge_at, obs_merge_at; + AsciiTable obj_at; + AsciiTable fcst_merge_at; + AsciiTable obs_merge_at; ofstream out; ConcatString stat_file; @@ -1703,45 +1712,44 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) if ( info.all_false() ) return; - int n, x, y; ConcatString out_file; ConcatString s; const ConcatString fcst_thresh = engine.conf_info.Fcst->conv_thresh.get_str(5); const ConcatString obs_thresh = engine.conf_info.Obs->conv_thresh.get_str(5); - float *fcst_raw_data = (float *) nullptr; - float *fcst_obj_raw_data = (float *) nullptr; - int *fcst_obj_data = (int *) nullptr; - int *fcst_clus_data = (int *) nullptr; + float *fcst_raw_data = nullptr; + float *fcst_obj_raw_data = nullptr; + int *fcst_obj_data = nullptr; + int *fcst_clus_data = nullptr; - float *obs_raw_data = (float *) nullptr; - float *obs_obj_raw_data = (float *) nullptr; - int *obs_obj_data = (int *) nullptr; - int *obs_clus_data = (int *) nullptr; + float *obs_raw_data = nullptr; + float *obs_obj_raw_data = nullptr; + int *obs_obj_data = nullptr; + int *obs_clus_data = nullptr; - NcFile *f_out = (NcFile *) nullptr; + NcFile *f_out = nullptr; - NcDim lat_dim ; - NcDim lon_dim ; + NcDim lat_dim; + NcDim lon_dim; - NcDim fcst_thresh_dim ; - NcDim obs_thresh_dim ; + NcDim fcst_thresh_dim; + NcDim obs_thresh_dim; - NcVar fcst_raw_var ; - NcVar fcst_obj_raw_var ; - NcVar fcst_obj_var ; - NcVar fcst_clus_var ; + NcVar fcst_raw_var; + NcVar fcst_obj_raw_var; + NcVar fcst_obj_var; + NcVar fcst_clus_var; - NcVar obs_raw_var ; - NcVar obs_obj_raw_var ; - NcVar obs_obj_var ; - NcVar obs_clus_var ; + NcVar obs_raw_var; + NcVar obs_obj_raw_var; + NcVar obs_obj_var; + NcVar obs_clus_var; - NcVar fcst_radius_var ; - NcVar obs_radius_var ; + NcVar fcst_radius_var; + NcVar obs_radius_var; - NcVar fcst_thresh_var ; - NcVar obs_thresh_var ; + NcVar fcst_thresh_var; + NcVar obs_thresh_var; // // Create output NetCDF file name @@ -1948,11 +1956,11 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) } - for(x=0; xdata (x, y); - obs_raw_data[n] = engine.obs_raw->data (x, y); + fcst_raw_data[n] = (float) engine.fcst_raw->data (x, y); + obs_raw_data[n] = (float) engine.obs_raw->data (x, y); } if(engine.fcst_split->is_nonzero(x, y) ) { if ( info.do_object_raw && fcst_obj_raw_data != nullptr && engine.fcst_raw != nullptr ) { - fcst_obj_raw_data[n] = engine.fcst_raw->data(x, y); + fcst_obj_raw_data[n] = (float) engine.fcst_raw->data(x, y); } if ( info.do_object_id && fcst_obj_data != nullptr && engine.fcst_split != nullptr ) { fcst_obj_data[n] = nint(engine.fcst_split->data(x, y)); @@ -1986,7 +1994,7 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) if(engine.obs_split->is_nonzero(x, y) ) { if ( info.do_object_raw && obs_obj_raw_data != nullptr ) { - obs_obj_raw_data[n] = engine.obs_raw->data(x, y); + obs_obj_raw_data[n] = (float) engine.obs_raw->data(x, y); } if ( info.do_object_id && obs_obj_data != nullptr ) { obs_obj_data[n] = nint(engine.obs_split->data(x, y)); @@ -2043,75 +2051,63 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) // Write the forecast and observation raw value variables // - if ( info.do_raw ) { - - if( !put_nc_data_with_dims(&fcst_raw_var, &fcst_raw_data[0], grid.ny(), grid.nx()) || - !put_nc_data_with_dims(&obs_raw_var, &obs_raw_data[0], grid.ny(), grid.nx()) ) { - - mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " - << "error with the fcst_raw_var->put or obs_raw_var->put\n\n"; - exit(1); - } + if( info.do_raw && + (!put_nc_data_with_dims(&fcst_raw_var, &fcst_raw_data[0], grid.ny(), grid.nx()) || + !put_nc_data_with_dims(&obs_raw_var, &obs_raw_data[0], grid.ny(), grid.nx())) ) { + mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " + << "error with the fcst_raw_var->put or obs_raw_var->put\n\n"; + exit(1); } - if ( info.do_object_raw ) { - - if( !put_nc_data_with_dims(&fcst_obj_raw_var, &fcst_obj_raw_data[0], grid.ny(), grid.nx()) || - !put_nc_data_with_dims(&obs_obj_raw_var, &obs_obj_raw_data[0], grid.ny(), grid.nx()) ) { - - mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " - << "error with the fcst_obj_raw_var->put or obs_obj_raw_var->put\n\n"; - exit(1); - } + if ( info.do_object_raw && + (!put_nc_data_with_dims(&fcst_obj_raw_var, &fcst_obj_raw_data[0], grid.ny(), grid.nx()) || + !put_nc_data_with_dims(&obs_obj_raw_var, &obs_obj_raw_data[0], grid.ny(), grid.nx())) ) { + mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " + << "error with the fcst_obj_raw_var->put or obs_obj_raw_var->put\n\n"; + exit(1); } // // Write the forecast and observation object ID variables // - if ( info.do_object_id ) { - - if( !put_nc_data_with_dims(&fcst_obj_var, &fcst_obj_data[0], grid.ny(), grid.nx()) || - !put_nc_data_with_dims(&obs_obj_var, &obs_obj_data[0], grid.ny(), grid.nx()) ) { - - mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " - << "error with the fcst_obj_var->put or obs_obj_var->put\n\n"; - exit(1); - } + if ( info.do_object_id && + (!put_nc_data_with_dims(&fcst_obj_var, &fcst_obj_data[0], grid.ny(), grid.nx()) || + !put_nc_data_with_dims(&obs_obj_var, &obs_obj_data[0], grid.ny(), grid.nx())) ) { + mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " + << "error with the fcst_obj_var->put or obs_obj_var->put\n\n"; + exit(1); } // // Write the forecast and observation cluster object ID variables // - if ( info.do_cluster_id ) { - - if( !put_nc_data_with_dims(&fcst_clus_var, &fcst_clus_data[0], grid.ny(), grid.nx()) || - !put_nc_data_with_dims(&obs_clus_var, &obs_clus_data[0], grid.ny(), grid.nx()) ) { - - mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " - << "error with the fcst_clus_var->put or obs_clus_var->put\n\n"; - exit(1); - } + if ( info.do_cluster_id && + (!put_nc_data_with_dims(&fcst_clus_var, &fcst_clus_data[0], grid.ny(), grid.nx()) || + !put_nc_data_with_dims(&obs_clus_var, &obs_clus_data[0], grid.ny(), grid.nx())) ) { + mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " + << "error with the fcst_clus_var->put or obs_clus_var->put\n\n"; + exit(1); } // // Delete allocated memory // - if (fcst_raw_data) { delete [] fcst_raw_data; fcst_raw_data = (float *) nullptr; } - if (fcst_obj_raw_data) { delete [] fcst_obj_raw_data; fcst_obj_raw_data = (float *) nullptr; } - if (fcst_obj_data) { delete [] fcst_obj_data; fcst_obj_data = (int *) nullptr; } - if (fcst_clus_data) { delete [] fcst_clus_data; fcst_clus_data = (int *) nullptr; } + if (fcst_raw_data) { delete [] fcst_raw_data; fcst_raw_data = nullptr; } + if (fcst_obj_raw_data) { delete [] fcst_obj_raw_data; fcst_obj_raw_data = nullptr; } + if (fcst_obj_data) { delete [] fcst_obj_data; fcst_obj_data = nullptr; } + if (fcst_clus_data) { delete [] fcst_clus_data; fcst_clus_data = nullptr; } - if (obs_raw_data) { delete [] obs_raw_data; obs_raw_data = (float *) nullptr; } - if (obs_obj_raw_data) { delete [] obs_obj_raw_data; obs_obj_raw_data = (float *) nullptr; } - if (obs_obj_data) { delete [] obs_obj_data; obs_obj_data = (int *) nullptr; } - if (obs_clus_data) { delete [] obs_clus_data; obs_clus_data = (int *) nullptr; } + if (obs_raw_data) { delete [] obs_raw_data; obs_raw_data = nullptr; } + if (obs_obj_raw_data) { delete [] obs_obj_raw_data; obs_obj_raw_data = nullptr; } + if (obs_obj_data) { delete [] obs_obj_data; obs_obj_data = nullptr; } + if (obs_clus_data) { delete [] obs_clus_data; obs_clus_data = nullptr; } // // Write out the values of the vertices of the polylines. @@ -2185,42 +2181,53 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) { - int i, j, x, y, n_pts, n_poly; - double lat, lon; + int n_pts; + int n_poly; + double lat; + double lon; - Polyline **poly = (Polyline **) nullptr; + Polyline **poly = nullptr; - int *poly_start = (int *) nullptr; - int *poly_npts = (int *) nullptr; - float *poly_lat = (float *) nullptr; - float *poly_lon = (float *) nullptr; - int *poly_x = (int *) nullptr; - int *poly_y = (int *) nullptr; + int *poly_start = nullptr; + int *poly_npts = nullptr; + float *poly_lat = nullptr; + float *poly_lon = nullptr; + int *poly_x = nullptr; + int *poly_y = nullptr; // Dimensions and variables for each object - NcDim obj_dim ; - NcVar obj_poly_start_var ; - NcVar obj_poly_npts_var ; + NcDim obj_dim; + NcVar obj_poly_start_var; + NcVar obj_poly_npts_var; // Dimensions and variables for each boundary point - NcDim poly_dim ; - NcVar poly_lat_var ; - NcVar poly_lon_var ; - NcVar poly_x_var ; - NcVar poly_y_var ; + NcDim poly_dim; + NcVar poly_lat_var; + NcVar poly_lon_var; + NcVar poly_x_var; + NcVar poly_y_var; // Dimension names - ConcatString obj_dim_name, poly_dim_name; + ConcatString obj_dim_name; + ConcatString poly_dim_name; // Variable names - ConcatString start_var_name, start_long_name; - ConcatString npts_var_name, npts_long_name; - ConcatString lat_var_name, lat_long_name; - ConcatString lon_var_name, lon_long_name; - ConcatString x_var_name, x_long_name; - ConcatString y_var_name, y_long_name; - ConcatString field_name, field_long; - ConcatString poly_name, poly_long; + ConcatString start_var_name; + ConcatString start_long_name; + ConcatString npts_var_name; + ConcatString npts_long_name; + ConcatString lat_var_name; + ConcatString lat_long_name; + ConcatString lon_var_name; + ConcatString lon_long_name; + ConcatString x_var_name; + ConcatString x_long_name; + ConcatString y_var_name; + ConcatString y_long_name; + ConcatString field_name; + ConcatString field_long; + ConcatString poly_name; + ConcatString poly_long; // Determine the number of polylines to be written // and set up strings @@ -2306,7 +2313,7 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) poly = new Polyline * [n_poly]; // Point at the polyline to be written - for(i=0; in_points; + for(int i=0, n_pts=0; in_points; // Define dimensions NcDim tmp_obj_dim = get_nc_dim(f_out, (string)obj_dim_name); @@ -2384,7 +2391,7 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // Store the points for each polyline // n_pts = 0; - for(i=0; in_points; - for(j=0; ju[j]); - y = nint(poly[i]->v[j]); + int x = nint(poly[i]->u[j]); + int y = nint(poly[i]->v[j]); poly_x[n_pts] = x; poly_y[n_pts] = y; // Convert to lat/lon and store them grid.xy_to_latlon(x, y, lat, lon); - poly_lat[n_pts] = lat; - poly_lon[n_pts] = -1.0*lon; + poly_lat[n_pts] = (float) lat; + poly_lon[n_pts] = (float) -1.0*lon; } } @@ -2465,7 +2472,7 @@ void ModeExecutive::write_ct_stats() AsciiTable cts_at; ofstream out; - int i, c; + int c; double v; ConcatString stat_file; @@ -2496,8 +2503,8 @@ void ModeExecutive::write_ct_stats() // Setup the AsciiTable to be used // cts_at.clear(); - i = n_mode_hdr_columns + n_mode_cts_columns; - cts_at.set_size(3, i); // Set table size + c = n_mode_hdr_columns + n_mode_cts_columns; + cts_at.set_size(3, c); // Set table size justify_mode_cols(cts_at); // Justify columns cts_at.set_precision( // Set the precision engine.conf_info.conf.output_precision()); @@ -2508,14 +2515,14 @@ void ModeExecutive::write_ct_stats() // // Write out the MODE header columns // - for(i=0; i values; vector count; @@ -99,7 +101,7 @@ static void _debug_shape_examine(string &name, const ShapeData &sd, values.push_back(v); count.push_back(1); } else { - int ii = vi - values.begin(); + int ii = nint(vi - values.begin()); count[ii] = count[ii] + 1; } } @@ -126,8 +128,8 @@ ModeSuperObject::ModeSuperObject(bool isFcst, int n_files, bool do_clusters, // set the BoolPlane values using the mvd content // - BoolPlane * simple_plane = new BoolPlane [n_files]; - BoolPlane * merge_plane = new BoolPlane [n_files]; + auto simple_plane = new BoolPlane [n_files]; + auto merge_plane = new BoolPlane [n_files]; for (int j=0; jobjects_from_arrays(do_clusters, true, simple_plane[j]); @@ -144,7 +146,8 @@ ModeSuperObject::ModeSuperObject(bool isFcst, int n_files, bool do_clusters, _simple_result.set_size(nx, ny); merge_result.set_size(nx, ny); - string simple_name, merge_name; + string simple_name; + string merge_name; if (isFcst) { simple_name = "Fcst_Simple"; @@ -172,7 +175,7 @@ ModeSuperObject::ModeSuperObject(bool isFcst, int n_files, bool do_clusters, } } - ShapeData merge_sd = ShapeData(*(mvd[0]->_simple->_sd)); + auto merge_sd = ShapeData(*(mvd[0]->_simple->_sd)); for (int x=0; x fcstSimple, obsSimple; + vector fcstSimple; + vector obsSimple; // create simple objects for all convolution settings if (config.quilt) { for (int ir=0; ir= 0) config.nc_info.set_compress_level(compress_level); - // from within mode_exec: - // engine.conf_info.nc_info.compress_level = engine.conf_info.get_compression_level(); return; } @@ -444,26 +439,24 @@ void MultivarFrontEnd::_set_output_path() //////////////////////////////////////////////////////////////////////// -int MultivarFrontEnd::_mkdir(const char *dir) +int MultivarFrontEnd::_mkdir(const char *dir) const { char tmp[256]; - char *p = NULL; size_t len; snprintf(tmp, sizeof(tmp),"%s",dir); len = strlen(tmp); if (tmp[len - 1] == '/') tmp[len - 1] = 0; - for (p = tmp + 1; *p; p++) + for (char *p = tmp + 1; *p; p++) if (*p == '/') { *p = 0; string s = tmp; - if (s != ".") { - if (mkdir(tmp, dir_creation_mode) < 0) { - mlog << Error << "\nMultivarFrontEnd::_mkdir() ->" - << "Error making " << tmp << "\n"; - return -1; - } + if (s != "." && + mkdir(tmp, dir_creation_mode) < 0) { + mlog << Error << "\nMultivarFrontEnd::_mkdir() ->" + << "Error making " << tmp << "\n"; + return -1; } *p = '/'; } @@ -514,7 +507,7 @@ void MultivarFrontEnd::_create_verif_grid() _init_exec(ModeExecutive::TRADITIONAL, "None", "None"); mode_exec->setup_verification_grid(fcstInput[0], obsInput[0], config); verification_grid = mode_exec->grid; - delete mode_exec; mode_exec = 0; + delete mode_exec; mode_exec = nullptr; } //////////////////////////////////////////////////////////////////////// @@ -553,7 +546,7 @@ MultiVarData *MultivarFrontEnd::_create_simple_multivar_data(ModeDataType dtype, _simple_objects(ModeExecutive::MULTIVAR_SIMPLE, dtype, rIndex, tIndex, j, n_files, filename, input); MultiVarData *mvdi = mode_exec->get_multivar_data(dtype); - delete mode_exec; mode_exec = 0; + delete mode_exec; mode_exec = nullptr; // // create simple merged objects @@ -561,7 +554,7 @@ MultiVarData *MultivarFrontEnd::_create_simple_multivar_data(ModeDataType dtype, _simple_objects(ModeExecutive::MULTIVAR_SIMPLE_MERGE, dtype, rIndex, tIndex, j, n_files, filename, input); mode_exec->add_multivar_merge_data(mvdi, dtype); - delete mode_exec; mode_exec = 0; + delete mode_exec; mode_exec = nullptr; return mvdi; } @@ -575,11 +568,11 @@ void MultivarFrontEnd::_simple_objects(ModeExecutive::Processing_t p, { if (dtype == ModeDataType::MvMode_Fcst) { _init_exec(p, filename, "None"); - mode_exec->init_multivar_simple(rIndex, tIndex, j, n_files, dtype, config); + mode_exec->init_multivar_simple(rIndex, tIndex, j, dtype, config); mode_exec->setup_multivar_fcst_data(verification_grid, input); } else { _init_exec(p, "None", filename); - mode_exec->init_multivar_simple(rIndex, tIndex, j, n_files, dtype, config); + mode_exec->init_multivar_simple(rIndex, tIndex, j, dtype, config); mode_exec->setup_multivar_obs_data(verification_grid, input); } @@ -654,7 +647,7 @@ MultivarFrontEnd::_create_intensity_comparisons(SimpleObjects &fcsts, int findex _intensity_compare_mode_algorithm(fcsts._rIndex, fcsts._tIndex, obs._rIndex, obs._tIndex, *mvdf, *mvdo, fcsts._super, obs._super); - delete mode_exec; mode_exec = 0; + delete mode_exec; mode_exec = nullptr; } //////////////////////////////////////////////////////////////////////// @@ -716,7 +709,7 @@ void MultivarFrontEnd::_process_superobjects(SimpleObjects &fcsts, SimpleObjects _superobject_mode_algorithm(fcsts._rIndex, fcsts._tIndex, obs._rIndex, obs._tIndex, fcsts._super, obs._super); - delete mode_exec; mode_exec = 0; + delete mode_exec; mode_exec = nullptr; } //////////////////////////////////////////////////////////////////////// @@ -747,10 +740,9 @@ void MultivarFrontEnd::_init_exec(ModeExecutive::Processing_t p, { mlog << Debug(4) << "Running multivar front end for " << ModeExecutive::stype(p) << "\n"; - if ( mode_exec ) { delete mode_exec; mode_exec = 0; } + if ( mode_exec ) { delete mode_exec; mode_exec = nullptr; } mode_exec = new ModeExecutive(); - // compress_level = -1; mode_exec->fcst_file = ffile; mode_exec->obs_file = ofile; diff --git a/src/tools/core/mode/multivar_frontend.h b/src/tools/core/mode/multivar_frontend.h index 8dbd322e6..80cd47566 100644 --- a/src/tools/core/mode/multivar_frontend.h +++ b/src/tools/core/mode/multivar_frontend.h @@ -32,9 +32,12 @@ class MultivarFrontEnd { int n_fcst_files, n_obs_files; StringArray fcst_filenames; StringArray obs_filenames; - BoolCalc f_calc, o_calc ; - std::vector fcstInput, obsInput; - std::vector mvdFcst, mvdObs; + BoolCalc f_calc; + BoolCalc o_calc; + std::vector fcstInput; + std::vector obsInput; + std::vector mvdFcst; + std::vector mvdObs; std::string fcst_fof; std::string obs_fof; @@ -43,7 +46,7 @@ class MultivarFrontEnd { void _read_config(const std::string & filename); void _setup_inputs(); void _set_output_path(); - int _mkdir(const char *dir); + int _mkdir(const char *dir) const; void _read_input(const std::string &name, int index, ModeDataType type, GrdFileType f_t, GrdFileType other_t, int shift); void _create_verif_grid(void); diff --git a/src/tools/core/mode/simple_objects.cc b/src/tools/core/mode/simple_objects.cc index b85cbaaed..a7ebd1ef7 100644 --- a/src/tools/core/mode/simple_objects.cc +++ b/src/tools/core/mode/simple_objects.cc @@ -50,9 +50,9 @@ void SimpleObjects::setSuper(bool isFcst, int n_fcst_files, bool do_clusters, void SimpleObjects::clear(void) { - for (size_t j=0; j<_mvd.size(); ++j) { - delete _mvd[j]; - _mvd[j] = 0; + for (auto &x : _mvd) { + delete x; + x = nullptr; } _mvd.clear(); } diff --git a/src/tools/core/mode/simple_objects.hh b/src/tools/core/mode/simple_objects.hh index b044f9fea..7215a0533 100644 --- a/src/tools/core/mode/simple_objects.hh +++ b/src/tools/core/mode/simple_objects.hh @@ -24,8 +24,6 @@ class SimpleObjects { - private: - public: SimpleObjects();