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 2472 sonarqube findings mtd and madis2nc #2526

Merged
merged 9 commits into from
May 3, 2023
4 changes: 2 additions & 2 deletions src/libcode/vx_python3_utils/python3_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Python3_Script {

ConcatString filename() const;

PyObject * module();
PyObject * get_module();
PyObject * dict();
PyObject * module_ascii();
PyObject * dict_ascii();
Expand Down Expand Up @@ -92,7 +92,7 @@ class Python3_Script {
////////////////////////////////////////////////////////////////////////


inline PyObject * Python3_Script::module() { return ( Module ); }
inline PyObject * Python3_Script::get_module() { return ( Module ); }

inline PyObject * Python3_Script::dict() { return ( Dict ); }

Expand Down
32 changes: 17 additions & 15 deletions src/tools/other/madis2nc/madis2nc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ static void setup_netcdf_out(int nhdr);

static bool get_filtered_nc_data(NcVar var, float *data, const long dim,
const long cur, const char *var_name, bool required=true);
// Added data_len for SonarQube
static bool get_filtered_nc_data_2d(NcVar var, int *data, const LongArray &dim,
const LongArray &cur, const char *var_name,
bool count_bad=false);
int data_len=0, bool count_bad=false);
static bool get_filtered_nc_data_2d(NcVar var, float *data, const LongArray &dim,
const LongArray &cur, const char *var_name,
bool count_bad=false);
int data_len=0, bool count_bad=false);

static void check_quality_control_flag(int &value, const char qty, const char *var_name);
static void check_quality_control_flag(float &value, const char qty, const char *var_name);
Expand Down Expand Up @@ -459,12 +460,12 @@ static bool get_filtered_nc_data(NcVar var, float *data,

static bool get_filtered_nc_data_2d(NcVar var, int *data, const LongArray &dim,
const LongArray &cur, const char *var_name,
bool count_bad) {
int data_len, bool count_bad) {

bool status = false;
int data_len = dim[0] * dim[1];
const char *method_name = "get_filtered_nc_data_2d(int) ";

if (data_len <= 0) data_len = dim[0] * dim[1];
for (int offset=0; offset<data_len; offset++) {
data[offset] = bad_data_int;
}
Expand Down Expand Up @@ -503,12 +504,12 @@ static bool get_filtered_nc_data_2d(NcVar var, int *data, const LongArray &dim,

static bool get_filtered_nc_data_2d(NcVar var, float *data, const LongArray &dim,
const LongArray &cur, const char *var_name,
bool count_bad) {
int data_len, bool count_bad) {

bool status = false;
int data_len = dim[0] * dim[1];
const char *method_name = "get_filtered_nc_data_2d(float) ";

if (data_len <= 0) data_len = dim[0] * dim[1];
for (int offset=0; offset<data_len; offset++) {
data[offset] = bad_data_float;
}
Expand Down Expand Up @@ -2135,8 +2136,8 @@ void process_madis_profiler(NcFile *&f_in) {
if (IS_VALID_NC(in_vComponentQty_var)) get_nc_data(&in_vComponentQty_var, (char *)vComponentQty_arr, dim, cur);
else memset(vComponentQty_arr, 0, data_cnt*sizeof(char));

get_filtered_nc_data_2d(in_uComponent_var, (float *)uComponent_arr, dim, cur, "uComponent");
get_filtered_nc_data_2d(in_vComponent_var, (float *)vComponent_arr, dim, cur, "vComponent");
get_filtered_nc_data_2d(in_uComponent_var, (float *)uComponent_arr, dim, cur, "uComponent", data_cnt);
get_filtered_nc_data_2d(in_vComponent_var, (float *)vComponent_arr, dim, cur, "vComponent", data_cnt);

for (int i_idx=0; i_idx<buf_size; i_idx++) {

Expand Down Expand Up @@ -3354,13 +3355,14 @@ void process_madis_acarsProfiles(NcFile *&f_in) {
cur[0] = i_hdr_s;
dim[0] = buf_size;
dim[1] = maxLevels;
data_cnt = buf_size * maxLevels;

get_nc_data(&in_hdr_vld_var, tmp_dbl_arr, dim, cur);
get_nc_data(&in_hdr_lat_var, (float *)hdr_lat_arr, dim, cur);
get_nc_data(&in_hdr_lon_var, (float *)hdr_lon_arr, dim, cur);
get_filtered_nc_data_2d(in_hdr_elv_var, (float *)hdr_elv_arr, dim, cur, "elevation");
get_filtered_nc_data_2d(in_hdr_elv_var, (float *)hdr_elv_arr, dim, cur, "elevation", data_cnt);


data_cnt = buf_size * maxLevels;
if (IS_VALID_NC(in_temperatureQty_var)) get_nc_data(&in_temperatureQty_var, (char *)&temperatureQty_arr, dim, cur);
else memset(temperatureQty_arr, 0, data_cnt*sizeof(char));
if (IS_VALID_NC(in_dewpointQty_var)) get_nc_data(&in_dewpointQty_var, (char *)&dewpointQty_arr, dim, cur);
Expand All @@ -3372,11 +3374,11 @@ void process_madis_acarsProfiles(NcFile *&f_in) {
if (IS_VALID_NC(in_altitudeQty_var)) get_nc_data(&in_altitudeQty_var, (char *)&altitudeQty_arr, dim, cur);
else memset(altitudeQty_arr, 0, data_cnt*sizeof(char));

get_filtered_nc_data_2d(in_hdr_tob_var, (int *)&obsTimeOfDay_arr, dim, cur, "obsTimeOfDay");
get_filtered_nc_data_2d(in_temperature_var, (float *)&temperature_arr, dim, cur, "temperature");
get_filtered_nc_data_2d(in_dewpoint_var, (float *)&dewpoint_arr, dim, cur, "dewpoint");
get_filtered_nc_data_2d(in_windDir_var, (float *)&windDir_arr, dim, cur, "windDir");
get_filtered_nc_data_2d(in_windSpeed_var, (float *)&windSpeed_arr, dim, cur, "windSpeed");
get_filtered_nc_data_2d(in_hdr_tob_var, (int *)&obsTimeOfDay_arr, dim, cur, "obsTimeOfDay", data_cnt);
get_filtered_nc_data_2d(in_temperature_var, (float *)&temperature_arr, dim, cur, "temperature", data_cnt);
get_filtered_nc_data_2d(in_dewpoint_var, (float *)&dewpoint_arr, dim, cur, "dewpoint", data_cnt);
get_filtered_nc_data_2d(in_windDir_var, (float *)&windDir_arr, dim, cur, "windDir", data_cnt);
get_filtered_nc_data_2d(in_windSpeed_var, (float *)&windSpeed_arr, dim, cur, "windSpeed", data_cnt);

dim[1] = hdr_sid_len;
get_nc_data(&in_hdr_sid_var, (char *)hdr_sid_arr, dim, cur);
Expand Down
3 changes: 2 additions & 1 deletion src/tools/other/mode_time_domain/interest_calc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void InterestCalculator::assign(const InterestCalculator & i)

clear();

if ( i.Nelements == 0 ) return;
if ( i.Nelements <= 0 ) return;

extend(i.Nelements);

Expand Down Expand Up @@ -256,6 +256,7 @@ if ( _weight < 0.0 ) {

}

if (Nelements < 0) Nelements = 0; // SonarQube findings

extend(Nelements + 1);

Expand Down
9 changes: 7 additions & 2 deletions src/tools/other/mode_time_domain/mtd_file_int.cc
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void MtdIntFile::fatten()
int x, y, n;
const int nxy = Nx*Ny;
int * u = new int [nxy];
int * a = 0;
int * a = nullptr;

a = u;

Expand Down Expand Up @@ -899,7 +899,9 @@ for (y = 0; y<(Ny - 2); ++y) {

for (x=0; x<(Nx - 2); ++x) {

if ( *a ) {
if (n >= (nxy-1)) break; // For SonarQube findings

if (n >=0 && *a ) {

Data[n + 1] = 1; // (x + 1, y)
Data[n + Nx] = 1; // (x, y + 1)
Expand Down Expand Up @@ -1719,11 +1721,14 @@ s.set_to_zeroes();

int * in = Data;
int * out = s.Data;
int out_size = s.nxyt();

v = 0;

for (j=0; j<n3; ++j) {

if (j >= out_size) break; // For SonarQube findings

if ( yesno[*in] ) { *out = 1; ++v; }

++in;
Expand Down
4 changes: 4 additions & 0 deletions src/tools/other/mode_time_domain/mtd_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ void EquivalenceClass::add_no_repeat(int k)

if ( has(k) ) return;

if (Nelements < 0) Nelements = 0;

extend(Nelements + 1);

E[Nelements++] = k;
Expand Down Expand Up @@ -685,6 +687,8 @@ void Mtd_Partition::add_no_repeat(int k)

if ( has(k) ) return;

if (Nelements < 0) Nelements = 0;

extend(Nelements + 1);

C[Nelements] = new EquivalenceClass;
Expand Down