From 571bdc2ad32b583da39da34f0edc4577a8f9906e Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 9 Oct 2024 21:01:52 +0000 Subject: [PATCH 01/16] #2673 SonarQube findings: use vector for the dynamic memory allocation --- src/basic/vx_math/hist.cc | 12 +- src/basic/vx_math/hist.h | 3 +- src/basic/vx_math/legendre.cc | 12 +- src/basic/vx_math/legendre.h | 8 +- src/basic/vx_math/ptile.cc | 4 +- src/basic/vx_util/num_array.cc | 89 +++++++-------- src/libcode/vx_nc_obs/nc_obs_util.cc | 72 +++++------- src/libcode/vx_python3_utils/wchar_argv.cc | 7 +- src/libcode/vx_shapedata/shapedata.cc | 27 ++--- src/tools/core/mode/mode_exec.cc | 124 ++++++++------------- src/tools/other/lidar2nc/lidar2nc.cc | 38 +++---- 11 files changed, 158 insertions(+), 238 deletions(-) diff --git a/src/basic/vx_math/hist.cc b/src/basic/vx_math/hist.cc index d0bcd924e1..c5d2c89133 100644 --- a/src/basic/vx_math/hist.cc +++ b/src/basic/vx_math/hist.cc @@ -51,7 +51,7 @@ Histogram::~Histogram() { -if ( Count ) { delete [] Count; Count = (int *) nullptr; } +Count.clear(); } @@ -93,7 +93,7 @@ void Histogram::init_from_scratch() { -Count = (int *) nullptr; +Count.clear(); Nbins = 0; @@ -120,9 +120,7 @@ void Histogram::clear() { -int j; - -for (j=0; j #include @@ -28,7 +29,7 @@ class Histogram { private: - int * Count; + std::vector Count; int Nbins; diff --git a/src/basic/vx_math/legendre.cc b/src/basic/vx_math/legendre.cc index 6a7b78e269..f04741135f 100644 --- a/src/basic/vx_math/legendre.cc +++ b/src/basic/vx_math/legendre.cc @@ -117,9 +117,9 @@ void Legendre::init_from_scratch() { -P = 0; +P.clear(); -PP = 0; +PP.clear(); clear(); @@ -135,9 +135,9 @@ void Legendre::clear() { -if ( P ) { delete [] P; P = nullptr; } +P.clear(); -if ( PP ) { delete [] PP; PP = nullptr; } +PP.clear(); X = 0.0; @@ -201,9 +201,9 @@ clear(); MaxDegree = N; -P = new double [N + 1]; +P.resize(N + 1); -PP = new double [N + 1]; +PP.resize(N + 1); calc(0.0); diff --git a/src/basic/vx_math/legendre.h b/src/basic/vx_math/legendre.h index 4d0265801f..b9af82db02 100644 --- a/src/basic/vx_math/legendre.h +++ b/src/basic/vx_math/legendre.h @@ -19,6 +19,10 @@ #define __VX_LEGENDRE_H__ +//////////////////////////////////////////////////////////////////////// + +#include + //////////////////////////////////////////////////////////////////////// @@ -37,9 +41,9 @@ class Legendre { double X; // last x value - double * P; // allocated + std::vector P; // allocated - double * PP; // allocated + std::vector PP; // allocated public: diff --git a/src/basic/vx_math/ptile.cc b/src/basic/vx_math/ptile.cc index e3253631f6..3618ae9ad4 100644 --- a/src/basic/vx_math/ptile.cc +++ b/src/basic/vx_math/ptile.cc @@ -215,11 +215,10 @@ if ( n <= 1 ) return 0; int i, j, ties_current, ties_total, tie_rank_start = 0, tie_rank_end; double tie_rank_mean; RankInfo *rank_info = (RankInfo *) nullptr; -double *ordered_array = (double *) nullptr; +vector ordered_array(n); double prev_v, v; rank_info = new RankInfo [n]; -ordered_array = new double [n]; // Each RankInfo structure contains a index value from 0 to n-1 and a pointer // to the data to be ranked @@ -296,7 +295,6 @@ if(ties_current != 0) { } if(rank_info) { delete [] rank_info; rank_info = (RankInfo *) nullptr; } -if(ordered_array) { delete [] ordered_array; ordered_array = (double *) nullptr; } return ties_total; diff --git a/src/basic/vx_util/num_array.cc b/src/basic/vx_util/num_array.cc index cb5046c8a6..5a7fcee4c9 100644 --- a/src/basic/vx_util/num_array.cc +++ b/src/basic/vx_util/num_array.cc @@ -123,7 +123,7 @@ void NumArray::init_from_scratch() { clear(); - + return; } @@ -171,7 +171,7 @@ void NumArray::assign(const NumArray & a) clear(); e = a.e; - + Sorted = a.Sorted; return; @@ -209,7 +209,7 @@ void NumArray::dump(ostream & out, int depth) const int j; for (j=0; j " - << "memory allocation error\n\n"; - - exit ( 1 ); + vector data (n); + vector data_loc (n); + vector data_rank (n); - } + //if ( !data || !data_loc || !data_rank ) { + // + // mlog << Error << "\nint NumArray::rank_array() -> " + // << "memory allocation error\n\n"; + // + // exit ( 1 ); + // + //} // // Search the data array for valid data and keep track of its location @@ -679,20 +677,13 @@ int NumArray::rank_array(int &ties) // Compute the rank of the data and store the ranks in the data_rank array // Keep track of the number of ties in the ranks. // - ties = do_rank(data, data_rank, n_vld); + ties = do_rank(data.data(), data_rank.data(), n_vld); // // Store the data_rank values // for(i=0; i hdr_typ_idx_block(buf_size); + vector hdr_sid_idx_block(buf_size); + vector hdr_vld_idx_block(buf_size); + vector hdr_lat_block(buf_size); + vector hdr_lon_block(buf_size); + vector hdr_elv_block(buf_size); LongArray offsets; // = { 0, 0 }; LongArray lengths; // = { 1, 1 }; @@ -685,7 +685,7 @@ void NetcdfObsVars::read_header_data(MetPointHeader &hdr_data) { else { // Get the corresponding header message type (index, not string) if(!get_nc_data(&hdr_typ_var, - hdr_typ_idx_block, lengths_1D, offsets_1D)) { + hdr_typ_idx_block.data(), lengths_1D, offsets_1D)) { mlog << Error << "\n" << method_name << "trouble getting hdr_typ\n\n"; exit(1); @@ -693,7 +693,7 @@ void NetcdfObsVars::read_header_data(MetPointHeader &hdr_data) { // Get the corresponding header station id (index, not string) if(!get_nc_data(&hdr_sid_var, - hdr_sid_idx_block, lengths_1D, offsets_1D)) { + hdr_sid_idx_block.data(), lengths_1D, offsets_1D)) { mlog << Error << "\n" << method_name << "trouble getting hdr_sid\n\n"; exit(1); @@ -701,7 +701,7 @@ void NetcdfObsVars::read_header_data(MetPointHeader &hdr_data) { // Get the corresponding header valid time (index, not string) if(!get_nc_data(&hdr_vld_var, - hdr_vld_idx_block, lengths_1D, offsets_1D)) { + hdr_vld_idx_block.data(), lengths_1D, offsets_1D)) { mlog << Error << "\n" << method_name << "trouble getting hdr_vld\n\n"; exit(1); @@ -711,19 +711,19 @@ void NetcdfObsVars::read_header_data(MetPointHeader &hdr_data) { // Get the header for this observation // if(!get_nc_data(&hdr_lat_var, - hdr_lat_block, lengths_1D, offsets_1D)) { + hdr_lat_block.data(), lengths_1D, offsets_1D)) { mlog << Error << "\n" << method_name << "trouble getting hdr_lat\n\n"; exit(1); } if(!get_nc_data(&hdr_lon_var, - hdr_lon_block, lengths_1D, offsets_1D)) { + hdr_lon_block.data(), lengths_1D, offsets_1D)) { mlog << Error << "\n" << method_name << "trouble getting hdr_lon\n\n"; exit(1); } if(!get_nc_data(&hdr_elv_var, - hdr_elv_block, lengths_1D, offsets_1D)) { + hdr_elv_block.data(), lengths_1D, offsets_1D)) { mlog << Error << "\n" << method_name << "trouble getting hdr_elv\n\n"; exit(1); @@ -739,13 +739,6 @@ void NetcdfObsVars::read_header_data(MetPointHeader &hdr_data) { } } - delete[] hdr_typ_idx_block; - delete[] hdr_sid_idx_block; - delete[] hdr_vld_idx_block; - delete[] hdr_lat_block; - delete[] hdr_lon_block; - delete[] hdr_elv_block; - if (!has_array_vars) { int tmp_dim_size; @@ -860,40 +853,40 @@ bool NetcdfObsVars::read_obs_data(int buf_size, int offset, } } else { - int *obs_hid_buf = new int[buf_size]; - int *obs_vid_buf = new int[buf_size]; - float *obs_lvl_buf = new float[buf_size]; - float *obs_hgt_buf = new float[buf_size]; - float *obs_val_buf = new float[buf_size]; + vector obs_hid_buf(buf_size); + vector obs_vid_buf(buf_size); + vector obs_lvl_buf(buf_size); + vector obs_hgt_buf(buf_size); + vector obs_val_buf(buf_size); lengths[1] = 1; - if(!get_nc_data(&obs_hid_var, obs_hid_buf, lengths, offsets)) { + if(!get_nc_data(&obs_hid_var, obs_hid_buf.data(), lengths, offsets)) { mlog << Error << "\n" << method_name << "can't read the record for observation " << "index " << offset << "\n\n"; result = false; } if(!get_nc_data((IS_INVALID_NC(obs_gc_var) ? &obs_vid_var : &obs_gc_var), - obs_vid_buf, lengths, offsets)) { + obs_vid_buf.data(), lengths, offsets)) { mlog << Error << "\n" << method_name << "can't read the record (vid or gc) for observation " << "index " << offset << "\n\n"; result = false; } - if(!get_nc_data(&obs_lvl_var, obs_lvl_buf, lengths, offsets)) { + if(!get_nc_data(&obs_lvl_var, obs_lvl_buf.data(), lengths, offsets)) { mlog << Error << "\n" << method_name << "can't read the record (lvl) for observation " << "index " << offset << "\n\n"; result = false; } - if(!get_nc_data(&obs_hgt_var, obs_hgt_buf, lengths, offsets)) { + if(!get_nc_data(&obs_hgt_var, obs_hgt_buf.data(), lengths, offsets)) { mlog << Error << "\n" << method_name << "can't read the record (hgt) for observation " << "index " << offset << "\n\n"; result = false; } - if(!get_nc_data(&obs_val_var, obs_val_buf, lengths, offsets)) { + if(!get_nc_data(&obs_val_var, obs_val_buf.data(), lengths, offsets)) { mlog << Error << "\n" << method_name << "can't read the record (val) for observation " << "index " << offset << "\n\n"; @@ -918,11 +911,6 @@ bool NetcdfObsVars::read_obs_data(int buf_size, int offset, } } - delete[] obs_hid_buf; - delete[] obs_vid_buf; - delete[] obs_lvl_buf; - delete[] obs_hgt_buf; - delete[] obs_val_buf; } return result; } @@ -955,9 +943,9 @@ void NetcdfObsVars::read_pb_hdr_data(MetPointHeader &hdr_data) { // Read PB report type int buf_size = ((pb_hdr_count > NC_BUFFER_SIZE_32K) ? NC_BUFFER_SIZE_32K : pb_hdr_count); - int *hdr_prpt_typ_block = new int[buf_size]; - int *hdr_irpt_typ_block = new int[buf_size]; - int *hdr_inst_typ_block = new int[buf_size]; + vector hdr_prpt_typ_block(buf_size); + vector hdr_irpt_typ_block(buf_size); + vector hdr_inst_typ_block(buf_size); for(int i_start=0; i_start NC_BUFFER_SIZE_32K) buf_size2 = NC_BUFFER_SIZE_32K; @@ -967,7 +955,7 @@ void NetcdfObsVars::read_pb_hdr_data(MetPointHeader &hdr_data) { if (has_hdr_prpt_typ_var) { // Get the corresponding header PB message type (string) if(!get_nc_data(&hdr_prpt_typ_var, - hdr_prpt_typ_block, lengths, offsets)) { + hdr_prpt_typ_block.data(), lengths, offsets)) { mlog << Error << "\n" << method_name << "trouble getting hdr_prpt_typ\n\n"; exit(1); @@ -977,7 +965,7 @@ void NetcdfObsVars::read_pb_hdr_data(MetPointHeader &hdr_data) { if (has_hdr_irpt_typ_var) { // Get the corresponding header In message type (string) if(!get_nc_data(&hdr_irpt_typ_var, - hdr_irpt_typ_block, lengths, offsets)) { + hdr_irpt_typ_block.data(), lengths, offsets)) { mlog << Error << "\n" << method_name << "trouble getting hdr_irpt_typ\n\n"; exit(1); @@ -987,7 +975,7 @@ void NetcdfObsVars::read_pb_hdr_data(MetPointHeader &hdr_data) { if (has_hdr_inst_typ_var) { // Get the corresponding header instrument type (string) if(!get_nc_data(&hdr_inst_typ_var, - hdr_inst_typ_block, lengths, offsets)) { + hdr_inst_typ_block.data(), lengths, offsets)) { mlog << Error << "\n" << method_name << "trouble getting hdr_inst_typ\n\n"; exit(1); @@ -1001,10 +989,6 @@ void NetcdfObsVars::read_pb_hdr_data(MetPointHeader &hdr_data) { } } - delete[] hdr_prpt_typ_block; - delete[] hdr_irpt_typ_block; - delete[] hdr_inst_typ_block; - } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index a51eea0675..6a8aeead58 100644 --- a/src/libcode/vx_python3_utils/wchar_argv.cc +++ b/src/libcode/vx_python3_utils/wchar_argv.cc @@ -198,14 +198,11 @@ clear(); int j, k; int argv_len; -int * len = nullptr; +vector len(_argc); Argc = _argc; -len = new int [Argc]; - - // // total length of the argument string ... // @@ -285,8 +282,6 @@ for (j=0; j val(Nxy); // Compute the requested percentile of intensity for(int i=0; i Index(2*data.ny()); - if ( !Index ) { - - mlog << Error << "\nShapedata::convex_hull() -> " - << "memory allocation error\n\n"; - exit(1); - } + //if ( !Index ) { + // + // mlog << Error << "\nShapedata::convex_hull() -> " + // << "memory allocation error\n\n"; + // exit(1); + //} n = 0; @@ -889,8 +884,6 @@ Polyline ShapeData::convex_hull_old() const // done // - delete [] Index; Index = (int *) nullptr; - return hull; } diff --git a/src/tools/core/mode/mode_exec.cc b/src/tools/core/mode/mode_exec.cc index 2ee853f30b..943b57ae9a 100644 --- a/src/tools/core/mode/mode_exec.cc +++ b/src/tools/core/mode/mode_exec.cc @@ -1704,15 +1704,15 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) 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; + vector fcst_raw_data ; + vector fcst_obj_raw_data; + vector fcst_obj_data ; + vector fcst_clus_data ; - 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; + vector obs_raw_data ; + vector obs_obj_raw_data; + vector obs_obj_data ; + vector obs_clus_data ; NcFile *f_out = (NcFile *) nullptr; @@ -1917,29 +1917,29 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) if ( info.do_raw ) { - fcst_raw_data = new float [grid.nx()*grid.ny()]; - obs_raw_data = new float [grid.nx()*grid.ny()]; + fcst_raw_data.resize(grid.nx()*grid.ny()); + obs_raw_data.resize(grid.nx()*grid.ny()); } if ( info.do_object_raw ) { - fcst_obj_raw_data = new float [grid.nx()*grid.ny()]; - obs_obj_raw_data = new float [grid.nx()*grid.ny()]; + fcst_obj_raw_data.resize(grid.nx()*grid.ny()); + obs_obj_raw_data.resize(grid.nx()*grid.ny()); } if ( info.do_object_id ) { - fcst_obj_data = new int [grid.nx()*grid.ny()]; - obs_obj_data = new int [grid.nx()*grid.ny()]; + fcst_obj_data.resize(grid.nx()*grid.ny()); + obs_obj_data.resize(grid.nx()*grid.ny()); } if ( info.do_cluster_id ) { - fcst_clus_data = new int [grid.nx()*grid.ny()]; - obs_clus_data = new int [grid.nx()*grid.ny()]; + fcst_clus_data.resize(grid.nx()*grid.ny()); + obs_clus_data.resize(grid.nx()*grid.ny()); } @@ -1954,7 +1954,7 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) // Extra nullptr checks to satisfy Fortify if ( info.do_raw && - fcst_raw_data != nullptr && obs_raw_data != nullptr && + !fcst_raw_data.empty() && !obs_raw_data.empty() && engine.fcst_raw != nullptr && engine.obs_raw != nullptr ) { fcst_raw_data[n] = engine.fcst_raw->data (x, y); @@ -1963,35 +1963,35 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) } if(engine.fcst_split->is_nonzero(x, y) ) { - if ( info.do_object_raw && fcst_obj_raw_data != nullptr && engine.fcst_raw != nullptr ) { + if ( info.do_object_raw && !fcst_obj_raw_data.empty() && engine.fcst_raw != nullptr ) { fcst_obj_raw_data[n] = engine.fcst_raw->data(x, y); } - if ( info.do_object_id && fcst_obj_data != nullptr && engine.fcst_split != nullptr ) { + if ( info.do_object_id && !fcst_obj_data.empty() && engine.fcst_split != nullptr ) { fcst_obj_data[n] = nint(engine.fcst_split->data(x, y)); } } else { - if ( info.do_object_raw && fcst_obj_raw_data != nullptr ) { + if ( info.do_object_raw && !fcst_obj_raw_data.empty() ) { fcst_obj_raw_data[n] = bad_data_float; } - if ( info.do_object_id && fcst_obj_data != nullptr ) { + if ( info.do_object_id && !fcst_obj_data.empty() ) { fcst_obj_data[n] = bad_data_int; } } if(engine.obs_split->is_nonzero(x, y) ) { - if ( info.do_object_raw && obs_obj_raw_data != nullptr ) { + if ( info.do_object_raw && !obs_obj_raw_data.empty() ) { obs_obj_raw_data[n] = engine.obs_raw->data(x, y); } - if ( info.do_object_id && obs_obj_data != nullptr ) { + if ( info.do_object_id && !obs_obj_data.empty() ) { obs_obj_data[n] = nint(engine.obs_split->data(x, y)); } } else { - if ( info.do_object_raw && obs_obj_raw_data != nullptr) { + if ( info.do_object_raw && !obs_obj_raw_data.empty()) { obs_obj_raw_data[n] = bad_data_float; } - if ( info.do_object_id && obs_obj_data != nullptr ) { + if ( info.do_object_id && !obs_obj_data.empty() ) { obs_obj_data[n] = bad_data_int; } } @@ -2000,7 +2000,7 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) // Get cluster object ID's for each grid box // - if ( info.do_cluster_id && fcst_clus_data != nullptr && obs_clus_data != nullptr) { + if ( info.do_cluster_id && !fcst_clus_data.empty() && !obs_clus_data.empty()) { // Write the index of the cluster object if ( engine.fcst_clus_split->data(x, y) > 0 ) { @@ -2040,8 +2040,8 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) 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()) ) { + if( !put_nc_data_with_dims(&fcst_raw_var, fcst_raw_data.data(), grid.ny(), grid.nx()) || + !put_nc_data_with_dims(&obs_raw_var, obs_raw_data.data(), grid.ny(), grid.nx()) ) { mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " << "error with the fcst_raw_var->put or obs_raw_var->put\n\n"; @@ -2052,8 +2052,8 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) 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()) ) { + if( !put_nc_data_with_dims(&fcst_obj_raw_var, fcst_obj_raw_data.data(), grid.ny(), grid.nx()) || + !put_nc_data_with_dims(&obs_obj_raw_var, obs_obj_raw_data.data(), 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"; @@ -2068,8 +2068,8 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) 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()) ) { + if( !put_nc_data_with_dims(&fcst_obj_var, fcst_obj_data.data(), grid.ny(), grid.nx()) || + !put_nc_data_with_dims(&obs_obj_var, obs_obj_data.data(), grid.ny(), grid.nx()) ) { mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " << "error with the fcst_obj_var->put or obs_obj_var->put\n\n"; @@ -2084,8 +2084,8 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) 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()) ) { + if( !put_nc_data_with_dims(&fcst_clus_var, fcst_clus_data.data(), grid.ny(), grid.nx()) || + !put_nc_data_with_dims(&obs_clus_var, obs_clus_data.data(), grid.ny(), grid.nx()) ) { mlog << Error << "\nModeExecutive::write_obj_netcdf() -> " << "error with the fcst_clus_var->put or obs_clus_var->put\n\n"; @@ -2094,20 +2094,6 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) } - // - // 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 (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; } - // // Write out the values of the vertices of the polylines. // @@ -2185,13 +2171,6 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) Polyline **poly = (Polyline **) 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; - // Dimensions and variables for each object NcDim obj_dim ; NcVar obj_poly_start_var ; @@ -2368,12 +2347,12 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Allocate memory for the polyline points // - poly_start = new int [n_poly]; - poly_npts = new int [n_poly]; - poly_lat = new float [n_pts]; - poly_lon = new float [n_pts]; - poly_x = new int [n_pts]; - poly_y = new int [n_pts]; + vector poly_start(n_poly); + vector poly_npts (n_poly); + vector poly_lat (n_pts); + vector poly_lon (n_pts); + vector poly_x (n_pts); + vector poly_y (n_pts); // // Store the points for each polyline @@ -2404,8 +2383,8 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Write the polyline information // - if( !put_nc_data_with_dims(&obj_poly_start_var, &poly_start[0], n_poly) || - !put_nc_data_with_dims(&obj_poly_npts_var, &poly_npts[0], n_poly) ) { + if( !put_nc_data_with_dims(&obj_poly_start_var, poly_start.data(), n_poly) || + !put_nc_data_with_dims(&obj_poly_npts_var, poly_npts.data(), n_poly) ) { mlog << Error << "\nModeExecutive::write_poly_netcdf() -> " << "error with " << start_var_name << "->put or " @@ -2416,8 +2395,8 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Write the forecast boundary lat/lon points // - if( !put_nc_data_with_dims(&poly_lat_var, &poly_lat[0], n_pts) || - !put_nc_data_with_dims(&poly_lon_var, &poly_lon[0], n_pts) ) { + if( !put_nc_data_with_dims(&poly_lat_var, poly_lat.data(), n_pts) || + !put_nc_data_with_dims(&poly_lon_var, poly_lon.data(), n_pts) ) { mlog << Error << "\nModeExecutive::write_poly_netcdf() -> " << "error with " << lat_var_name << "->put or " @@ -2428,8 +2407,8 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Write the forecast boundary (x,y) points // - if( !put_nc_data_with_dims(&poly_x_var, &poly_x[0], n_pts) || - !put_nc_data_with_dims(&poly_y_var, &poly_y[0], n_pts) ) { + if( !put_nc_data_with_dims(&poly_x_var, poly_x.data(), n_pts) || + !put_nc_data_with_dims(&poly_y_var, poly_y.data(), n_pts) ) { mlog << Error << "\nModeExecutive::write_poly_netcdf() -> " << "error with " << x_var_name << "->put or" @@ -2437,17 +2416,6 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) exit(1); } - // - // Delete allocated memory - // - if(poly) { delete [] poly; poly = (Polyline **) nullptr; } - if(poly_start) { delete [] poly_start; poly_start = (int *) nullptr; } - if(poly_npts) { delete [] poly_npts; poly_npts = (int *) nullptr; } - if(poly_lat) { delete [] poly_lat; poly_lat = (float *) nullptr; } - if(poly_lon) { delete [] poly_lon; poly_lon = (float *) nullptr; } - if(poly_x) { delete [] poly_x; poly_x = (int *) nullptr; } - if(poly_y) { delete [] poly_y; poly_y = (int *) nullptr; } - return; } diff --git a/src/tools/other/lidar2nc/lidar2nc.cc b/src/tools/other/lidar2nc/lidar2nc.cc index ef30b1aa29..4dc6134397 100644 --- a/src/tools/other/lidar2nc/lidar2nc.cc +++ b/src/tools/other/lidar2nc/lidar2nc.cc @@ -370,7 +370,7 @@ else s << " on host " << junk; // allocate the buffer // -int * const ibuf = new int [n_data]; +vector ibuf(n_data, 0); mlog << Debug(2) << "Processing Lidar points\t= " << n_data << "\n"; @@ -379,17 +379,17 @@ mlog << Debug(2) << "Processing Lidar points\t= " << n_data << "\n"; // populate the hdr_typ variable // -memset(ibuf, 0, n_data*sizeof(int)); +//memset(ibuf, 0, n_data*sizeof(int)); -obs_vars->hdr_typ_var.putVar(ibuf); +obs_vars->hdr_typ_var.putVar(ibuf.data()); // // populate the hdr_sid variable // -memset(ibuf, 0, n_data*sizeof(int)); +//memset(ibuf, 0, n_data*sizeof(int)); -obs_vars->hdr_sid_var.putVar(ibuf); +obs_vars->hdr_sid_var.putVar(ibuf.data()); nc_point_obs.add_header_strings(hdr_typ_string, na_str); // @@ -401,13 +401,9 @@ nc_point_obs.add_header_strings(hdr_typ_string, na_str); float ff[2]; -float *fhdr_lat_buf = new float[n_data]; -float *fhdr_lon_buf = new float[n_data]; -float *fhdr_elv_buf = new float[n_data]; - -memset(fhdr_lat_buf, 0, n_data * sizeof(float)); -memset(fhdr_lon_buf, 0, n_data * sizeof(float)); -memset(fhdr_elv_buf, 0, n_data * sizeof(float)); +vector fhdr_lat_buf(n_data, 0.0); +vector fhdr_lon_buf(n_data, 0.0); +vector fhdr_elv_buf(n_data, 0.0); for (j=0; jhdr_lat_var.putVar(fhdr_lat_buf); -obs_vars->hdr_lon_var.putVar(fhdr_lon_buf); -obs_vars->hdr_elv_var.putVar(fhdr_elv_buf); +obs_vars->hdr_lat_var.putVar(fhdr_lat_buf.data()); +obs_vars->hdr_lon_var.putVar(fhdr_lon_buf.data()); +obs_vars->hdr_elv_var.putVar(fhdr_elv_buf.data()); -delete [] fhdr_lat_buf; -delete [] fhdr_lon_buf; -delete [] fhdr_elv_buf; - // // populate the hdr_vld variable // @@ -441,7 +433,7 @@ unixtime t; get_hdf_var_info(hdf_sd_id, hdf_time_name, info); -memset(ibuf, 0, n_data*sizeof(int)); +//memset(ibuf, 0, n_data*sizeof(int)); for (j=0; jhdr_vld_var.putVar(ibuf); +obs_vars->hdr_vld_var.putVar(ibuf.data()); -delete[] ibuf; - // // populate the obs_arr variable // @@ -585,7 +575,7 @@ void write_nc_record(const float * f, int qc_value) snprintf(junk, sizeof(junk), "%d", qc_value); nc_point_obs.write_observation(f, junk); } - + return; } From e59a1408169d191735883af404335f141e471fa4 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 10 Oct 2024 22:59:22 +0000 Subject: [PATCH 02/16] #2673 Check if a vector is allocated --- src/basic/vx_util/num_array.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/basic/vx_util/num_array.cc b/src/basic/vx_util/num_array.cc index 5a7fcee4c9..06452934f3 100644 --- a/src/basic/vx_util/num_array.cc +++ b/src/basic/vx_util/num_array.cc @@ -652,14 +652,14 @@ int NumArray::rank_array(int &ties) vector data_loc (n); vector data_rank (n); - //if ( !data || !data_loc || !data_rank ) { - // - // mlog << Error << "\nint NumArray::rank_array() -> " - // << "memory allocation error\n\n"; - // - // exit ( 1 ); - // - //} + if ( data.size() < n || data_loc.size() < n || data_rank.size() < n) { + + mlog << Error << "\nint NumArray::rank_array() -> " + << "memory allocation error\n\n"; + + exit ( 1 ); + + } // // Search the data array for valid data and keep track of its location From 15c2f3fe1428937c2b45776770d3e42c36684c62 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 10 Oct 2024 22:59:37 +0000 Subject: [PATCH 03/16] #2673 Check if a vector is allocated --- src/libcode/vx_shapedata/shapedata.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libcode/vx_shapedata/shapedata.cc b/src/libcode/vx_shapedata/shapedata.cc index 0c429d7694..f3a8dc14f2 100644 --- a/src/libcode/vx_shapedata/shapedata.cc +++ b/src/libcode/vx_shapedata/shapedata.cc @@ -733,12 +733,12 @@ Polyline ShapeData::convex_hull_old() const vector Index(2*data.ny()); - //if ( !Index ) { - // - // mlog << Error << "\nShapedata::convex_hull() -> " - // << "memory allocation error\n\n"; - // exit(1); - //} + if ( Index.size() < 2*data.ny() ) { + + mlog << Error << "\nShapedata::convex_hull() -> " + << "memory allocation error\n\n"; + exit(1); + } n = 0; @@ -1891,7 +1891,7 @@ void ShapeData::threshold(SingleThresh t) { /////////////////////////////////////////////////////////////////////////////// -void ShapeData::set_to_1_or_0() +void ShapeData::set_to_1_or_0() { int j; double v; From 34d6ffd2bce849fec3d74a6943040c86a7309b5e Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 10 Oct 2024 23:28:19 +0000 Subject: [PATCH 04/16] #2673 SonarQube findings use vector --- src/libcode/vx_python3_utils/wchar_argv.cc | 53 ++++++++++------------ 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index 6a8aeead58..271a6468a4 100644 --- a/src/libcode/vx_python3_utils/wchar_argv.cc +++ b/src/libcode/vx_python3_utils/wchar_argv.cc @@ -96,9 +96,9 @@ void Wchar_Argv::init_from_scratch() { -W_Buf = 0; +W_Buf = nullptr; -W_Argv = 0; +W_Argv = nullptr; return; @@ -134,8 +134,7 @@ void Wchar_Argv::set(const StringArray & a) int j, k, N; int len; -char * s = nullptr; -char ** av = nullptr; + ConcatString c; const char *method_name = "Wchar_Argv::set() -> "; @@ -150,38 +149,32 @@ for (j=0; j<(a.n()); ++j) { N = len + a.n(); -s = new char [N]; - -av = new char * [a.n()]; +vector s(N, 0); -memset(s, 0, N); +vector av((a.n()); k = 0; for (j=0; j<(a.n()); ++j) { - av[j] = s + k; + av[j] = s.data() + k; c = a[j].c_str(); len = c.length(); - m_strncpy(s + k, c.text(), len, method_name); + m_strncpy(s.data() + k, c.text(), len, method_name); k += (len + 1); } -set(a.n(), av); +set(a.n(), av.data()); // // done // -if ( s ) { delete [] s; s = nullptr; } - -if ( av ) { delete [] av; av = nullptr; } - return; } @@ -196,26 +189,30 @@ void Wchar_Argv::set(int _argc, char ** _argv) clear(); -int j, k; -int argv_len; -vector len(_argc); +int k; Argc = _argc; +vectorlen(Argc); + + // // total length of the argument string ... // -argv_len = 0; +int argv_len = 0; +int argv_buf_len = sizeof(_argv)/sizeof(*_argv); -for (j=0; j<_argc; ++j) { +for (int j=0; j<_argc; ++j) { - len[j] = m_strlen(_argv[j]); // we're using the len array here because - // we don't want to call m_strlen more than - // once on each argv value - - argv_len += len[j]; + if (j < argv_buf_len) { + len[j] = m_strlen(_argv[j]); // we're using the len array here because + // we don't want to call m_strlen more than + // once on each argv value + + argv_len += len[j]; + } ++argv_len; // ... including the end-of-string sentinels (ie, nul chars); @@ -232,7 +229,7 @@ for (j=0; j<_argc; ++j) { W_Buf = new wchar_t [argv_len]; -for (j=0; j Date: Fri, 11 Oct 2024 02:12:35 +0000 Subject: [PATCH 05/16] #2673 Resolved SonarQube findingds --- scripts/python/met/logger.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/scripts/python/met/logger.py b/scripts/python/met/logger.py index a85de36d1f..1e7b30a798 100644 --- a/scripts/python/met/logger.py +++ b/scripts/python/met/logger.py @@ -25,10 +25,6 @@ def error_message(msg): for a_msg in msgs: logger.log_message(logger.append_error_prompt(a_msg)) - #@staticmethod - #def get_met_fill_value(): - # return logger.MET_FILL_VALUE - @staticmethod def info_message(msg): print(f'{logger.PROMPT} {logger.INFO_P} {msg}') @@ -78,8 +74,8 @@ def log_msg(self, msg): @staticmethod def get_numpy_filename(tmp_filename): - return logger.replace_extension(tmp_filename, "json", "npy") if tmp_filename.endswith(".json") else \ - logger.replace_extension(tmp_filename, "nc", "npy") if tmp_filename.endswith(".nc") else f'{tmp_filename}.npy' + file_ext = os.path.splitext(tmp_filename)[1] + return logger.replace_extension(tmp_filename, file_ext, ".npy") if file_ext else f'{tmp_filename}.npy' def is_debug_enabled(self, component_name=""): return met_base_tools.is_debug_enabled(component_name) @@ -99,22 +95,27 @@ class met_base_tools(object): ENV_MET_PYTHON_DEBUG = "MET_PYTHON_DEBUG" ENV_MET_PYTHON_TMP_FORMAT = "MET_PYTHON_TMP_FORMAT" + @staticmethod + def convert_byte_type_to_array(ndarray_data): + array_data = [] + if isinstance(ndarray_data[0], (np.ma.MaskedArray, np.ma.core.MaskedArray)): + for byte_data in ndarray_data: + array_data.append(byte_data.tobytes(fill_value=' ').decode('utf-8').rstrip()) + else: + for byte_data in ndarray_data: + array_data.append(byte_data.decode("utf-8").rstrip()) + return array_data + @staticmethod def convert_to_array(ndarray_data): is_byte_type = False if 0 < len(ndarray_data): is_byte_type = isinstance(ndarray_data[0], (bytes, np.bytes_)) - if isinstance(ndarray_data[0], np.ndarray): - if 0 < len(ndarray_data[0]): - is_byte_type = isinstance(ndarray_data[0][0], (bytes, np.bytes_)) + if not is_byte_type and isinstance(ndarray_data[0], np.ndarray) \ + and 0 < len(ndarray_data[0]): + is_byte_type = isinstance(ndarray_data[0][0], (bytes, np.bytes_)) if is_byte_type: - array_data = [] - if isinstance(ndarray_data[0], (np.ma.MaskedArray, np.ma.core.MaskedArray)): - for byte_data in ndarray_data: - array_data.append(byte_data.tobytes(fill_value=' ').decode('utf-8').rstrip()) - else: - for byte_data in ndarray_data: - array_data.append(byte_data.decode("utf-8").rstrip()) + array_data = met_base_tools.convert_byte_type_to_array(ndarray_data) elif isinstance(ndarray_data, (np.ma.MaskedArray, np.ma.core.MaskedArray)): array_data = ndarray_data.filled(fill_value=-9999).tolist() elif isinstance(ndarray_data, np.ndarray): From 541a005d742793b63d843cc6e7716cb9338ea7fe Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Fri, 11 Oct 2024 02:14:15 +0000 Subject: [PATCH 06/16] #2673 SonarQube: Replaced f-strings to regular strings --- scripts/python/met/point.py | 73 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/scripts/python/met/point.py b/scripts/python/met/point.py index 05e3054ba3..46576c8e59 100644 --- a/scripts/python/met/point.py +++ b/scripts/python/met/point.py @@ -181,9 +181,6 @@ def check_point_data(self): if self.use_var_id: self.check_data_member_string(self.obs_var_table,'obs_var_table') - #def convert_to_numpy(self, value_list): - # return met_point_tools.convert_to_ndarray(value_list) - def dump(self): met_point_tools.print_point_data(self.get_point_data()) @@ -346,7 +343,7 @@ def write_point_data(self, tmp_filename): nc_point_obs.write_nc_file(tmp_filename, self) if met_base_tools.is_debug_enabled("point"): - met_base.log_message(f"Save to a temporary NetCDF file (point)") + met_base.log_message("Save to a temporary NetCDF file (point)") else: self.write_point_data_json_numpy(tmp_filename) @@ -417,8 +414,8 @@ def __init__(self, point_data): def check_csv_record(self, csv_point_data, index): method_name = f"{self.__class__.__name__}.check_csv_record()" error_msgs = [] - # names=['typ', 'sid', 'vld', 'lat', 'lon', 'elv', 'var', 'lvl', 'hgt', 'qc', 'obs'] - # dtype={'typ':'str', 'sid':'str', 'vld':'str', 'var':'str', 'qc':'str'} + # names: ['typ', 'sid', 'vld', 'lat', 'lon', 'elv', 'var', 'lvl', 'hgt', 'qc', 'obs'] + # dtype: {'typ':'str', 'sid':'str', 'vld':'str', 'var':'str', 'qc':'str'} if 11 > len(csv_point_data): error_msgs.append(f"{method_name} {index}-th data: missing columns. should be 11 columns, not {len(csv_point_data)} columns") elif 11 < len(csv_point_data): @@ -488,7 +485,7 @@ def convert_point_data(self): self.use_var_id = not self.is_grib_code() index = 0 - #names=['typ', 'sid', 'vld', 'lat', 'lon', 'elv', 'var', 'lvl', 'hgt', 'qc', 'obs'] + #name: ['typ', 'sid', 'vld', 'lat', 'lon', 'elv', 'var', 'lvl', 'hgt', 'qc', 'obs'] for csv_point_record in self.point_data: # Build header map. hdr_typ_str = csv_point_record[0] @@ -539,7 +536,7 @@ def convert_point_data(self): obs_qty_map[qc_str] = qc_id qc_cnt += 1 - # names=['typ', 'sid', 'vld', 'lat', 'lon', 'elv', 'var', 'lvl', 'hgt', 'qc', 'obs'] + # names: ['typ', 'sid', 'vld', 'lat', 'lon', 'elv', 'var', 'lvl', 'hgt', 'qc', 'obs'] self.obs_vid[index] = var_id self.obs_hid[index] = hdr_idx self.obs_lvl[index] = self.get_num_value(csv_point_record[7]) @@ -627,21 +624,21 @@ def read_data(self, args): # - set self.input_name # # Here is a template - ''' - if isinstance(args, dict): - in_filename = args.get('in_name',None) - elif isinstance(args, list): - in_filename = args[0] - else: - in_filename = args - self.input_name = in_filename - ''' + # + # if isinstance(args, dict): + # in_filename = args.get('in_name',None) + # elif isinstance(args, list): + # in_filename = args[0] + # else: + # in_filename = args + # self.input_name = in_filename pass class dummy_point_obs(met_point_obs): def read_data(self, args): + # Do nothing to return an empty point_obs pass @@ -689,7 +686,7 @@ def print_data(key, data_array, show_count=COUNT_SHOW): @staticmethod def print_point_data(met_point_data, print_subset=True): - method_name = f"met_point_tools.print_point_data()" + method_name = "met_point_tools.print_point_data()" print(' === MET point data by python embedding ===') if print_subset: met_point_tools.print_data('nhdr',met_point_data['nhdr']) @@ -714,26 +711,26 @@ def print_point_data(met_point_data, print_subset=True): met_point_tools.print_data('obs_val',met_point_data['obs_val']) else: print(f'{method_name} All',met_point_data) - print(f" nhdr: met_point_data['nhdr']") - print(f" nobs: met_point_data['nobs']") - print(f" use_var_id: met_point_data['use_var_id']") - print(f" hdr_typ: met_point_data['hdr_typ']") - print(f"hdr_typ_table: met_point_data['hdr_typ_table']") - print(f" hdr_sid: met_point_data['hdr_sid']") - print(f"hdr_sid_table: met_point_data['hdr_sid_table']") - print(f" hdr_vld: met_point_data['hdr_vld']") - print(f"hdr_vld_table: met_point_data['hdr_vld_table']") - print(f" hdr_lat: met_point_data['hdr_lat']") - print(f" hdr_lon: met_point_data['hdr_lon']") - print(f" hdr_elv: met_point_data['hdr_elv']") - print(f" obs_hid: met_point_data['obs_hid']") - print(f" obs_vid: met_point_data['obs_vid']") - print(f"obs_var_table: met_point_data['obs_var_table']") - print(f" obs_qty: met_point_data['obs_qty']") - print(f"obs_qty_table: met_point_data['obs_qty_table']") - print(f" obs_lvl: met_point_data['obs_lvl']") - print(f" obs_hgt: met_point_data['obs_hgt']") - print(f" obs_val: met_point_data['obs_val']") + print(" nhdr: met_point_data['nhdr']") + print(" nobs: met_point_data['nobs']") + print(" use_var_id: met_point_data['use_var_id']") + print(" hdr_typ: met_point_data['hdr_typ']") + print("hdr_typ_table: met_point_data['hdr_typ_table']") + print(" hdr_sid: met_point_data['hdr_sid']") + print("hdr_sid_table: met_point_data['hdr_sid_table']") + print(" hdr_vld: met_point_data['hdr_vld']") + print("hdr_vld_table: met_point_data['hdr_vld_table']") + print(" hdr_lat: met_point_data['hdr_lat']") + print(" hdr_lon: met_point_data['hdr_lon']") + print(" hdr_elv: met_point_data['hdr_elv']") + print(" obs_hid: met_point_data['obs_hid']") + print(" obs_vid: met_point_data['obs_vid']") + print("obs_var_table: met_point_data['obs_var_table']") + print(" obs_qty: met_point_data['obs_qty']") + print("obs_qty_table: met_point_data['obs_qty_table']") + print(" obs_lvl: met_point_data['obs_lvl']") + print(" obs_hgt: met_point_data['obs_hgt']") + print(" obs_val: met_point_data['obs_val']") print(' === MET point data by python embedding ===') From 0eb721c6c62e6226b9f2d02c991a0c697c6863da Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Fri, 11 Oct 2024 02:14:57 +0000 Subject: [PATCH 07/16] #2673 Added staticmethod to read_mpr --- scripts/python/met/mprbase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/python/met/mprbase.py b/scripts/python/met/mprbase.py index 0615171313..40cc36f7fb 100644 --- a/scripts/python/met/mprbase.py +++ b/scripts/python/met/mprbase.py @@ -6,6 +6,7 @@ class mpr_data(): # Read a text file with N columns and returns the list of N column data # Skip first "col_start" columns if col_start is not 0. + @staticmethod def read_mpr(input_file, col_last, col_start = 0, header=None, delim_whitespace=True, keep_default_na=False, skiprows=1, dtype='string'): From ab8a51a1e284b000f67cfc3da800f176c809be55 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Fri, 11 Oct 2024 02:15:43 +0000 Subject: [PATCH 08/16] #2673 SonarQube: removed unnecessary pass --- scripts/python/examples/read_ascii_numpy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/python/examples/read_ascii_numpy.py b/scripts/python/examples/read_ascii_numpy.py index 342121f2ff..061e1aa250 100644 --- a/scripts/python/examples/read_ascii_numpy.py +++ b/scripts/python/examples/read_ascii_numpy.py @@ -85,7 +85,6 @@ def set_dataplane_attrs(): user_fill_value = float(sys.argv[3]) except: log(f"{SCRIPT_NAME} Ignored argument {sys.argv[3]}") - pass log(f"{SCRIPT_NAME} Input File:\t{repr(input_file)}") log(f"{SCRIPT_NAME} Data Name:\t{repr(data_name)}") From b2249ea2b5ae5688fe18404bf0bc5828574371a6 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Fri, 11 Oct 2024 02:25:15 +0000 Subject: [PATCH 09/16] #2673 SonarQube: use vector --- src/libcode/vx_python3_utils/wchar_argv.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index 271a6468a4..aff0e5f512 100644 --- a/src/libcode/vx_python3_utils/wchar_argv.cc +++ b/src/libcode/vx_python3_utils/wchar_argv.cc @@ -151,7 +151,7 @@ N = len + a.n(); vector s(N, 0); -vector av((a.n()); +vector av(a.n()); k = 0; From 9707f601ea14e19c54498e0a9085755260a7e24f Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Mon, 14 Oct 2024 22:04:16 +0000 Subject: [PATCH 10/16] #2673 Initialize vecvgtor variables --- src/tools/core/mode/mode_exec.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/tools/core/mode/mode_exec.cc b/src/tools/core/mode/mode_exec.cc index 12206cabce..475bc9e72b 100644 --- a/src/tools/core/mode/mode_exec.cc +++ b/src/tools/core/mode/mode_exec.cc @@ -2347,17 +2347,18 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Allocate memory for the polyline points // - vector poly_start(n_poly); - vector poly_npts (n_poly); - vector poly_lat (n_pts); - vector poly_lon (n_pts); - vector poly_x (n_pts); - vector poly_y (n_pts); + vector poly_start(n_poly, 0); + vector poly_npts (n_poly, 0); + vector poly_lat (n_pts, bad_data_float); + vector poly_lon (n_pts, bad_data_float); + vector poly_x (n_pts, 0); + vector poly_y (n_pts, 0); // // Store the points for each polyline // - for(i=0, n_pts=0; i Date: Tue, 15 Oct 2024 17:18:34 +0000 Subject: [PATCH 11/16] 673 Check if an user python command is empty --- scripts/python/met/dataplane.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/python/met/dataplane.py b/scripts/python/met/dataplane.py index 468bbd6e44..4d94c0e712 100644 --- a/scripts/python/met/dataplane.py +++ b/scripts/python/met/dataplane.py @@ -25,6 +25,9 @@ def call_python(argv): sys.exit(1) met_base.log_message(f"User python command:\t{repr(' '.join(argv[1:]))}") + if not argv[1] or not argv[1].strip(): + met_base.quit_msg(f"User python command is empty") + sys.exit(1) # argv[1] contains the user defined python script pyembed_module_name = argv[1] From 52a785b7f4d66d268781a8bd458031fa45171858 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 15 Oct 2024 17:19:04 +0000 Subject: [PATCH 12/16] #2673 Changed 0 to nullptr --- src/libcode/vx_data2d_python/python_dataplane.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcode/vx_data2d_python/python_dataplane.cc b/src/libcode/vx_data2d_python/python_dataplane.cc index 9f53bb7cf8..6921b1eed6 100644 --- a/src/libcode/vx_data2d_python/python_dataplane.cc +++ b/src/libcode/vx_data2d_python/python_dataplane.cc @@ -114,11 +114,11 @@ bool straight_python_dataplane(const char * user_script_name, { -PyObject * module_obj = 0; -PyObject * module_dict_obj = 0; -PyObject * key_obj = 0; -PyObject * numpy_array_obj = 0; -PyObject * attrs_dict_obj = 0; +PyObject * module_obj = nullptr; +PyObject * module_dict_obj = nullptr; +PyObject * key_obj = nullptr; +PyObject * numpy_array_obj = nullptr; +PyObject * attrs_dict_obj = nullptr; ConcatString cs, user_dir, user_base; const char *method_name = "straight_python_dataplane() -> "; From ff8914a96fd83d688d657441a54e028f9887339c Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 15 Oct 2024 17:28:15 +0000 Subject: [PATCH 13/16] #2673 Rollback for s and av --- src/libcode/vx_python3_utils/wchar_argv.cc | 52 ++++++++++------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/libcode/vx_python3_utils/wchar_argv.cc b/src/libcode/vx_python3_utils/wchar_argv.cc index aff0e5f512..d05953c120 100644 --- a/src/libcode/vx_python3_utils/wchar_argv.cc +++ b/src/libcode/vx_python3_utils/wchar_argv.cc @@ -132,49 +132,51 @@ void Wchar_Argv::set(const StringArray & a) { -int j, k, N; -int len; - +int k = 0; +int len = 0; ConcatString c; const char *method_name = "Wchar_Argv::set() -> "; -len = 0; - -for (j=0; j<(a.n()); ++j) { +for (int j=0; j<(a.n()); ++j) { len += a.length(j); } -N = len + a.n(); +int N = len + a.n(); -vector s(N, 0); +char * s = new char [N]; -vector av(a.n()); +char ** av = new char * [a.n()]; + +memset(s, 0, N); -k = 0; -for (j=0; j<(a.n()); ++j) { +for (int j=0; j<(a.n()); ++j) { - av[j] = s.data() + k; + av[j] = s + k; c = a[j].c_str(); len = c.length(); - m_strncpy(s.data() + k, c.text(), len, method_name); + m_strncpy(s + k, c.text(), len, method_name); k += (len + 1); } -set(a.n(), av.data()); +set(a.n(), av); // // done // +if ( s ) { delete [] s; s = nullptr; } + +if ( av ) { delete [] av; av = nullptr; } + return; } @@ -187,32 +189,26 @@ void Wchar_Argv::set(int _argc, char ** _argv) { -clear(); - int k; +int argv_len = 0; +vector len(_argc, 0); +clear(); Argc = _argc; -vectorlen(Argc); - // // total length of the argument string ... // -int argv_len = 0; -int argv_buf_len = sizeof(_argv)/sizeof(*_argv); - for (int j=0; j<_argc; ++j) { - if (j < argv_buf_len) { - len[j] = m_strlen(_argv[j]); // we're using the len array here because - // we don't want to call m_strlen more than - // once on each argv value - - argv_len += len[j]; - } + len[j] = m_strlen(_argv[j]); // we're using the len array here because + // we don't want to call m_strlen more than + // once on each argv value + + argv_len += len[j]; ++argv_len; // ... including the end-of-string sentinels (ie, nul chars); From 5fa80136c18840bf1f817d9153b882ac1bbb8dd3 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 15 Oct 2024 17:50:04 +0000 Subject: [PATCH 14/16] #2673 Applied the static method call --- src/tools/other/gen_vx_mask/gen_vx_mask.cc | 114 +++++++++++---------- 1 file changed, 62 insertions(+), 52 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 1c7f77c002..83fe7cc568 100644 --- a/src/tools/other/gen_vx_mask/gen_vx_mask.cc +++ b/src/tools/other/gen_vx_mask/gen_vx_mask.cc @@ -401,9 +401,8 @@ void get_data_plane(const ConcatString &file_name, } // Attempt to open the data file - Met2dDataFileFactory mtddf_factory; - Met2dDataFile *mtddf_ptr = (Met2dDataFile *) nullptr; - mtddf_ptr = mtddf_factory.new_met_2d_data_file(file_name.c_str(), ftype); + Met2dDataFile *mtddf_ptr = Met2dDataFileFactory::new_met_2d_data_file( + file_name.c_str(), ftype); if(!mtddf_ptr) { mlog << Error << "\nget_data_plane() -> " << "can't open input file \"" << file_name << "\"\n\n"; @@ -423,9 +422,7 @@ void get_data_plane(const ConcatString &file_name, if(local_cs.length() > 0) { // Allocate new VarInfo object - VarInfoFactory vi_factory; - VarInfo *vi_ptr = (VarInfo *) nullptr; - vi_ptr = vi_factory.new_var_info(mtddf_ptr->file_type()); + VarInfo *vi_ptr = VarInfoFactory::new_var_info(mtddf_ptr->file_type()); if(!vi_ptr) { mlog << Error << "\nget_data_plane() -> " << "can't allocate new VarInfo pointer.\n\n"; @@ -444,7 +441,8 @@ void get_data_plane(const ConcatString &file_name, } // Dump the range of data values read - double dmin, dmax; + double dmin; + double dmax; dp.data_range(dmin, dmax); mlog << Debug(3) << "Read field \"" << vi_ptr->magic_str() << "\" from \"" @@ -471,7 +469,6 @@ bool get_gen_vx_mask_config_str(MetNcMetDataFile *mnmdf_ptr, ConcatString &config_str) { bool status = false; ConcatString tool; - int i; // Check for null pointer if(!mnmdf_ptr) return status; @@ -483,7 +480,7 @@ bool get_gen_vx_mask_config_str(MetNcMetDataFile *mnmdf_ptr, if(tool != program_name) return status; // Loop through the NetCDF variables - for(i=0; iMetNc->Nvars; i++) { + for(int i=0; iMetNc->Nvars; i++) { // Skip the lat/lon variables if(mnmdf_ptr->MetNc->Var[i].name == "lat" || @@ -515,7 +512,7 @@ void get_shapefile_strings() { << dbf_filename << "\n"; // Open the database file - if(!(f.open(dbf_filename.c_str()))) { + if(!f.open(dbf_filename.c_str())) { mlog << Error << "\nget_shapefile_strings() -> " << "unable to open database file \"" << dbf_filename << "\"\n\n"; @@ -582,7 +579,7 @@ void get_shapefile_records() { } // Open shapefile - if(!(f.open(shape_filename))) { + if(!f.open(shape_filename)) { mlog << Error << "\nget_shapefile_records() -> " << "unable to open shape file \"" << shape_filename << "\"\n\n"; @@ -667,13 +664,14 @@ bool is_shape_str_match(const int i_shape, const StringArray &names, const Strin //////////////////////////////////////////////////////////////////////// void apply_poly_mask(DataPlane & dp) { - int x, y, n_in; + int n_in = 0; bool inside; - double lat, lon; + double lat; + double lon; // Check the Lat/Lon of each grid point being inside the polyline - for(x=0,n_in=0; x::const_iterator poly_it; for(poly_it = poly_list.begin(); @@ -1285,7 +1295,7 @@ void apply_shape_mask(DataPlane & dp) { DataPlane combine(const DataPlane &dp_data, const DataPlane &dp_mask, SetLogic logic) { - int x, y, n_in; + int n_in = 0; bool v_data, v_mask; double v; DataPlane dp; @@ -1309,8 +1319,8 @@ DataPlane combine(const DataPlane &dp_data, const DataPlane &dp_mask, dp.set_size(grid.nx(), grid.ny()); // Process each point - for(x=0,n_in=0; x mask_data(grid.nx()*grid.ny()); // Loop through each grid point - for(x=0; x Date: Tue, 15 Oct 2024 18:45:29 +0000 Subject: [PATCH 15/16] #2673 Rollback using vector because of introducing a bug --- src/tools/core/mode/mode_exec.cc | 124 +++++++++++++++++++------------ 1 file changed, 78 insertions(+), 46 deletions(-) diff --git a/src/tools/core/mode/mode_exec.cc b/src/tools/core/mode/mode_exec.cc index 475bc9e72b..db43b97ebe 100644 --- a/src/tools/core/mode/mode_exec.cc +++ b/src/tools/core/mode/mode_exec.cc @@ -1704,15 +1704,15 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) 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); - vector fcst_raw_data ; - vector fcst_obj_raw_data; - vector fcst_obj_data ; - vector fcst_clus_data ; + 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; - vector obs_raw_data ; - vector obs_obj_raw_data; - vector obs_obj_data ; - vector obs_clus_data ; + 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; NcFile *f_out = (NcFile *) nullptr; @@ -1917,29 +1917,29 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) if ( info.do_raw ) { - fcst_raw_data.resize(grid.nx()*grid.ny()); - obs_raw_data.resize(grid.nx()*grid.ny()); + fcst_raw_data = new float [grid.nx()*grid.ny()]; + obs_raw_data = new float [grid.nx()*grid.ny()]; } if ( info.do_object_raw ) { - fcst_obj_raw_data.resize(grid.nx()*grid.ny()); - obs_obj_raw_data.resize(grid.nx()*grid.ny()); + fcst_obj_raw_data = new float [grid.nx()*grid.ny()]; + obs_obj_raw_data = new float [grid.nx()*grid.ny()]; } if ( info.do_object_id ) { - fcst_obj_data.resize(grid.nx()*grid.ny()); - obs_obj_data.resize(grid.nx()*grid.ny()); + fcst_obj_data = new int [grid.nx()*grid.ny()]; + obs_obj_data = new int [grid.nx()*grid.ny()]; } if ( info.do_cluster_id ) { - fcst_clus_data.resize(grid.nx()*grid.ny()); - obs_clus_data.resize(grid.nx()*grid.ny()); + fcst_clus_data = new int [grid.nx()*grid.ny()]; + obs_clus_data = new int [grid.nx()*grid.ny()]; } @@ -1954,7 +1954,7 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) // Extra nullptr checks to satisfy Fortify if ( info.do_raw && - !fcst_raw_data.empty() && !obs_raw_data.empty() && + fcst_raw_data != nullptr && obs_raw_data != nullptr && engine.fcst_raw != nullptr && engine.obs_raw != nullptr ) { fcst_raw_data[n] = engine.fcst_raw->data (x, y); @@ -1963,35 +1963,35 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) } if(engine.fcst_split->is_nonzero(x, y) ) { - if ( info.do_object_raw && !fcst_obj_raw_data.empty() && engine.fcst_raw != nullptr ) { + 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); } - if ( info.do_object_id && !fcst_obj_data.empty() && engine.fcst_split != nullptr ) { + if ( info.do_object_id && fcst_obj_data != nullptr && engine.fcst_split != nullptr ) { fcst_obj_data[n] = nint(engine.fcst_split->data(x, y)); } } else { - if ( info.do_object_raw && !fcst_obj_raw_data.empty() ) { + if ( info.do_object_raw && fcst_obj_raw_data != nullptr ) { fcst_obj_raw_data[n] = bad_data_float; } - if ( info.do_object_id && !fcst_obj_data.empty() ) { + if ( info.do_object_id && fcst_obj_data != nullptr ) { fcst_obj_data[n] = bad_data_int; } } if(engine.obs_split->is_nonzero(x, y) ) { - if ( info.do_object_raw && !obs_obj_raw_data.empty() ) { + if ( info.do_object_raw && obs_obj_raw_data != nullptr ) { obs_obj_raw_data[n] = engine.obs_raw->data(x, y); } - if ( info.do_object_id && !obs_obj_data.empty() ) { + if ( info.do_object_id && obs_obj_data != nullptr ) { obs_obj_data[n] = nint(engine.obs_split->data(x, y)); } } else { - if ( info.do_object_raw && !obs_obj_raw_data.empty()) { + if ( info.do_object_raw && obs_obj_raw_data != nullptr) { obs_obj_raw_data[n] = bad_data_float; } - if ( info.do_object_id && !obs_obj_data.empty() ) { + if ( info.do_object_id && obs_obj_data != nullptr ) { obs_obj_data[n] = bad_data_int; } } @@ -2000,7 +2000,7 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) // Get cluster object ID's for each grid box // - if ( info.do_cluster_id && !fcst_clus_data.empty() && !obs_clus_data.empty()) { + if ( info.do_cluster_id && fcst_clus_data != nullptr && obs_clus_data != nullptr) { // Write the index of the cluster object if ( engine.fcst_clus_split->data(x, y) > 0 ) { @@ -2040,8 +2040,8 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) if ( info.do_raw ) { - if( !put_nc_data_with_dims(&fcst_raw_var, fcst_raw_data.data(), grid.ny(), grid.nx()) || - !put_nc_data_with_dims(&obs_raw_var, obs_raw_data.data(), grid.ny(), grid.nx()) ) { + 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"; @@ -2052,8 +2052,8 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) if ( info.do_object_raw ) { - if( !put_nc_data_with_dims(&fcst_obj_raw_var, fcst_obj_raw_data.data(), grid.ny(), grid.nx()) || - !put_nc_data_with_dims(&obs_obj_raw_var, obs_obj_raw_data.data(), grid.ny(), grid.nx()) ) { + 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"; @@ -2068,8 +2068,8 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) if ( info.do_object_id ) { - if( !put_nc_data_with_dims(&fcst_obj_var, fcst_obj_data.data(), grid.ny(), grid.nx()) || - !put_nc_data_with_dims(&obs_obj_var, obs_obj_data.data(), grid.ny(), grid.nx()) ) { + 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"; @@ -2084,8 +2084,8 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) if ( info.do_cluster_id ) { - if( !put_nc_data_with_dims(&fcst_clus_var, fcst_clus_data.data(), grid.ny(), grid.nx()) || - !put_nc_data_with_dims(&obs_clus_var, obs_clus_data.data(), grid.ny(), grid.nx()) ) { + 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"; @@ -2094,6 +2094,20 @@ void ModeExecutive::write_obj_netcdf(const ModeNcOutInfo & info) } + // + // 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 (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; } + // // Write out the values of the vertices of the polylines. // @@ -2171,6 +2185,13 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) Polyline **poly = (Polyline **) 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; + // Dimensions and variables for each object NcDim obj_dim ; NcVar obj_poly_start_var ; @@ -2347,12 +2368,12 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Allocate memory for the polyline points // - vector poly_start(n_poly, 0); - vector poly_npts (n_poly, 0); - vector poly_lat (n_pts, bad_data_float); - vector poly_lon (n_pts, bad_data_float); - vector poly_x (n_pts, 0); - vector poly_y (n_pts, 0); + poly_start = new int [n_poly]; + poly_npts = new int [n_poly]; + poly_lat = new float [n_pts]; + poly_lon = new float [n_pts]; + poly_x = new int [n_pts]; + poly_y = new int [n_pts]; // // Store the points for each polyline @@ -2384,8 +2405,8 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Write the polyline information // - if( !put_nc_data_with_dims(&obj_poly_start_var, poly_start.data(), n_poly) || - !put_nc_data_with_dims(&obj_poly_npts_var, poly_npts.data(), n_poly) ) { + if( !put_nc_data_with_dims(&obj_poly_start_var, &poly_start[0], n_poly) || + !put_nc_data_with_dims(&obj_poly_npts_var, &poly_npts[0], n_poly) ) { mlog << Error << "\nModeExecutive::write_poly_netcdf() -> " << "error with " << start_var_name << "->put or " @@ -2396,8 +2417,8 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Write the forecast boundary lat/lon points // - if( !put_nc_data_with_dims(&poly_lat_var, poly_lat.data(), n_pts) || - !put_nc_data_with_dims(&poly_lon_var, poly_lon.data(), n_pts) ) { + if( !put_nc_data_with_dims(&poly_lat_var, &poly_lat[0], n_pts) || + !put_nc_data_with_dims(&poly_lon_var, &poly_lon[0], n_pts) ) { mlog << Error << "\nModeExecutive::write_poly_netcdf() -> " << "error with " << lat_var_name << "->put or " @@ -2408,8 +2429,8 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Write the forecast boundary (x,y) points // - if( !put_nc_data_with_dims(&poly_x_var, poly_x.data(), n_pts) || - !put_nc_data_with_dims(&poly_y_var, poly_y.data(), n_pts) ) { + if( !put_nc_data_with_dims(&poly_x_var, &poly_x[0], n_pts) || + !put_nc_data_with_dims(&poly_y_var, &poly_y[0], n_pts) ) { mlog << Error << "\nModeExecutive::write_poly_netcdf() -> " << "error with " << x_var_name << "->put or" @@ -2417,6 +2438,17 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) exit(1); } + // + // Delete allocated memory + // + if(poly) { delete [] poly; poly = (Polyline **) nullptr; } + if(poly_start) { delete [] poly_start; poly_start = (int *) nullptr; } + if(poly_npts) { delete [] poly_npts; poly_npts = (int *) nullptr; } + if(poly_lat) { delete [] poly_lat; poly_lat = (float *) nullptr; } + if(poly_lon) { delete [] poly_lon; poly_lon = (float *) nullptr; } + if(poly_x) { delete [] poly_x; poly_x = (int *) nullptr; } + if(poly_y) { delete [] poly_y; poly_y = (int *) nullptr; } + return; } From 8abc76601edb1ada64db7ce0178684c6c636b1d1 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 15 Oct 2024 19:43:40 +0000 Subject: [PATCH 16/16] 673 Cleanup commented out code --- src/tools/other/lidar2nc/lidar2nc.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/tools/other/lidar2nc/lidar2nc.cc b/src/tools/other/lidar2nc/lidar2nc.cc index 4dc6134397..b5b771d08c 100644 --- a/src/tools/other/lidar2nc/lidar2nc.cc +++ b/src/tools/other/lidar2nc/lidar2nc.cc @@ -379,16 +379,12 @@ mlog << Debug(2) << "Processing Lidar points\t= " << n_data << "\n"; // populate the hdr_typ variable // -//memset(ibuf, 0, n_data*sizeof(int)); - obs_vars->hdr_typ_var.putVar(ibuf.data()); // // populate the hdr_sid variable // -//memset(ibuf, 0, n_data*sizeof(int)); - obs_vars->hdr_sid_var.putVar(ibuf.data()); nc_point_obs.add_header_strings(hdr_typ_string, na_str); @@ -433,8 +429,6 @@ unixtime t; get_hdf_var_info(hdf_sd_id, hdf_time_name, info); -//memset(ibuf, 0, n_data*sizeof(int)); - for (j=0; j