Skip to content
Open
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
18 changes: 18 additions & 0 deletions packages/src/cf_timeseries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include "cf_time_series.h"
#include "netcdf.h"
#include<boost/algorithm/string/split.hpp>
#include<boost/algorithm/string.hpp>

using namespace std;

Expand All @@ -45,7 +47,7 @@
this->type = ftype;
this->tsfilefilename = strdup(this->fname.absoluteFilePath().toUtf8());
m_nr_par_loc = 0;
time_var_name = NULL;

Check failure on line 50 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the "nullptr" literal.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPc7&open=AZ0Gk2zRSrNuz-3DzPc7&pullRequest=1

Check warning on line 50 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not assign data members in a constructor. Initialize member "time_var_name" in an initialization list.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPc6&open=AZ0Gk2zRSrNuz-3DzPc6&pullRequest=1
datetime_ntimes = 0;
m_pre_selection = false;
m_cb_parloc_index = -1;
Expand All @@ -53,7 +55,7 @@
TSFILE::~TSFILE()
{
delete tsfilefilename;
delete[] time_var_name;

Check failure on line 58 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rewrite the code so that you no longer need this "delete".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPc8&open=AZ0Gk2zRSrNuz-3DzPc8&pullRequest=1
for (int i = 0; i < this->global_attributes->count; i++)
{
if (this->global_attributes->attribute[i]->name != NULL) free(this->global_attributes->attribute[i]->name); this->global_attributes->attribute[i]->name = NULL;
Expand Down Expand Up @@ -138,7 +140,7 @@
{
QMessageBox::warning(NULL, QObject::tr("Warning"), QObject::tr("Only HISTORY is yet supported"));
}
if (time_var_name == NULL)

Check failure on line 143 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the "nullptr" literal.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPc9&open=AZ0Gk2zRSrNuz-3DzPc9&pullRequest=1
{
QMessageBox::warning(NULL, QObject::tr("Error"), QString("No time variable found in file:\n%1.\nFile will not be read.").arg(this->tsfilefilename));
return 1;
Expand Down Expand Up @@ -173,27 +175,35 @@
status = nc_inq_attlen(this->m_ncid, i_var, "units", &length);
if (status == NC_NOERR)
{
c_units = (char *)malloc(sizeof(char) * (length + 1));

Check failure on line 178 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "malloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdA&open=AZ0Gk2zRSrNuz-3DzPdA&pullRequest=1
c_units[length] = '\0';
status = nc_get_att(this->m_ncid, i_var, "units", c_units);
QString units = QString(c_units).replace("T", " "); // "seconds since 1970-01-01T00:00:00" changed into "seconds since 1970-01-01 00:00:00"
date_time = units.split(" ");
if (date_time.count()>=2)
{
if (!strcmp("since", date_time.at(1).toUtf8()))

Check failure on line 185 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPc-&open=AZ0Gk2zRSrNuz-3DzPc-&pullRequest=1
{
// now it is the time variable, can only be detected by the "seconds since 1970-01-01T00:00:00" character string
// retrieve the long_name, standard_name -> var_name for the xaxis label
length = (size_t) -1;
status = nc_inq_var(this->m_ncid, i_var, var_name, NULL, &ndims, &dimids, &natts);

Check failure on line 190 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the "nullptr" literal.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdD&open=AZ0Gk2zRSrNuz-3DzPdD&pullRequest=1

// skip variable where name contains analysis_time
string var_name_str(var_name);
string var_sub_str("analysis_time");
if (var_name_str.find(var_sub_str) != string::npos) {

Check warning on line 195 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "contains" instead of "find".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdE&open=AZ0Gk2zRSrNuz-3DzPdE&pullRequest=1
continue;
}

status = nc_inq_attlen(this->m_ncid, i_var, "long_name", &length);
if (status == NC_NOERR)
{
char * c_label = (char *)malloc(sizeof(char) * (length + 1));

Check failure on line 202 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "malloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdH&open=AZ0Gk2zRSrNuz-3DzPdH&pullRequest=1
c_label[length] = '\0';
status = nc_get_att(this->m_ncid, i_var, "long_name", c_label);
this->xaxis_label = QString(c_label);
free(c_label); c_label = NULL;

Check failure on line 206 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdG&open=AZ0Gk2zRSrNuz-3DzPdG&pullRequest=1
}
else
{
Expand All @@ -219,14 +229,14 @@
QString janm1 = this->RefDate->toString("yyyy-MM-dd hh:mm:ss.zzz");
QString janm2 = this->RefDate->toUTC().toString("yyyy-MM-dd hh:mm:ss.zzz");
#endif
double * times_c = (double *)malloc(sizeof(double)*datetime_ntimes);

Check failure on line 232 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "malloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdJ&open=AZ0Gk2zRSrNuz-3DzPdJ&pullRequest=1

Check warning on line 232 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdB&open=AZ0Gk2zRSrNuz-3DzPdB&pullRequest=1
status = nc_get_var_double(this->m_ncid, i_var, times_c);
for (int i = 0; i < datetime_ntimes; i++)
{
m_times.time.push_back(times_c[i]);
m_times.pre_selected.push_back(0); // not pre selected
}
free(times_c);

Check failure on line 239 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdC&open=AZ0Gk2zRSrNuz-3DzPdC&pullRequest=1
times_c = nullptr;
if (datetime_ntimes >= 2)
{
Expand Down Expand Up @@ -302,7 +312,7 @@
break;
}
}
free(c_units);

Check failure on line 315 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPc_&open=AZ0Gk2zRSrNuz-3DzPc_&pullRequest=1
}
}
free(var_name); var_name = NULL;
Expand All @@ -316,7 +326,7 @@
{
return this->m_times;
}
void TSFILE::put_times(_time times)

Check warning on line 329 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Pass large object "times" by reference to const.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdK&open=AZ0Gk2zRSrNuz-3DzPdK&pullRequest=1
{
this->m_times = times;
return;
Expand Down Expand Up @@ -353,7 +363,7 @@
long i_par_loc = -1;
long i_param = -1;

if (this->time_var_name == NULL)

Check failure on line 366 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the "nullptr" literal.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdQ&open=AZ0Gk2zRSrNuz-3DzPdQ&pullRequest=1
{
return;
}
Expand Down Expand Up @@ -396,9 +406,17 @@
status = nc_inq_attlen(this->m_ncid, i_var, "coordinates", &length);
if (status == NC_NOERR)
{
coord = (char *)malloc(sizeof(char) * (length + 1));

Check failure on line 409 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "malloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdR&open=AZ0Gk2zRSrNuz-3DzPdR&pullRequest=1
status = nc_get_att(this->m_ncid, i_var, "coordinates", coord);
coord[length] = '\0';

// if coordinates contains multiple elements, ignore it then
vector<string> strVec;
using boost::is_any_of;
boost::algorithm::split(strVec, string(coord), is_any_of(" "),boost::token_compress_on);
if (strVec.size() > 1) {
status = nc_inq_attlen(this->m_ncid, i_var, "babaslfalskjlskdjflksdjf", &length);
}
}

if (status != NC_NOERR)
Expand Down Expand Up @@ -433,16 +451,16 @@
for (int i = 0; i < m_nr_par_loc; i++)
{
char * crd = strdup(this->par_loc[i]->location_var_name);
if (strstr(coord, (const char *)crd))

Check warning on line 454 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::string_view::contains" instead of "strstr".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdV&open=AZ0Gk2zRSrNuz-3DzPdV&pullRequest=1
{
i_par_loc = i;
i_param = this->par_loc[i_par_loc]->nr_parameters;
this->par_loc[i_par_loc]->nr_parameters += 1;
this->nr_parameters = this->par_loc[i_par_loc]->nr_parameters;
delete crd;

Check failure on line 460 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rewrite the code so that you no longer need this "delete".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdW&open=AZ0Gk2zRSrNuz-3DzPdW&pullRequest=1
break;
}
delete crd;

Check failure on line 463 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rewrite the code so that you no longer need this "delete".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdU&open=AZ0Gk2zRSrNuz-3DzPdU&pullRequest=1
}
if (i_par_loc == -1 || i_param == -1)
{
Expand All @@ -467,11 +485,11 @@
status = nc_inq_attlen(this->m_ncid, i_var, "long_name", &length);
if (status == NC_NOERR)
{
char * parameter_name_c = (char *)malloc(sizeof(char) * (length + 1));

Check failure on line 488 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "malloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdZ&open=AZ0Gk2zRSrNuz-3DzPdZ&pullRequest=1
status = nc_get_att(this->m_ncid, i_var, "long_name", parameter_name_c);
parameter_name_c[length] = '\0';
parameter_name = strdup(StripWhiteSpaces(parameter_name_c));
free(parameter_name_c);

Check failure on line 492 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdY&open=AZ0Gk2zRSrNuz-3DzPdY&pullRequest=1
parameter_name_c = nullptr;
}
else
Expand All @@ -484,18 +502,18 @@
status = nc_inq_attlen(this->m_ncid, i_var, "units", &length);
if (status == NC_NOERR)
{
unit = (char *)malloc(sizeof(char) * (length + 1));

Check failure on line 505 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "malloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdb&open=AZ0Gk2zRSrNuz-3DzPdb&pullRequest=1
status = nc_get_att(this->m_ncid, i_var, "units", unit);
unit[length] = '\0';
this->par_loc[i_par_loc]->parameter[i_param]->unit = strdup(unit);
free(unit); unit = NULL;

Check failure on line 509 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the "nullptr" literal.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdc&open=AZ0Gk2zRSrNuz-3DzPdc&pullRequest=1

Check failure on line 509 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPda&open=AZ0Gk2zRSrNuz-3DzPda&pullRequest=1
}
else
{
this->par_loc[i_par_loc]->parameter[i_param]->unit = strdup("?");
}
free(parameter_name); parameter_name = NULL;

Check failure on line 515 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the "nullptr" literal.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdd&open=AZ0Gk2zRSrNuz-3DzPdd&pullRequest=1
free(coord); coord = NULL;

Check failure on line 516 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdT&open=AZ0Gk2zRSrNuz-3DzPdT&pullRequest=1
}
else
{
Expand Down Expand Up @@ -534,13 +552,13 @@
// because the coordinates attribute was not found; try long_name else use var_name
length = (size_t) -1;
status = nc_inq_attlen(this->m_ncid, i_var, "long_name", &length);
if (status == NC_NOERR)

Check failure on line 555 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdN&open=AZ0Gk2zRSrNuz-3DzPdN&pullRequest=1
{
char * parameter_name_c = (char *)malloc(sizeof(char) * (length + 1));

Check failure on line 557 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "malloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdh&open=AZ0Gk2zRSrNuz-3DzPdh&pullRequest=1

Check warning on line 557 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdf&open=AZ0Gk2zRSrNuz-3DzPdf&pullRequest=1
status = nc_get_att(this->m_ncid, i_var, "long_name", parameter_name_c);
parameter_name_c[length] = '\0';
parameter_name = strdup(StripWhiteSpaces(parameter_name_c));
free(parameter_name_c);

Check failure on line 561 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdg&open=AZ0Gk2zRSrNuz-3DzPdg&pullRequest=1
parameter_name_c = nullptr;
}
else
Expand All @@ -551,7 +569,7 @@

this->par_loc[i_par_loc]->parameter[i_param]->name = strdup(parameter_name);
status = nc_inq_attlen(this->m_ncid, i_var, "units", &length);
if (status == NC_NOERR)

Check failure on line 572 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdO&open=AZ0Gk2zRSrNuz-3DzPdO&pullRequest=1
{
unit = (char *)malloc(sizeof(char) * (length + 1));
status = nc_get_att(this->m_ncid, i_var, "units", unit);
Expand Down Expand Up @@ -618,11 +636,11 @@
status = nc_inq_attlen(this->m_ncid, i_var, "long_name", &length);
if (status == NC_NOERR)
{
char * parameter_name_c = (char *)malloc(sizeof(char) * (length + 1));

Check failure on line 639 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "malloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdm&open=AZ0Gk2zRSrNuz-3DzPdm&pullRequest=1

Check warning on line 639 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdk&open=AZ0Gk2zRSrNuz-3DzPdk&pullRequest=1
status = nc_get_att(this->m_ncid, i_var, "long_name", parameter_name_c);
parameter_name_c[length] = '\0';
parameter_name = StripWhiteSpaces(parameter_name_c);
free(parameter_name_c);

Check failure on line 643 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdl&open=AZ0Gk2zRSrNuz-3DzPdl&pullRequest=1
parameter_name_c = nullptr;
}
else
Expand Down Expand Up @@ -703,7 +721,7 @@
return status;
}

void TSFILE::read_locations()

Check failure on line 724 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 126 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdq&open=AZ0Gk2zRSrNuz-3DzPdq&pullRequest=1
{
// look for variable with cf_role == timeseries_id, that are the locations
int ndims, nvars, natts, nunlimited;
Expand Down Expand Up @@ -745,7 +763,7 @@
{
nc_type nc_type;
location_name_varid = i_var;
status = nc_inq_var(this->m_ncid, location_name_varid, var_name, &nc_type, &ndims, NULL, &natts);

Check failure on line 766 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the "nullptr" literal.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdu&open=AZ0Gk2zRSrNuz-3DzPdu&pullRequest=1
for (int i = 0; i < m_nr_par_loc; i++)
{
if (!strcmp(this->par_loc[i]->location_var_name, var_name))
Expand Down Expand Up @@ -816,7 +834,7 @@
}
ensure_capacity_locations(i_par_loc, m_nr_locations);
// reading 64 strings for each location, length of string??
if (nc_type == NC_STRING)

Check failure on line 837 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdr&open=AZ0Gk2zRSrNuz-3DzPdr&pullRequest=1
{
char ** location_strings = (char **)malloc(sizeof(char *) * (mem_length)+1);
status = nc_get_var_string(this->m_ncid, location_name_varid, location_strings);
Expand Down Expand Up @@ -1027,7 +1045,7 @@
return this->global_attributes;
}

vector<double> TSFILE::get_time_series(long cb_index, char * param_name, long loc_id, long layer_id)

Check warning on line 1048 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "param_name" is "char *".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdw&open=AZ0Gk2zRSrNuz-3DzPdw&pullRequest=1
{
int ndims, nvars, natts, nunlimited;
nc_type nc_type;
Expand All @@ -1047,8 +1065,8 @@
dim_name = (char *)malloc(sizeof(char) * (NC_MAX_NAME + 1));
var_name = (char *)malloc(sizeof(char) * (NC_MAX_NAME + 1));

status = nc_open(this->tsfilefilename, NC_NOWRITE, &this->m_ncid);

Check warning on line 1068 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'status' is never read

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPd5&open=AZ0Gk2zRSrNuz-3DzPd5&pullRequest=1
status = nc_inq(this->m_ncid, &ndims, &nvars, &natts, &nunlimited);

Check warning on line 1069 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'status' is never read

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPd6&open=AZ0Gk2zRSrNuz-3DzPd6&pullRequest=1
for (long i = 0; i < nvars; i++)
{
// look for the var_id of the nc_variable with long_name "parameter"
Expand All @@ -1058,19 +1076,19 @@
{
tmp_name = (char *)malloc(sizeof(char) * (length + 1));
tmp_name[length] = '\0';
status = nc_get_att(this->m_ncid, i, "long_name", tmp_name);

Check warning on line 1079 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'status' is never read

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPd7&open=AZ0Gk2zRSrNuz-3DzPd7&pullRequest=1
tmp_name = StripWhiteSpaces(tmp_name);
if (!strcmp(param_name, tmp_name))
{
par_id = i;
break;
}
free(tmp_name); tmp_name = NULL;

Check failure on line 1086 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdy&open=AZ0Gk2zRSrNuz-3DzPdy&pullRequest=1
}
else
{
// try var_name
status = nc_inq_var(this->m_ncid, i, var_name, NULL, NULL, NULL, NULL);

Check warning on line 1091 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'status' is never read

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPd8&open=AZ0Gk2zRSrNuz-3DzPd8&pullRequest=1
if (!strcmp(param_name, var_name))
{
par_id = i;
Expand All @@ -1080,7 +1098,7 @@
}

// retrieve the data belonging to the parameter variable
status = nc_inq_var(this->m_ncid, par_id, var_name, &nc_type, &ndims, NULL, &natts);

Check warning on line 1101 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'status' is never read

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPd9&open=AZ0Gk2zRSrNuz-3DzPd9&pullRequest=1

var_dims = (long *)malloc(sizeof(long) * ndims);
status = nc_inq_vardimid(this->m_ncid, par_id, (int *)var_dims);
Expand All @@ -1099,10 +1117,10 @@
if (nc_type == NC_DOUBLE)
{
double att_value;
status = nc_get_att_double(this->m_ncid, par_id, "_FillValue", &att_value);

Check warning on line 1120 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'status' is never read

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPeA&open=AZ0Gk2zRSrNuz-3DzPeA&pullRequest=1

y_array = (double*)malloc(sizeof(double) * mem_length);
status = nc_get_var_double(this->m_ncid, par_id, y_array);

Check warning on line 1123 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'status' is never read

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPeB&open=AZ0Gk2zRSrNuz-3DzPeB&pullRequest=1
for (int i = 0; i < mem_length; ++i)
{
if (y_array[i] == att_value) { y_array[i] = numeric_limits<double>::quiet_NaN(); }
Expand Down Expand Up @@ -1134,10 +1152,10 @@
{
j = j + 1;
ii = ii_layer + nr_layers * loc_id + nr_layers * nr_loc * i_times;
m_y_values.push_back(y_array[ii]);

Check failure on line 1155 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Forming reference to null pointer

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPeE&open=AZ0Gk2zRSrNuz-3DzPeE&pullRequest=1
}

free(y_array); y_array = nullptr;

Check failure on line 1158 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPdx&open=AZ0Gk2zRSrNuz-3DzPdx&pullRequest=1
free(var_dims); var_dims= nullptr;
free(dim_name); dim_name = nullptr;
free(var_name); var_name = nullptr;
Expand Down Expand Up @@ -1199,7 +1217,7 @@
}
else if (this->nr_parameters > 1)
{
this->par_loc[i_par_loc]->parameter = (struct _parameter **) realloc(this->par_loc[i_par_loc]->parameter, sizeof(struct _parameter *) * this->nr_parameters);

Check failure on line 1220 in packages/src/cf_timeseries.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "realloc".

See more on https://sonarcloud.io/project/issues?id=Deltares_PlotCFTS&issues=AZ0Gk2zRSrNuz-3DzPd4&open=AZ0Gk2zRSrNuz-3DzPd4&pullRequest=1
}
i_param = this->par_loc[i_par_loc]->nr_parameters - 1;
this->par_loc[i_par_loc]->parameter[i_param] = (struct _parameter *) malloc(sizeof(struct _parameter) * 1);
Expand Down