Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #2474 sonarqube_findings_ncutil #2512

Merged
merged 9 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/basic/vx_math/nti.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ y = ca2;
// reduce x and y as much as possible
//

n = (y*L_over_b - x*L_over_a)/( L_over_a*L_over_a + L_over_b*L_over_b );
n = (0 == L_over_a && 0 == L_over_b) ?
0 : (y*L_over_b - x*L_over_a)/( L_over_a*L_over_a + L_over_b*L_over_b );

x += n*L_over_a;
y -= n*L_over_b;
Expand Down
9 changes: 7 additions & 2 deletions src/basic/vx_util/two_d_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ T TwoD_Array<T>::operator()(int _x, int _y) const

{

return ( E[two_to_one(_x, _y)] );
return ( get(_x, _y) );

}

Expand All @@ -287,6 +287,11 @@ T TwoD_Array<T>::get(int _x, int _y) const

{

if (E == nullptr) {
mlog << Error << "\nTwoD_Array<T>::get(x,y) -> E is not initialized\n\n";
exit ( 1 );
}

return ( E[two_to_one(_x, _y)] );

}
Expand All @@ -301,7 +306,7 @@ bool TwoD_Array<T>::s_is_on(int _x, int _y) const

{

return ( (bool) (E[two_to_one(_x, _y)]) );
return ( (bool) (E == nullptr) ? false : (E[two_to_one(_x, _y)]) );

}

Expand Down
8 changes: 4 additions & 4 deletions src/libcode/vx_data2d_nc_met/met_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ double fill_value;
double missing_value = get_var_missing_value(var);
get_var_fill_value(var, fill_value);

status = get_nc_data(var, &d, (long *)a);
status = get_nc_data(var, &d, a);

if ( !status ) {

Expand Down Expand Up @@ -579,10 +579,10 @@ plane.set_size(Nx, Ny);
clock_t clock_time;
double nc_time;

long dim[dimCount], cur[dimCount];
LongArray dim, cur;
for (int index=0; index<dimCount; index++) {
dim[index] = 1;
cur[index] = (b[index] == vx_data2d_star) ? 0 : b[index];
dim.add(1);
cur.add((b[index] == vx_data2d_star) ? 0 : b[index]);
}
dim[x_slot] = Nx;
dim[y_slot] = Ny;
Expand Down
10 changes: 5 additions & 5 deletions src/libcode/vx_data2d_nc_pinterp/pinterp_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ double d = bad_data_double;
double missing_value = get_var_missing_value(var);
get_var_fill_value(var, fill_value);

status = get_nc_data(var, &d, (long *)a);
status = get_nc_data(var, &d, a);

if ( !status ) {

Expand Down Expand Up @@ -743,12 +743,12 @@ plane.set_size(Nx, Ny);
//
double d[Ny];

long offsets[dim_count];
long lengths[dim_count];
LongArray offsets;
LongArray lengths;

for (int k=0; k<dim_count; k++) {
offsets[k] = (a[k] == vx_data2d_star) ? 0 : a[k];
lengths[k] = 1;
offsets.add((a[k] == vx_data2d_star) ? 0 : a[k]);
lengths.add(1);
}
lengths[y_slot] = Ny;

Expand Down
18 changes: 10 additions & 8 deletions src/libcode/vx_data2d_nccf/nccf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ double NcCfFile::getData(NcVar * var, const LongArray & a) const
double missing_value = get_var_missing_value(var);
get_var_fill_value(var, fill_value);

status = get_nc_data(var, &d, (long *)a);
status = get_nc_data(var, &d, a);

if (!status)
{
Expand Down Expand Up @@ -1049,11 +1049,11 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
double *d = new double[plane_size];

size_t dim_size;
long offsets[dim_count];
long lengths[dim_count];
LongArray offsets;
LongArray lengths;
for (int k=0; k<dim_count; k++) {
offsets[k] = (a[k] == vx_data2d_star) ? 0 : a[k];
lengths[k] = 1;
offsets.add((a[k] == vx_data2d_star) ? 0 : a[k]);
lengths.add(1);
dim_size = v->getDim(k).getSize();
if (dim_size < offsets[k]) {
mlog << Error << "\n" << method_name
Expand Down Expand Up @@ -3202,9 +3202,11 @@ LatLonData NcCfFile::get_data_from_lat_lon_vars(NcVar *lat_var, NcVar *lon_var,
bool lat_first = false;
if (two_dim_coord) {
lat_first = (lat_counts == get_dim_size(lat_var, 0));
long cur[2], length[2];
cur[0] = cur[1] = 0;
length[0] = length[1] = 1;
LongArray cur, length; // {0,0}, {1,1}
cur.add(0);
cur.add(0);
length.add(1);
length.add(1);
if (lat_first) length[0] = lat_counts;
else length[1] = lat_counts;
get_nc_data(lat_var,lat_values, length, cur);
Expand Down
30 changes: 22 additions & 8 deletions src/libcode/vx_nc_obs/nc_obs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,17 @@ void NetcdfObsVars::read_header_data(MetPointHeader &hdr_data) {
float *hdr_lon_block = new float[buf_size];
float *hdr_elv_block = new float[buf_size];

long offsets[2] = { 0, 0 };
long lengths[2] = { 1, 1 };
long offsets_1D[1] = { 0 };
long lengths_1D[1] = { 1 };
LongArray offsets; // = { 0, 0 };
LongArray lengths; // = { 1, 1 };
LongArray offsets_1D; // = { 0 };
LongArray lengths_1D; // = { 1 };

offsets.add(0);
offsets.add(0);
lengths.add(1);
lengths.add(1);
offsets_1D.add(0);
lengths_1D.add(1);

for(int i_start=0; i_start<nhdr_count; i_start+=buf_size) {
buf_size = ((nhdr_count-i_start) > NC_BUFFER_SIZE_32K)
Expand Down Expand Up @@ -821,10 +828,14 @@ void NetcdfObsVars::read_header_data(MetPointHeader &hdr_data) {
bool NetcdfObsVars::read_obs_data(int buf_size, int offset,
int qty_len, float *obs_arr, int *qty_idx_arr, char *obs_qty_buf) {
bool result = true;
long offsets[2] = { offset, 0 };
long lengths[2] = { buf_size, 1 };
LongArray offsets; // = { offset, 0 };
LongArray lengths; // = { buf_size, 1 };
const char *method_name = "read_obs_data() -> ";

offsets.add(offset);
offsets.add(0);
lengths.add(buf_size);
lengths.add(1);
if (IS_VALID_NC(obs_arr_var)) {
// Read the current observation message
lengths[1] = OBS_ARRAY_LEN;
Expand Down Expand Up @@ -921,8 +932,8 @@ void NetcdfObsVars::read_pb_hdr_data(MetPointHeader &hdr_data) {
return;
}

long offsets[1] = { 0 };
long lengths[1] = { 1 };
LongArray offsets; // = { 0 };
LongArray lengths; // = { 1 };
bool has_hdr_prpt_typ_var = !IS_INVALID_NC(hdr_prpt_typ_var);
bool has_hdr_irpt_typ_var = !IS_INVALID_NC(hdr_irpt_typ_var);
bool has_hdr_inst_typ_var = !IS_INVALID_NC(hdr_inst_typ_var);
Expand All @@ -931,6 +942,9 @@ void NetcdfObsVars::read_pb_hdr_data(MetPointHeader &hdr_data) {
if (has_hdr_irpt_typ_var) hdr_data.irpt_typ_array.extend(pb_hdr_count);
if (has_hdr_inst_typ_var) hdr_data.inst_typ_array.extend(pb_hdr_count);

offsets.add(0);
lengths.add(1);

// Read PB report type
int buf_size = ((pb_hdr_count > NC_BUFFER_SIZE_32K)
? NC_BUFFER_SIZE_32K : (pb_hdr_count));
Expand Down
48 changes: 27 additions & 21 deletions src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ float get_float_var(NcVar * var, const int index) {

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, int *data, const long *curs) {
bool get_nc_data(NcVar *var, int *data, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, bad_data_int, curs);

return(return_status);
Expand Down Expand Up @@ -1307,23 +1307,23 @@ bool get_nc_data(NcVar *var, int *data, const long dim, const long cur) {

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, int *data, const long *dims, const long *curs) {
bool get_nc_data(NcVar *var, int *data, const LongArray &dims, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, bad_data_int, dims, curs);

return(return_status);
}

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, short *data, const long *curs) {
bool get_nc_data(NcVar *var, short *data, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, (short)bad_data_int, curs);

return(return_status);
}

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, short *data, const long *dims, const long *curs) {
bool get_nc_data(NcVar *var, short *data, const LongArray &dims, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, (short)bad_data_int, dims, curs);

return(return_status);
Expand Down Expand Up @@ -1421,13 +1421,13 @@ bool get_nc_data(NcVar *var, float *data) {
for (int idx=0; idx<cell_count; idx++) {
ushort_data[idx] =(unsigned short)packed_data[idx];
}
copy_nc_data_t(var, data, ushort_data, cell_count,
copy_nc_data_t(var, data, ushort_data, cell_count,
"ushort", add_offset, scale_factor,
has_missing, (unsigned short)missing_value);
delete [] ushort_data;
}
else {
copy_nc_data_t(var, data, packed_data, cell_count,
copy_nc_data_t(var, data, packed_data, cell_count,
"short", add_offset, scale_factor,
has_missing, missing_value);
}
Expand Down Expand Up @@ -1496,15 +1496,15 @@ bool get_nc_data(NcVar *var, float *data) {

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, float *data, const long *curs) {
bool get_nc_data(NcVar *var, float *data, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, bad_data_float, curs);

return(return_status);
}

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, float *data, const long *dims, const long *curs) {
bool get_nc_data(NcVar *var, float *data, const LongArray &dims, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, bad_data_float, dims, curs);

return(return_status);
Expand All @@ -1521,7 +1521,7 @@ bool get_nc_data(NcVar *var, float *data, const long dim, const long cur) {
////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcFile *nc, const char *var_name, double *data,
const long *dims, const long *curs) {
const LongArray &dims, const LongArray &curs) {

//
// Retrieve the input variables
Expand Down Expand Up @@ -1620,13 +1620,13 @@ bool get_nc_data(NcVar *var, double *data) {
for (int idx=0; idx<cell_count; idx++) {
ushort_data[idx] =(unsigned short)packed_data[idx];
}
copy_nc_data_t(var, data, ushort_data, cell_count,
copy_nc_data_t(var, data, ushort_data, cell_count,
"ushort", add_offset, scale_factor,
has_missing, (unsigned short)missing_value);
delete [] ushort_data;
}
else {
copy_nc_data_t(var, data, packed_data, cell_count,
copy_nc_data_t(var, data, packed_data, cell_count,
"short", add_offset, scale_factor,
has_missing, missing_value);
}
Expand Down Expand Up @@ -1692,7 +1692,7 @@ bool get_nc_data(NcVar *var, double *data) {

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, double *data, const long *curs) {
bool get_nc_data(NcVar *var, double *data, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, bad_data_double, curs);
return(return_status);
}
Expand All @@ -1707,7 +1707,8 @@ bool get_nc_data(NcVar *var, double *data, const long dim, const long cur) {

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, double *data, const long *dims, const long *curs) {
bool get_nc_data(NcVar *var, double *data, const LongArray &dims,
const LongArray &curs) {
bool return_status = get_nc_data_(var, data, bad_data_double, dims, curs);

return(return_status);
Expand Down Expand Up @@ -1795,7 +1796,7 @@ bool get_nc_data(NcVar *var, unsigned short *data) {
////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcFile *nc, const char *var_name, char *data,
const long *dims, const long *curs) {
const LongArray &dims, const LongArray &curs) {

//
// Retrieve the input variables
Expand All @@ -1814,7 +1815,7 @@ bool get_nc_data(NcVar *var, char *data, const long dim, const long cur) {

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, char *data, const long *dims, const long *curs) {
bool get_nc_data(NcVar *var, char *data, const LongArray &dims, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, bad_data_char, dims, curs);

return(return_status);
Expand All @@ -1833,7 +1834,7 @@ bool get_nc_data(NcVar *var, ncbyte *data) {
////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcFile *nc, const char *var_name, ncbyte *data,
const long *dims, const long *curs) {
const LongArray &dims, const LongArray &curs) {

//
// Retrieve the input variables
Expand All @@ -1852,7 +1853,7 @@ bool get_nc_data(NcVar *var, ncbyte *data, const long dim, const long cur) {

////////////////////////////////////////////////////////////////////////

bool get_nc_data(NcVar *var, ncbyte *data, const long *dims, const long *curs) {
bool get_nc_data(NcVar *var, ncbyte *data, const LongArray &dims, const LongArray &curs) {
bool return_status = get_nc_data_(var, data, (ncbyte)bad_data_char, dims, curs);

return(return_status);
Expand All @@ -1867,7 +1868,7 @@ int get_index_at_nc_data(NcVar *var, double value, const string dim_name, bool i
if (IS_VALID_NC_P(var)) {
int data_size = get_data_size(var);
double *values = new double[data_size];

if (get_nc_data(var, values)) {
unixtime ut;
int sec_per_unit;
Expand Down Expand Up @@ -1935,14 +1936,19 @@ bool get_nc_data_to_array(NcVar *var, StringArray *array_buf) {
<< GET_NC_NAME_P(var) << "\n\n";
}
else {
long offsets[2] = { 0, 0 };
long lengths[2] = { 1, 1 };
LongArray offsets; // { 0, 0 };
LongArray lengths; // { 1, 1 };
NcDim count_dim = var->getDim(dim_count-2);
NcDim str_dim = var->getDim(dim_count-1);
int count = get_dim_size(&count_dim);
int str_len = get_dim_size(&str_dim);
lengths[1] = str_len;
char str_buffer[str_len+1];

offsets.add(0);
offsets.add(0);
lengths.add(1);
lengths.add(str_len);

result = true;
for (int idx=0; idx<count; idx++) {
if(!get_nc_data(var, str_buffer, lengths, offsets)) {
Expand Down
Loading