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)}") 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] 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): 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'): 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 ===') 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..06452934f3 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 data (n); + vector data_loc (n); + vector data_rank (n); + 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 ); - + } // @@ -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 d60d9ab14d..ff26b0d215 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; @@ -132,14 +132,12 @@ void Wchar_Argv::set(const StringArray & a) { -char * s = nullptr; -char ** av = nullptr; +int k = 0; +int len = 0; ConcatString c; const char *method_name = "Wchar_Argv::set() -> "; -int len = 0; - for (int j=0; j<(a.n()); ++j) { len += a.length(j); @@ -148,14 +146,12 @@ for (int j=0; j<(a.n()); ++j) { int N = len + a.n(); -s = new char [N]; +char * s = new char [N]; -av = new char * [a.n()]; +char ** av = new char * [a.n()]; memset(s, 0, N); -int k = 0; - for (int j=0; j<(a.n()); ++j) { av[j] = s + k; @@ -194,14 +190,12 @@ void Wchar_Argv::set(int _argc, char ** _argv) clear(); -int * len = nullptr; +int k; +int *len = new int [_argc]; Argc = _argc; -len = new int [Argc]; - - // // total length of the argument string ... // @@ -210,9 +204,10 @@ int argv_len = 0; 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 + // we're using the len array here because + // we don't want to call m_strlen more than + // once on each argv value + len[j] = (_argv == nullptr) ? 0 : len[j] = m_strlen(_argv[j]); argv_len += len[j]; @@ -241,11 +236,11 @@ for (int j=0; j " << "mbstowcs failed for string \"" << _argv[j] << "\"\n\n"; diff --git a/src/libcode/vx_shapedata/shapedata.cc b/src/libcode/vx_shapedata/shapedata.cc index 3e4491e380..f3a8dc14f2 100644 --- a/src/libcode/vx_shapedata/shapedata.cc +++ b/src/libcode/vx_shapedata/shapedata.cc @@ -390,7 +390,6 @@ double ShapeData::complexity() const { double ShapeData::intensity_percentile(const ShapeData *raw_ptr, int perc, bool precip_flag) const { int n = 0; - double * val = (double *) nullptr; double v; double val_sum = 0.0; const int Nxy = data.nx()*data.ny(); @@ -401,7 +400,7 @@ double ShapeData::intensity_percentile(const ShapeData *raw_ptr, int perc, exit(1); } - val = new double [Nxy]; + vector val(Nxy); // Compute the requested percentile of intensity for(int i=0; i Index(2*data.ny()); - if ( !Index ) { + if ( Index.size() < 2*data.ny() ) { mlog << Error << "\nShapedata::convex_hull() -> " << "memory allocation error\n\n"; @@ -889,8 +884,6 @@ Polyline ShapeData::convex_hull_old() const // done // - delete [] Index; Index = (int *) nullptr; - return hull; } @@ -1898,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; diff --git a/src/tools/core/mode/mode_exec.cc b/src/tools/core/mode/mode_exec.cc index 2463b97ab9..db43b97ebe 100644 --- a/src/tools/core/mode/mode_exec.cc +++ b/src/tools/core/mode/mode_exec.cc @@ -2378,7 +2378,8 @@ void ModeExecutive::write_poly_netcdf(NcFile *f_out, ObjPolyType poly_type) // // Store the points for each polyline // - for(i=0, n_pts=0; i " << "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 ibuf(n_data, 0); mlog << Debug(2) << "Processing Lidar points\t= " << n_data << "\n"; @@ -379,17 +379,13 @@ 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); +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); +obs_vars->hdr_sid_var.putVar(ibuf.data()); nc_point_obs.add_header_strings(hdr_typ_string, na_str); // @@ -401,13 +397,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,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; jhdr_vld_var.putVar(ibuf); +obs_vars->hdr_vld_var.putVar(ibuf.data()); -delete[] ibuf; - // // populate the obs_arr variable // @@ -585,7 +569,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; }