diff --git a/scripts/python/met/dataplane.py b/scripts/python/met/dataplane.py index a28661b365..468bbd6e44 100644 --- a/scripts/python/met/dataplane.py +++ b/scripts/python/met/dataplane.py @@ -178,7 +178,11 @@ def validate_met_data(met_data, fill_value=None): met_base.quit(f"{method_name} The met_data is None") sys.exit(1) - nx, ny = met_data.shape + if hasattr(met_data, 'shape'): + nx, ny = met_data.shape + else: + met_base.quit(f"{method_name} The met_data does not have the shape property") + sys.exit(1) met_fill_value = met_base.MET_FILL_VALUE if dataplane.is_xarray_dataarray(met_data): diff --git a/src/libcode/vx_data2d_nc_cf/nc_cf_file.cc b/src/libcode/vx_data2d_nc_cf/nc_cf_file.cc index 41c8106f31..be015948a0 100644 --- a/src/libcode/vx_data2d_nc_cf/nc_cf_file.cc +++ b/src/libcode/vx_data2d_nc_cf/nc_cf_file.cc @@ -345,9 +345,9 @@ bool NcCfFile::open(const char * filepath) int n_times = get_data_size(valid_time_var); int tim_buf_size = n_times; if (use_bounds_var) tim_buf_size *= 2; - auto time_values = new double[tim_buf_size]; + vector time_values(tim_buf_size); - if( get_nc_data(nc_time_var, time_values) ) { + if( get_nc_data(nc_time_var, time_values.data()) ) { bool no_leap_year = get_att_no_leap_year(valid_time_var); if( time_dim_count > 1 ) { double latest_time = bad_data_double; @@ -381,7 +381,6 @@ bool NcCfFile::open(const char * filepath) } } else ValidTime.add(0); //Initialize - delete [] time_values; } NcVar init_time_var = get_var(_ncFile, "forecast_reference_time"); @@ -504,14 +503,13 @@ bool NcCfFile::open(const char * filepath) if (IS_VALID_NC_P(z_var)) { int z_count = get_data_size(z_var); - auto z_values = new double[z_count]; + vector z_values(z_count); - if( get_nc_data(z_var, z_values) ) { + if( get_nc_data(z_var, z_values.data()) ) { for(int i=0; i d(plane_size); size_t dim_size; LongArray offsets; @@ -1125,7 +1123,7 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const offsets[y_slot] = 0; lengths[y_slot] = ny; - get_nc_data(v, d, lengths, offsets); + get_nc_data(v, d.data(), lengths, offsets); int offset = 0; if( x_slot > y_slot ) { @@ -1163,8 +1161,6 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const } /* for x */ } - delete [] d; - // done mlog << Debug(6) << method_name << "took " << get_exe_duration(start_clock) << " seconds\n"; diff --git a/src/libcode/vx_data2d_nc_met/get_met_grid.cc b/src/libcode/vx_data2d_nc_met/get_met_grid.cc index 90a6cd798b..0c428c6ab2 100644 --- a/src/libcode/vx_data2d_nc_met/get_met_grid.cc +++ b/src/libcode/vx_data2d_nc_met/get_met_grid.cc @@ -699,10 +699,9 @@ void get_semilatlon_var(NcFile *ncfile, const char * var_name, NumArray &out_na) // Store the requested data in the specified NumArray object long count = get_data_size(&nc_var); - double * data_values = new double[ count ]; - get_nc_data(&nc_var, data_values); + vector data_values(count); + get_nc_data(&nc_var, data_values.data()); for(int i=0; i data_array(cell_count); + vector double_array(cell_count); clock_time = clock(); - get_nc_data(v, double_array, dim, cur); - copy_nc_data_as_double(data_array, double_array, x_slot, y_slot, Nx, Ny, + get_nc_data(v, double_array.data(), dim, cur); + copy_nc_data_as_double(data_array.data(), double_array.data(), x_slot, y_slot, Nx, Ny, missing_value, fill_value); nc_time = clock(); if (mlog.verbosity_level() >= 7) { double duration_sec = (double)(nc_time - clock_time)/CLOCKS_PER_SEC; - check_nc_data_2d(data_array, Nx, Ny, missing_value); + check_nc_data_2d(data_array.data(), Nx, Ny, missing_value); mlog << Debug(7) << method_name_short << "took " << duration_sec << " seconds to read NetCDF data\n"; } - plane.set_block(data_array, Nx, Ny); + plane.set_block(data_array.data(), Nx, Ny); if (mlog.verbosity_level() >= 7) { double duration_sec = (double)(clock() - nc_time)/CLOCKS_PER_SEC; @@ -612,9 +612,6 @@ plane.set_size(Nx, Ny); << " seconds to fill data plane\n"; } - if (data_array) delete[] data_array; - if (double_array) delete[] double_array; - // // done // diff --git a/src/libcode/vx_data2d_nc_wrf/wrf_file.cc b/src/libcode/vx_data2d_nc_wrf/wrf_file.cc index 5279ca49f7..56820aea09 100644 --- a/src/libcode/vx_data2d_nc_wrf/wrf_file.cc +++ b/src/libcode/vx_data2d_nc_wrf/wrf_file.cc @@ -849,7 +849,7 @@ plane.set_size(Nx, Ny); // // get the data // -double d[Ny]; +vector d(Ny); LongArray offsets; LongArray lengths; @@ -863,7 +863,7 @@ lengths[y_slot] = Ny; int type_id = GET_NC_TYPE_ID_P(v); for (x=0; x time_values(tim_buf_size); if(2 == time_dim_count) { for(int i=0; i 1 ) { double latest_time = bad_data_double; @@ -396,7 +396,6 @@ bool UGridFile::open_metadata(const char * filepath) } } else ValidTime.add(0); //Initialize - delete [] time_values; } // Pull out the grid. This must be done after pulling out the dimension @@ -440,14 +439,13 @@ bool UGridFile::open_metadata(const char * filepath) if (IS_VALID_NC_P(z_var)) { int z_count = (int) get_data_size(z_var); - double *z_values = new double[z_count]; + vector z_values(z_count); - if( get_nc_data(z_var, z_values) ) { + if( get_nc_data(z_var, z_values.data()) ) { for(int i=0; i d(plane_size); int length; size_t dim_size; @@ -726,7 +724,7 @@ bool UGridFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const } } - get_nc_data(v, d, lengths, offsets); + get_nc_data(v, d.data(), lengths, offsets); double min_value = 10e10; double max_value = -min_value; @@ -744,8 +742,6 @@ bool UGridFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const } // for x - if (nullptr != d) delete [] d; - // done ConcatString log_message; for (int idx=0; idx _lat(face_count); + vector _lon(face_count); if (IS_INVALID_NC_P(_latVar)) { mlog << Error << "\n" << method_name << "latitude variable is missing\n\n"; exit(1); } - else if (!get_nc_data(_latVar,_lat)) { + else if (!get_nc_data(_latVar,_lat.data())) { mlog << Error << "\n" << method_name << "fail to read latitude values\n\n"; exit(1); } @@ -922,7 +918,7 @@ void UGridFile::read_netcdf_grid() mlog << Error << "\n" << method_name << "longitude variable is missing\n\n"; exit(1); } - else if (!get_nc_data(_lonVar,_lon)) { + else if (!get_nc_data(_lonVar,_lon.data())) { mlog << Error << "\n" << method_name << "fail to read latitude values\n\n"; exit(1); } @@ -943,7 +939,7 @@ void UGridFile::read_netcdf_grid() // Convert longitude from degrees east to west for (int idx=0; idxgetAttLength()]; - att->getValues(values); + vector values(att->getAttLength()); + att->getValues(values.data()); for(unsigned int i=0; i<=att->getAttLength(); i++) value.add(values[i]); - if(values) { delete [] values; values = 0; } return; } @@ -1397,8 +1396,8 @@ bool get_nc_data(NcVar *var, float *data) { switch ( type_id ) { case NcType::nc_DOUBLE: { - double *packed_data = new double[cell_count]; - if (get_nc_data_t(var, packed_data)) { + vector packed_data(cell_count); + if (get_nc_data_t(var, packed_data.data())) { double fill_value; bool has_fill_value = get_var_fill_value(var, fill_value); for (int idx=0; idx packed_data(cell_count, (long long)bad_data_int); - var->getVar(packed_data); - copy_nc_data_(var, data, packed_data, cell_count, + var->getVar(packed_data.data()); + copy_nc_data_(var, data, packed_data.data(), cell_count, "int64", add_offset, scale_factor); - delete [] packed_data; } break; case NcType::nc_INT: { - int *packed_data = new int[cell_count]; + vector packed_data(cell_count); - var->getVar(packed_data); - copy_nc_data_(var, data, packed_data, cell_count, + var->getVar(packed_data.data()); + copy_nc_data_(var, data, packed_data.data(), cell_count, "int", add_offset, scale_factor); - delete [] packed_data; } break; case NcType::nc_SHORT: { short missing_value; bool has_missing = get_var_fill_value(var, missing_value); - short *packed_data = new short[cell_count]; + vector packed_data(cell_count); - var->getVar(packed_data); + var->getVar(packed_data.data()); if (unsigned_value) { - unsigned short *ushort_data = new unsigned short[cell_count]; + vector ushort_data(cell_count); for (int idx=0; idx packed_data(cell_count); - var->getVar(packed_data); - copy_nc_data_(var, data, packed_data, cell_count, + var->getVar(packed_data.data()); + copy_nc_data_(var, data, packed_data.data(), cell_count, "unsigned short", add_offset, scale_factor); - delete [] packed_data; } break; case NcType::nc_BYTE: { ncbyte missing_value; bool has_missing = get_var_fill_value(var, missing_value); - ncbyte *packed_data = new ncbyte[cell_count]; + vector packed_data(cell_count); - var->getVar(packed_data); + var->getVar(packed_data.data()); if (unsigned_value) { - unsigned char *ubyte_data = new unsigned char[cell_count]; + vector ubyte_data(cell_count); for (int idx=0; idx packed_data(cell_count); - var->getVar(packed_data); - copy_nc_data_(var, data, packed_data, cell_count, + var->getVar(packed_data.data()); + copy_nc_data_(var, data, packed_data.data(), cell_count, "unsigned char", add_offset, scale_factor); - delete [] packed_data; } break; default: @@ -1601,9 +1590,9 @@ bool get_nc_data(NcVar *var, double *data) { switch ( type_id ) { case NcType::nc_FLOAT: { - float *packed_data = new float[cell_count]; + vector packed_data(cell_count); - var->getVar(packed_data); + var->getVar(packed_data.data()); float fill_value; bool has_fill_value = get_var_fill_value(var, fill_value); @@ -1612,96 +1601,87 @@ bool get_nc_data(NcVar *var, double *data) { data[idx] = bad_data_double; else data[idx] = (double)packed_data[idx]; } - delete [] packed_data; } break; case NcType::nc_INT64: { - long long *packed_data = new long long[cell_count]; + vector packed_data(cell_count); - var->getVar(packed_data); - copy_nc_data_(var, data, packed_data, cell_count, + var->getVar(packed_data.data()); + copy_nc_data_(var, data, packed_data.data(), cell_count, "int64", add_offset, scale_factor); - delete [] packed_data; } break; case NcType::nc_INT: { - int *packed_data = new int[cell_count]; + vector packed_data(cell_count); - var->getVar(packed_data); - copy_nc_data_(var, data, packed_data, cell_count, + var->getVar(packed_data.data()); + copy_nc_data_(var, data, packed_data.data(), cell_count, "int", add_offset, scale_factor); - delete [] packed_data; } break; case NcType::nc_SHORT: { short missing_value; bool has_missing = get_var_fill_value(var, missing_value); - short *packed_data = new short[cell_count]; - var->getVar(packed_data); + vector packed_data(cell_count); + var->getVar(packed_data.data()); if (unsigned_value) { - unsigned short *ushort_data = new unsigned short[cell_count]; + vector ushort_data(cell_count); for (int idx=0; idx packed_data(cell_count); - var->getVar(packed_data); - copy_nc_data_(var, data, packed_data, cell_count, + var->getVar(packed_data.data()); + copy_nc_data_(var, data, packed_data.data(), cell_count, "ushort", add_offset, scale_factor); - delete [] packed_data; } break; case NcType::nc_BYTE: { ncbyte missing_value; bool has_missing = get_var_fill_value(var, missing_value); - ncbyte *packed_data = new ncbyte[cell_count]; + vector packed_data(cell_count); - var->getVar(packed_data); + var->getVar(packed_data.data()); if (unsigned_value) { - unsigned char *ubyte_data = new unsigned char[cell_count]; + vector ubyte_data(cell_count); for (int idx=0; idx packed_data(cell_count); - var->getVar(packed_data); - copy_nc_data_(var, data, packed_data, cell_count, + var->getVar(packed_data.data()); + copy_nc_data_(var, data, packed_data.data(), cell_count, "ncubyte", add_offset, scale_factor); - delete [] packed_data; } break; default: @@ -1770,14 +1750,13 @@ bool get_nc_data(NcVar *var, uchar *data, bool allow_conversion) { << "INFO: Unexpected conversion from 'ncbyte' for variable \"" << GET_NC_NAME_P(var) << "\".\n\n"; } - ncbyte *signed_data = new ncbyte[cell_count]; - return_status = get_nc_data_t(var, signed_data); + vector signed_data(cell_count); + return_status = get_nc_data_t(var, signed_data.data()); if (return_status) { for (int idx=0; idx short_data(cell_count); + if (return_status = get_nc_data_t(var, short_data.data())) { for (int idx=0; idx values(data_size); - if (get_nc_data(var, values)) { + if (get_nc_data(var, values.data())) { unixtime ut; int sec_per_unit; bool no_leap_year = get_att_no_leap_year(var); @@ -1943,7 +1921,6 @@ int get_index_at_nc_data(NcVar *var, double value, const string dim_name, bool i } } } - if (values) delete [] values; ConcatString value_str; if (is_time && (value > 10000000.)) value_str << unix_to_yyyymmdd_hhmmss(value); @@ -2818,65 +2795,45 @@ void copy_nc_atts(NcVar *var_from, NcVar *var_to, const bool all_attrs) { void copy_nc_data_char(NcVar *var_from, NcVar *var_to, int data_size) { //const string method_name = "copy_nc_data_char"; - char *data = new char[data_size]; - var_from->getVar(data); - var_to->putVar(data); - // mlog << Error << "\n" << method_name << " -> error writing the variable " - // << GET_NC_NAME_P(var_to) << " to the netCDF file\n\n"; - // exit(1); - delete[] data; + vector data(data_size); + var_from->getVar(data.data()); + var_to->putVar(data.data()); } //////////////////////////////////////////////////////////////////////// void copy_nc_data_double(NcVar *var_from, NcVar *var_to, int data_size) { //const string method_name = "copy_nc_data_double"; - double *data = new double[data_size]; - var_from->getVar(data); - var_to->putVar(data); - // mlog << Error << "\n" << method_name << " -> error writing the variable " - // << GET_NC_NAME_P(var_to) << " to the netCDF file\n\n"; - // exit(1); - delete[] data; + vector data(data_size); + var_from->getVar(data.data()); + var_to->putVar(data.data()); } //////////////////////////////////////////////////////////////////////// void copy_nc_data_float(NcVar *var_from, NcVar *var_to, int data_size) { //const string method_name = "copy_nc_data_float"; - float *data = new float[data_size]; - var_from->getVar(data); - var_to->putVar(data); - // mlog << Error << "\n" << method_name << " -> error writing the variable " - // << GET_NC_NAME_P(var_to) << " to the netCDF file\n\n"; - // exit(1); - delete[] data; + vector data(data_size); + var_from->getVar(data.data()); + var_to->putVar(data.data()); } //////////////////////////////////////////////////////////////////////// void copy_nc_data_int(NcVar *var_from, NcVar *var_to, int data_size) { //const string method_name = "copy_nc_data_int"; - int *data = new int[data_size]; - var_from->getVar(data); - var_to->putVar(data); - // mlog << Error << "\n" << method_name << " -> error writing the variable " - // << GET_NC_NAME_P(var_to) << " to the netCDF file\n\n"; - // exit(1); - delete[] data; + vector data(data_size); + var_from->getVar(data.data()); + var_to->putVar(data.data()); } //////////////////////////////////////////////////////////////////////// void copy_nc_data_short(NcVar *var_from, NcVar *var_to, int data_size) { //const string method_name = "copy_nc_data_double"; - short *data = new short[data_size]; - var_from->getVar(data); - var_to->putVar(data); - // mlog << Error << "\n" << method_name << " -> error writing the variable " - // << GET_NC_NAME_P(var_to) << " to the netCDF file\n\n"; - // exit(1); - delete[] data; + vector data(data_size); + var_from->getVar(data.data()); + var_to->putVar(data.data()); } //////////////////////////////////////////////////////////////////////// @@ -2886,9 +2843,6 @@ void copy_nc_data_string(NcVar *var_from, NcVar *var_to, int data_size) { string *data = new string[data_size]; var_from->getVar(data); var_to->putVar(data); - // mlog << Error << "\n" << method_name << " -> error writing the variable " - // << GET_NC_NAME_P(var_to) << " to the netCDF file\n\n"; - // exit(1); delete[] data; } diff --git a/src/libcode/vx_nc_util/write_netcdf.cc b/src/libcode/vx_nc_util/write_netcdf.cc index 6a747cf7df..e156f85ce7 100644 --- a/src/libcode/vx_nc_util/write_netcdf.cc +++ b/src/libcode/vx_nc_util/write_netcdf.cc @@ -113,8 +113,8 @@ void write_netcdf_latlon_1d(NcFile *f_out, NcDim *lat_dim, NcDim *lon_dim, NcVar lat_var; NcVar lon_var; // Allocate space for lat/lon values - float *lat_data = new float [grid.ny()]; - float *lon_data = new float [grid.nx()]; + vector lat_data(grid.ny()); + vector lon_data(grid.nx()); // Define Variables lat_var = f_out->addVar("lat", ncFloat, *lat_dim); @@ -142,13 +142,10 @@ void write_netcdf_latlon_1d(NcFile *f_out, NcDim *lat_dim, NcDim *lon_dim, } // Write the lat data - put_nc_data(&lat_var, &lat_data[0], lat_dim->getSize(), 0); + put_nc_data(&lat_var, lat_data.data(), lat_dim->getSize(), 0); // Write the lon data - put_nc_data(&lon_var, &lon_data[0], lon_dim->getSize(), 0); - - if ( lat_data ) { delete [] lat_data; lat_data = nullptr; } - if ( lon_data ) { delete [] lon_data; lon_data = nullptr; } + put_nc_data(&lon_var, lon_data.data(), lon_dim->getSize(), 0); return; } @@ -164,8 +161,8 @@ void write_netcdf_latlon_2d(NcFile *f_out, NcDim *lat_dim, NcDim *lon_dim, long counts[2] = {grid.ny(), grid.nx()}; long offsets[2] = {0 , 0}; // Allocate space for lat/lon values - float *lat_data = new float [grid.nx()*grid.ny()]; - float *lon_data = new float [grid.nx()*grid.ny()]; + vector lat_data(grid.nx()*grid.ny()); + vector lon_data(grid.nx()*grid.ny()); // Define Variables dims.push_back(*lat_dim); @@ -196,13 +193,10 @@ void write_netcdf_latlon_2d(NcFile *f_out, NcDim *lat_dim, NcDim *lon_dim, } // Write the lat data - put_nc_data(&lat_var, &lat_data[0], counts, offsets); + put_nc_data(&lat_var, lat_data.data(), counts, offsets); // Write the lon data - put_nc_data(&lon_var, &lon_data[0], counts, offsets); - - if ( lat_data ) { delete [] lat_data; lat_data = nullptr; } - if ( lon_data ) { delete [] lon_data; lon_data = nullptr; } + put_nc_data(&lon_var, lon_data.data(), counts, offsets); return; } @@ -216,7 +210,7 @@ void write_netcdf_grid_weight(NcFile *f_out, NcDim *lat_dim, NcDim *lon_dim, vector dims; vector count; // Allocate space for weight values - float *wgt_data = new float [wgt_dp.nx()*wgt_dp.ny()]; + vector wgt_data(wgt_dp.nx()*wgt_dp.ny()); // Define Variables dims.push_back(*lat_dim); @@ -256,10 +250,9 @@ void write_netcdf_grid_weight(NcFile *f_out, NcDim *lat_dim, NcDim *lon_dim, // Write the weights count.push_back(wgt_dp.ny()); count.push_back(wgt_dp.nx()); - put_nc_data_with_dims(&wgt_var, &wgt_data[0], wgt_dp.ny(), wgt_dp.nx()); + put_nc_data_with_dims(&wgt_var, wgt_data.data(), wgt_dp.ny(), wgt_dp.nx()); // Clean up - if(wgt_data) { delete [] wgt_data; wgt_data = (float *) nullptr; } return; } diff --git a/src/libcode/vx_tc_util/vx_tc_nc_util.cc b/src/libcode/vx_tc_util/vx_tc_nc_util.cc index bc835eb4e2..2f25861d81 100644 --- a/src/libcode/vx_tc_util/vx_tc_nc_util.cc +++ b/src/libcode/vx_tc_util/vx_tc_nc_util.cc @@ -56,8 +56,8 @@ void write_tc_track_lat_lon(NcFile* nc_out, add_att(&track_lon_var, "units", "degrees_east"); add_att(&track_lon_var, "standard_name", "longitude_track"); - double* track_lat_data = new double[track.n_points()]; - double* track_lon_data = new double[track.n_points()]; + vector track_lat_data(track.n_points()); + vector track_lon_data(track.n_points()); for(int i = 0; i < track.n_points(); i++) { mlog << Debug(5) << track[i].serialize() << "\n"; @@ -71,11 +71,9 @@ void write_tc_track_lat_lon(NcFile* nc_out, vector counts; counts.push_back(track.n_points()); - track_lat_var.putVar(offsets, counts, track_lat_data); - track_lon_var.putVar(offsets, counts, track_lon_data); + track_lat_var.putVar(offsets, counts, track_lat_data.data()); + track_lon_var.putVar(offsets, counts, track_lon_data.data()); - delete[] track_lat_data; - delete[] track_lon_data; } //////////////////////////////////////////////////////////////////////// @@ -139,7 +137,7 @@ void write_tc_rmw(NcFile* nc_out, add_att(&track_mrd_var, "units", "nautical_miles"); add_att(&track_mrd_var, "standard_name", "radius_max_wind"); - double* track_mrd_data = new double[track.n_points()]; + vector track_mrd_data(track.n_points()); for(int i = 0; i < track.n_points(); i++) { track_mrd_data[i] = track[i].mrd(); @@ -151,9 +149,8 @@ void write_tc_rmw(NcFile* nc_out, vector counts; counts.push_back(track.n_points()); - track_mrd_var.putVar(offsets, counts, track_mrd_data); + track_mrd_var.putVar(offsets, counts, track_mrd_data.data()); - delete[] track_mrd_data; } //////////////////////////////////////////////////////////////////////// @@ -281,7 +278,7 @@ void def_tc_pressure(NcFile* nc_out, NcVar pressure_var; - double* pressure_data = new double[pressure_levels.size()]; + vector pressure_data(pressure_levels.size()); // Define variable pressure_var = nc_out->addVar("pressure", ncDouble, pressure_dim); @@ -300,10 +297,7 @@ void def_tc_pressure(NcFile* nc_out, k--; } - put_nc_data(&pressure_var, &pressure_data[0]); - - // Cleanup - if(pressure_data) { delete [] pressure_data; pressure_data = (double *) 0; } + put_nc_data(&pressure_var, pressure_data.data()); return; } @@ -317,8 +311,8 @@ void def_tc_range_azimuth(NcFile* nc_out, NcVar range_var; NcVar azimuth_var; - double* range_data = new double[grid.range_n()]; - double* azimuth_data = new double[grid.azimuth_n()]; + vector range_data(grid.range_n()); + vector azimuth_data(grid.azimuth_n()); // Define variables range_var = nc_out->addVar("range", ncDouble, range_dim); @@ -352,12 +346,8 @@ void def_tc_range_azimuth(NcFile* nc_out, } // Write coordinates - put_nc_data(&range_var, &range_data[0]); - put_nc_data(&azimuth_var, &azimuth_data[0]); - - // Cleanup - if(range_data) { delete [] range_data; range_data = (double *) 0; } - if(azimuth_data) { delete [] azimuth_data; azimuth_data = (double *) 0; } + put_nc_data(&range_var, range_data.data()); + put_nc_data(&azimuth_var, azimuth_data.data()); return; } @@ -669,8 +659,7 @@ void write_tc_data_rev(NcFile* nc_out, const TcrmwGrid& grid, vector offsets; vector counts; - - double* data_rev; + vector data_rev(grid.range_n() * grid.azimuth_n()); offsets.clear(); offsets.push_back(i_point); @@ -682,9 +671,6 @@ void write_tc_data_rev(NcFile* nc_out, const TcrmwGrid& grid, counts.push_back(grid.range_n()); counts.push_back(grid.azimuth_n()); - data_rev = new double[ - grid.range_n() * grid.azimuth_n()]; - for(int ir = 0; ir < grid.range_n(); ir++) { for(int ia = 0; ia < grid.azimuth_n(); ia++) { int i = ir * grid.azimuth_n() + ia; @@ -693,9 +679,8 @@ void write_tc_data_rev(NcFile* nc_out, const TcrmwGrid& grid, } } - var.putVar(offsets, counts, data_rev); + var.putVar(offsets, counts, data_rev.data()); - delete[] data_rev; } //////////////////////////////////////////////////////////////////////// @@ -706,8 +691,8 @@ void write_tc_azi_mean_data(NcFile* nc_out, const TcrmwGrid& grid, vector offsets; vector counts; - double* data_rev; - double* data_azi_mean; + vector data_rev(grid.range_n() * grid.azimuth_n()); + vector data_azi_mean(grid.range_n(), 0.0); offsets.clear(); offsets.push_back(i_point); @@ -717,10 +702,6 @@ void write_tc_azi_mean_data(NcFile* nc_out, const TcrmwGrid& grid, counts.push_back(1); counts.push_back(grid.range_n()); - data_rev = new double[ - grid.range_n() * grid.azimuth_n()]; - data_azi_mean = new double[grid.range_n()]; - for(int ir = 0; ir < grid.range_n(); ir++) { data_azi_mean[ir] = 0.; for(int ia = 0; ia < grid.azimuth_n(); ia++) { @@ -735,10 +716,8 @@ void write_tc_azi_mean_data(NcFile* nc_out, const TcrmwGrid& grid, data_azi_mean[ir] /= grid.azimuth_n(); } - var.putVar(offsets, counts, data_azi_mean); + var.putVar(offsets, counts, data_azi_mean.data()); - delete[] data_rev; - delete[] data_azi_mean; } //////////////////////////////////////////////////////////////////////// @@ -761,8 +740,7 @@ extern void write_tc_pressure_level_data( vector offsets_3d; vector counts_3d; - - double* data_rev; + vector data_rev(grid.range_n() * grid.azimuth_n()); offsets_3d.clear(); offsets_3d.push_back(i_point); @@ -776,9 +754,6 @@ extern void write_tc_pressure_level_data( counts_3d.push_back(grid.range_n()); counts_3d.push_back(grid.azimuth_n()); - data_rev = new double[ - grid.range_n() * grid.azimuth_n()]; - for(int ir = 0; ir < grid.range_n(); ir++) { for(int ia = 0; ia < grid.azimuth_n(); ia++) { int i = ir * grid.azimuth_n() + ia; @@ -787,9 +762,8 @@ extern void write_tc_pressure_level_data( } } - var.putVar(offsets_3d, counts_3d, data_rev); + var.putVar(offsets_3d, counts_3d, data_rev.data()); - delete[] data_rev; } //////////////////////////////////////////////////////////////////////// diff --git a/src/tools/core/ensemble_stat/ensemble_stat.cc b/src/tools/core/ensemble_stat/ensemble_stat.cc index 475a1bd52a..38abd51a3b 100644 --- a/src/tools/core/ensemble_stat/ensemble_stat.cc +++ b/src/tools/core/ensemble_stat/ensemble_stat.cc @@ -2560,27 +2560,11 @@ void write_orank_nc(PairDataEnsemble &pd, DataPlane &dp, int i, n; // Arrays for storing observation rank data - float *obs_v = (float *) nullptr; - int *obs_rank = (int *) nullptr; - float *obs_pit = (float *) nullptr; - int *ens_vld = (int *) nullptr; - float *ens_mean = (float *) nullptr; - - // Allocate memory for storing ensemble data - obs_v = new float [nxy]; - obs_rank = new int [nxy]; - obs_pit = new float [nxy]; - ens_vld = new int [nxy]; - ens_mean = new float [nxy]; - - // Initialize - for(i=0; i obs_v (nxy, bad_data_float); + vector obs_rank (nxy, bad_data_int ); + vector obs_pit (nxy, bad_data_float); + vector ens_vld (nxy, bad_data_int ); + vector ens_mean (nxy, bad_data_float); // Loop over all the pairs for(i=0; i data(grid.nxy()); // Set the NetCDF compression level int deflate_level = compress_level; @@ -3001,7 +3000,7 @@ void write_nc(const ConcatString &field_name, const DataPlane &dp, } // end for x // Write out the data - if(!put_nc_data_with_dims(&nc_var, &data[0], grid.ny(), grid.nx())) { + if(!put_nc_data_with_dims(&nc_var, data.data(), grid.ny(), grid.nx())) { mlog << Error << "\nwrite_nc() -> " << "error writing NetCDF variable name " << var_name << "\n\n"; @@ -3010,9 +3009,6 @@ void write_nc(const ConcatString &field_name, const DataPlane &dp, } // end for i - // Deallocate and clean up - if(data) { delete [] data; data = (float *) nullptr; } - return; } @@ -3046,9 +3042,6 @@ void write_nbrhd_nc(const DataPlane &fcst_dp, const DataPlane &obs_dp, // Store the apply_mask option apply_mask = conf_info.vx_opt[i_vx].nc_info.do_apply_mask; - float *fcst_data = (float *) nullptr; - float *obs_data = (float *) nullptr; - NcVar fcst_var; NcVar obs_var; @@ -3081,8 +3074,8 @@ void write_nbrhd_nc(const DataPlane &fcst_dp, const DataPlane &obs_dp, if(!fcst_flag && !obs_flag) return; // Allocate memory for the forecast and observation fields - fcst_data = new float [grid.nxy()]; - obs_data = new float [grid.nxy()]; + vector fcst_data(grid.nxy()); + vector obs_data (grid.nxy()); // Add the forecast variable if(fcst_flag) { @@ -3161,7 +3154,7 @@ void write_nbrhd_nc(const DataPlane &fcst_dp, const DataPlane &obs_dp, // Write out the forecast field if(fcst_flag) { - if(!put_nc_data_with_dims(&fcst_var, &fcst_data[0], grid.ny(), grid.nx())) { + if(!put_nc_data_with_dims(&fcst_var, fcst_data.data(), grid.ny(), grid.nx())) { mlog << Error << "\nwrite_nbrhd_nc() -> " << "error with the fcst_var->put for forecast variable " << fcst_var_name << "\n\n"; @@ -3171,7 +3164,7 @@ void write_nbrhd_nc(const DataPlane &fcst_dp, const DataPlane &obs_dp, // Write out the observation field if(obs_flag) { - if(!put_nc_data_with_dims(&obs_var, &obs_data[0], grid.ny(), grid.nx())) { + if(!put_nc_data_with_dims(&obs_var, obs_data.data(), grid.ny(), grid.nx())) { mlog << Error << "\nwrite_nbrhd_nc() -> " << "error with the obs_var->put for observation variable " << obs_var_name << "\n\n"; @@ -3179,10 +3172,6 @@ void write_nbrhd_nc(const DataPlane &fcst_dp, const DataPlane &obs_dp, } } - // Deallocate and clean up - if(fcst_data) { delete [] fcst_data; fcst_data = (float *) nullptr; } - if(obs_data) { delete [] obs_data; obs_data = (float *) nullptr; } - return; } diff --git a/src/tools/core/series_analysis/series_analysis.cc b/src/tools/core/series_analysis/series_analysis.cc index fa2d4a8ef7..581356dcd8 100644 --- a/src/tools/core/series_analysis/series_analysis.cc +++ b/src/tools/core/series_analysis/series_analysis.cc @@ -2273,7 +2273,7 @@ void write_stat_data() { if(deflate_level < 0) deflate_level = conf_info.get_compression_level(); // Allocate memory to store data values for each grid point - float *data = new float [grid.nx()*grid.ny()]; + vector data(grid.nx()*grid.ny()); // Write output for each stat_data map entry for(auto &key : stat_data_keys) { @@ -2300,7 +2300,7 @@ void write_stat_data() { } // end for x // Write out the data - if(!put_nc_data_with_dims(&nc_var, &data[0], grid.ny(), grid.nx())) { + if(!put_nc_data_with_dims(&nc_var, data.data(), grid.ny(), grid.nx())) { mlog << Error << "\nwrite_stat_data() -> " << R"(error writing ")" << key << R"(" data to the output file.)" << "\n\n"; @@ -2308,9 +2308,6 @@ void write_stat_data() { } } - // Clean up - if(data) { delete [] data; data = (float *) nullptr; } - return; } diff --git a/src/tools/core/wavelet_stat/wavelet_stat.cc b/src/tools/core/wavelet_stat/wavelet_stat.cc index 70f55ed870..89d05ce6ae 100644 --- a/src/tools/core/wavelet_stat/wavelet_stat.cc +++ b/src/tools/core/wavelet_stat/wavelet_stat.cc @@ -953,13 +953,6 @@ int get_tile_tot_count() { void do_intensity_scale(const NumArray &f_na, const NumArray &o_na, ISCInfo *&isc_info, int i_vx, int i_tile) { - double *f_dat = (double *) nullptr; // Raw and thresholded binary fields - double *o_dat = (double *) nullptr; // Raw and thresholded binary fields - double *f_dwt = (double *) nullptr; // Discrete wavelet transformations - double *o_dwt = (double *) nullptr; // Discrete wavelet transformations - double *f_scl = (double *) nullptr; // Binary field decomposed by scale - double *o_scl = (double *) nullptr; // Binary field decomposed by scale - double *diff = (double *) nullptr; // Difference field double mse, fen, oen, mad; int n, ns, n_isc; int bnd, row, col; @@ -999,13 +992,13 @@ void do_intensity_scale(const NumArray &f_na, const NumArray &o_na, } // Allocate space - f_dat = new double [n]; - o_dat = new double [n]; - f_dwt = new double [n]; - o_dwt = new double [n]; - f_scl = new double [n]; - o_scl = new double [n]; - diff = new double [n]; + vector f_dat(n); // Raw and thresholded binary fields + vector o_dat(n); // Raw and thresholded binary fields + vector f_dwt(n); // Discrete wavelet transformations + vector o_dwt(n); // Discrete wavelet transformations + vector f_scl(n); // Binary field decomposed by scale + vector o_scl(n); // Binary field decomposed by scale + vector diff (n); // Difference field // Initialize f_dat and o_dat for(i=0; i data(n); dp.data_range(dmin, dmax); mlog << Debug(2) @@ -319,7 +319,7 @@ void write_nc_bin(const DataPlane &dp, int i_cdf, double cdf_y) { } // Write out the gridded field of CDF X-values - if(!put_nc_data(&cdf_x_var, &data[0], lengths, offsets)) { + if(!put_nc_data(&cdf_x_var, data.data(), lengths, offsets)) { mlog << Error << "\nwrite_nc_bin() -> " << "error writing NetCDF variable name \"" << var_name << "\" for the " << i_cdf @@ -327,9 +327,6 @@ void write_nc_bin(const DataPlane &dp, int i_cdf, double cdf_y) { exit(1); } - // Deallocate and clean up - if(data) { delete [] data; data = (float *) nullptr; } - return; } diff --git a/src/tools/other/gen_ens_prod/gen_ens_prod.cc b/src/tools/other/gen_ens_prod/gen_ens_prod.cc index 9f36c55ad3..d552e90405 100644 --- a/src/tools/other/gen_ens_prod/gen_ens_prod.cc +++ b/src/tools/other/gen_ens_prod/gen_ens_prod.cc @@ -821,14 +821,14 @@ void write_ens_nc(GenEnsProdVarInfo *ens_info, int n_ens_vld, DataPlane prob_dp, nbrhd_dp; // Allocate memory for storing ensemble data - float *ens_mean = new float [nxy]; - float *ens_stdev = new float [nxy]; - float *ens_minus = new float [nxy]; - float *ens_plus = new float [nxy]; - float *ens_min = new float [nxy]; - float *ens_max = new float [nxy]; - float *ens_range = new float [nxy]; - int *ens_vld = new int [nxy]; + vector ens_mean (nxy); + vector ens_stdev (nxy); + vector ens_minus (nxy); + vector ens_plus (nxy); + vector ens_min (nxy); + vector ens_max (nxy); + vector ens_range (nxy); + vector ens_vld (nxy); // Store the threshold for the ratio of valid data points t = conf_info.vld_data_thresh; @@ -865,56 +865,56 @@ void write_ens_nc(GenEnsProdVarInfo *ens_info, int n_ens_vld, // Add the ensemble mean, if requested if(ens_info->nc_info.do_mean) { - write_ens_var_float(ens_info, ens_mean, ens_dp, + write_ens_var_float(ens_info, ens_mean.data(), ens_dp, "ENS_MEAN", "Ensemble Mean"); } // Add the ensemble standard deviation, if requested if(ens_info->nc_info.do_stdev) { - write_ens_var_float(ens_info, ens_stdev, ens_dp, + write_ens_var_float(ens_info, ens_stdev.data(), ens_dp, "ENS_STDEV", "Ensemble Standard Deviation"); } // Add the ensemble mean minus one standard deviation, if requested if(ens_info->nc_info.do_minus) { - write_ens_var_float(ens_info, ens_minus, ens_dp, + write_ens_var_float(ens_info, ens_minus.data(), ens_dp, "ENS_MINUS", "Ensemble Mean Minus 1 Standard Deviation"); } // Add the ensemble mean plus one standard deviation, if requested if(ens_info->nc_info.do_plus) { - write_ens_var_float(ens_info, ens_plus, ens_dp, + write_ens_var_float(ens_info, ens_plus.data(), ens_dp, "ENS_PLUS", "Ensemble Mean Plus 1 Standard Deviation"); } // Add the ensemble minimum value, if requested if(ens_info->nc_info.do_min) { - write_ens_var_float(ens_info, ens_min, ens_dp, + write_ens_var_float(ens_info, ens_min.data(), ens_dp, "ENS_MIN", "Ensemble Minimum"); } // Add the ensemble maximum value, if requested if(ens_info->nc_info.do_max) { - write_ens_var_float(ens_info, ens_max, ens_dp, + write_ens_var_float(ens_info, ens_max.data(), ens_dp, "ENS_MAX", "Ensemble Maximum"); } // Add the ensemble range, if requested if(ens_info->nc_info.do_range) { - write_ens_var_float(ens_info, ens_range, ens_dp, + write_ens_var_float(ens_info, ens_range.data(), ens_dp, "ENS_RANGE", "Ensemble Range"); } // Add the ensemble valid data count, if requested if(ens_info->nc_info.do_vld) { - write_ens_var_int(ens_info, ens_vld, ens_dp, + write_ens_var_int(ens_info, ens_vld.data(), ens_dp, "ENS_VLD", "Ensemble Valid Data Count"); } @@ -1061,16 +1061,6 @@ void write_ens_nc(GenEnsProdVarInfo *ens_info, int n_ens_vld, } // end for it } - // Deallocate and clean up - if(ens_mean) { delete [] ens_mean; ens_mean = (float *) nullptr; } - if(ens_stdev) { delete [] ens_stdev; ens_stdev = (float *) nullptr; } - if(ens_minus) { delete [] ens_minus; ens_minus = (float *) nullptr; } - if(ens_plus) { delete [] ens_plus; ens_plus = (float *) nullptr; } - if(ens_min) { delete [] ens_min; ens_min = (float *) nullptr; } - if(ens_max) { delete [] ens_max; ens_max = (float *) nullptr; } - if(ens_range) { delete [] ens_range; ens_range = (float *) nullptr; } - if(ens_vld) { delete [] ens_vld; ens_vld = (int *) nullptr; } - return; } 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 98b15a212a..1c7f77c002 100644 --- a/src/tools/other/gen_vx_mask/gen_vx_mask.cc +++ b/src/tools/other/gen_vx_mask/gen_vx_mask.cc @@ -1368,7 +1368,6 @@ void write_netcdf(const DataPlane &dp) { int n, x, y; ConcatString cs; - float *mask_data = (float *) nullptr; NcFile *f_out = (NcFile *) nullptr; NcDim lat_dim; NcDim lon_dim; @@ -1433,7 +1432,7 @@ void write_netcdf(const DataPlane &dp) { } // Allocate memory to store the mask values for each grid point - mask_data = new float [grid.nx()*grid.ny()]; + vector mask_data(grid.nx()*grid.ny()); // Loop through each grid point for(x=0; x " << "error with mask_var->put\n\n"; - // Delete allocated memory - if(mask_data) { delete[] mask_data; mask_data = (float *) nullptr; } exit(1); } - // Delete allocated memory - if(mask_data) { delete[] mask_data; mask_data = (float *) nullptr; } - delete f_out; f_out = (NcFile *) nullptr; diff --git a/src/tools/other/ioda2nc/ioda2nc.cc b/src/tools/other/ioda2nc/ioda2nc.cc index da466c79d2..bf5b288cdf 100644 --- a/src/tools/other/ioda2nc/ioda2nc.cc +++ b/src/tools/other/ioda2nc/ioda2nc.cc @@ -572,12 +572,12 @@ void process_ioda_file(int i_pb) { ? (npbmsg * nmsg_percent / 100) : nmsg; } - float *hdr_lat_arr = new float[nlocs]; - float *hdr_lon_arr = new float[nlocs]; - float *hdr_elv_arr = new float[nlocs]; - float *obs_pres_arr = new float[nlocs]; - float *obs_hght_arr = new float[nlocs]; - float *hdr_time_arr = new float[nlocs]; + vector hdr_lat_arr (nlocs); + vector hdr_lon_arr (nlocs); + vector hdr_elv_arr (nlocs); + vector obs_pres_arr (nlocs); + vector obs_hght_arr (nlocs); + vector hdr_time_arr (nlocs); char *hdr_vld_block = new char[nlocs*ndatetime]; char *hdr_msg_types = nullptr; char *hdr_station_ids = nullptr; @@ -592,9 +592,9 @@ void process_ioda_file(int i_pb) { for (int i=0; i lat_data(nx*ny); +vector lon_data(nx*ny); -Lat = lat_data; -Lon = lon_data; +Lat = lat_data.data(); +Lon = lon_data.data(); for (y=0; y out_data(n3); const string name = ( is_fcst ? fcst_clus_id_name : obs_clus_id_name ); @@ -363,7 +357,7 @@ add_att(&var, "_FillValue", bad_data_int); const int n_objects = ( is_fcst ? (e.n_fcst_simples()) : (e.n_obs_simples()) ); -remap = new int [n_objects + 1]; +vector remap(n_objects + 1); remap[0] = 0; @@ -378,26 +372,20 @@ for (j=1; j<=n_objects; ++j) { } -op = out_data; - for (j=0; j " << "error writing data to the output file.\n\n"; exit(1); @@ -1726,7 +1726,7 @@ void write_nc_data_int(const DataPlane &dp, const Grid &grid, NcVar *data_var) { } // end for x // Write out the data - if(!put_nc_data_with_dims(data_var, &data.data()[0], grid.ny(), grid.nx())) { + if(!put_nc_data_with_dims(data_var, data.data(), grid.ny(), grid.nx())) { mlog << Error << "\nwrite_nc_data_int() -> " << "error writing data to the output file.\n\n"; exit(1); diff --git a/src/tools/other/regrid_data_plane/regrid_data_plane.cc b/src/tools/other/regrid_data_plane/regrid_data_plane.cc index 28ec4704ea..0306c670a6 100644 --- a/src/tools/other/regrid_data_plane/regrid_data_plane.cc +++ b/src/tools/other/regrid_data_plane/regrid_data_plane.cc @@ -390,7 +390,7 @@ void open_nc(const Grid &grid, ConcatString run_cs) { void write_nc_data(const DataPlane &dp, const Grid &grid, NcVar *data_var) { // Allocate memory to store data values for each grid point - float *data = new float [grid.nx()*grid.ny()]; + vector data(grid.nx()*grid.ny()); // Store the data int grid_nx = grid.nx(); @@ -403,15 +403,12 @@ void write_nc_data(const DataPlane &dp, const Grid &grid, NcVar *data_var) { } // end for x // Write out the data - if(!put_nc_data_with_dims(data_var, &data[0], grid.ny(), grid.nx())) { + if(!put_nc_data_with_dims(data_var, data.data(), grid.ny(), grid.nx())) { mlog << Error << "\nwrite_nc_data() -> " << "error writing data to the output file.\n\n"; exit(1); } - // Clean up - if(data) { delete [] data; data = (float *) nullptr; } - return; } diff --git a/src/tools/other/shift_data_plane/shift_data_plane.cc b/src/tools/other/shift_data_plane/shift_data_plane.cc index 40e2f742bc..7f5e56da5b 100644 --- a/src/tools/other/shift_data_plane/shift_data_plane.cc +++ b/src/tools/other/shift_data_plane/shift_data_plane.cc @@ -336,7 +336,7 @@ void write_netcdf(const DataPlane &dp, const Grid &grid, add_att(&data_var, "smoothing_shape", gtf.enum2String(Shape)); // Allocate memory to store data values for each grid point - float *data = new float [grid.nx()*grid.ny()]; + vector data(grid.nx()*grid.ny()); // Store the data for(int x=0; x " << "error writing data to the output file.\n\n"; exit(1); } // Clean up - if(data) { delete [] data; data = (float *) nullptr; } if(f_out) { delete f_out; f_out = (NcFile *) nullptr; } diff --git a/src/tools/tc_utils/tc_diag/tc_diag.cc b/src/tools/tc_utils/tc_diag/tc_diag.cc index c4b76a7cdd..1644333772 100644 --- a/src/tools/tc_utils/tc_diag/tc_diag.cc +++ b/src/tools/tc_utils/tc_diag/tc_diag.cc @@ -1331,14 +1331,11 @@ void copy_time_vars(NcFile *to_nc, NcFile *from_nc, int i_time) { } // Allocate buffer - double *buf = new double[buf_size]; + vector buf(buf_size); // Copy the data for this time slice - get_nc_data(&from_var, buf); - to_var.putVar(offsets, counts, buf); - - // Cleanup - if(buf) { delete[] buf; buf = (double *) nullptr; } + get_nc_data(&from_var, buf.data()); + to_var.putVar(offsets, counts, buf.data()); } // end for i @@ -1665,7 +1662,7 @@ void OutFileInfo::write_nc_diag() { // Allocate space int n_prs_data = vld_dim.getSize() * prs_dim.getSize(); - float *prs_data = new float [n_prs_data]; + vector prs_data(n_prs_data); ConcatString diag_name; // Loop over the pressure diagnostic names @@ -1698,7 +1695,7 @@ void OutFileInfo::write_nc_diag() { } // end for j // Write the data - write_nc_diag_prs_vals(prs_diag[i], prs_data); + write_nc_diag_prs_vals(prs_diag[i], prs_data.data()); } // end for i @@ -1708,9 +1705,6 @@ void OutFileInfo::write_nc_diag() { write_nc_diag_vals(*it, diag_custom_map.at(*it)); } - // Clean up - if(prs_data) { delete [] prs_data; prs_data = (float *) nullptr; } - return; } @@ -2198,8 +2192,8 @@ void TmpFileInfo::setup_nc_file(const DomainInfo &di, // Define latitude and longitude arrays TcrmwData d = di.data; int nra = d.range_n * d.azimuth_n; - double *lat_arr = new double[nra]; - double *lon_arr = new double[nra]; + vector lat_arr(nra); + vector lon_arr(nra); // Set grid center d.lat_center = pnt_ptr->lat(); @@ -2262,19 +2256,15 @@ void TmpFileInfo::setup_nc_file(const DomainInfo &di, lat_var, lon_var); // Compute lat and lon coordinate arrays - compute_lat_lon(ra_grid, lat_arr, lon_arr); + compute_lat_lon(ra_grid, lat_arr.data(), lon_arr.data()); // Write coordinate arrays - write_tc_data(tmp_out, ra_grid, 0, lat_var, lat_arr); - write_tc_data(tmp_out, ra_grid, 0, lon_var, lon_arr); + write_tc_data(tmp_out, ra_grid, 0, lat_var, lat_arr.data()); + write_tc_data(tmp_out, ra_grid, 0, lon_var, lon_arr.data()); // Write track point values write_tc_track_point(tmp_out, vld_dim, *pnt_ptr); - // Clean up - if(lat_arr) { delete[] lat_arr; lat_arr = (double *) nullptr; } - if(lon_arr) { delete[] lon_arr; lon_arr = (double *) nullptr; } - return; } diff --git a/src/tools/tc_utils/tc_dland/tc_dland.cc b/src/tools/tc_utils/tc_dland/tc_dland.cc index 0a563b5e30..97c1e21d25 100644 --- a/src/tools/tc_utils/tc_dland/tc_dland.cc +++ b/src/tools/tc_utils/tc_dland/tc_dland.cc @@ -203,7 +203,6 @@ void process_land_data() { void process_distances() { int n, x, y, c, npts, nlog, imin; double lat, lon; - float *dland = (float *) nullptr; // Instantiate the grid Grid grid(GridData); @@ -250,7 +249,7 @@ void process_distances() { add_att(&dland_var, "_FillValue", bad_data_float); // Allocate memory to store the data values for each grid point - dland = new float [grid.nx()*grid.ny()]; + vector dland(grid.nx()*grid.ny()); // Dump out grid info mlog << Debug(2) @@ -294,16 +293,13 @@ void process_distances() { // Write the computed distances to the output file mlog << Debug(3) << "Writing distance to land variable.\n"; - if(!put_nc_data_with_dims(&dland_var, &dland[0], grid.ny(), grid.nx())) { - if(dland) { delete [] dland; dland = (float *) nullptr; } + if(!put_nc_data_with_dims(&dland_var, dland.data(), grid.ny(), grid.nx())) { + delete f_out; mlog << Error << "\nprocess_distances() -> " << "error with dland_var->put\n\n"; exit(1); } - // Delete allocated memory - if(dland) { delete [] dland; dland = (float *) nullptr; } - // Close the output NetCDF file delete f_out; f_out = (NcFile *) nullptr; diff --git a/src/tools/tc_utils/tc_gen/tc_gen.cc b/src/tools/tc_utils/tc_gen/tc_gen.cc index 7c6a44c16e..c02f65e9b4 100644 --- a/src/tools/tc_utils/tc_gen/tc_gen.cc +++ b/src/tools/tc_utils/tc_gen/tc_gen.cc @@ -2412,10 +2412,9 @@ void write_nc(GenCTCInfo &gci) { unixtime valid_end = (unixtime) 0; // Allocate memory - float *data = (float *) nullptr; int nx = gci.NcOutGrid->nx(); int ny = gci.NcOutGrid->ny(); - data = new float [nx*ny]; + vector data(nx*ny, 0.0); // Loop over vector of output types for(i=0; i " << "error writing NetCDF variable name " << var_name << "\n\n"; @@ -2543,9 +2539,6 @@ void write_nc(GenCTCInfo &gci) { } } - // Deallocate and clean up - if(data) { delete [] data; data = (float *) nullptr; } - return; }