Commit 2052b4cb authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Fix cppcheck warnings.

parent 291f8440
Pipeline #2524 passed with stages
in 15 minutes and 37 seconds
......@@ -403,7 +403,7 @@ Expr(void *process)
{
cdoInitialize(process);
void *scanner;
void *scanner = NULL;
int yy_scan_string(const char *str, void *scanner);
yylex_init(&scanner);
......
......@@ -564,6 +564,7 @@ Importbinary(void *process)
if (var_zaxisID) Free(var_zaxisID);
if (var_dfrm) Free(var_dfrm);
if (pfi.infile) fclose(pfi.infile);
cdoFinish();
......
......@@ -25,21 +25,21 @@
#include <mpim_grid.h>
#define NTR2NSP(ntr) ((ntr + 1) * (ntr + 2))
#define NSP2NTR(nsp) ((int) ((((std::sqrt((double) (4 * nsp + 1))) - 3) / 2)))
#define NGP2NLEVEL(ngp) ((int) (log10(((double) ngp) / 80.) / std::log10(4.)))
#define NGP_ICON(nrooti, nlevel) ((int) (20 * nrooti * nrooti * ipow(4, nlevel)))
#define NSP2NTR(nsp) ((long) ((((std::sqrt((double) (4 * nsp + 1))) - 3) / 2)))
#define NGP2NLEVEL(ngp) ((long) (log10(((double) ngp) / 80.) / std::log10(4.)))
#define NGP_ICON(nrooti, nlevel) ((long) (20 * nrooti * nrooti * ipow(4, nlevel)))
/*#define NGP_GME(ni) ((ni+1)*(ni+1)*10)*/
#define NGP_GME(ni) (2 + ni * ni * 10)
#define NGP2NI(ngp) ((int) std::sqrt((double) ngp / 10.) - 1)
#define NGP2NI(ngp) ((long) std::sqrt((double) ngp / 10.) - 1)
static void
fac(int nlonin, int *nlonout, int *ierr)
fac(long nlonin, long *nlonout, int *ierr)
{
int n2 = 0;
int n3 = 0;
int n5 = 0;
long n2 = 0;
long n3 = 0;
long n5 = 0;
int m = nlonin;
long m = nlonin;
while (m % 2 == 0)
{
......@@ -71,14 +71,15 @@ fac(int nlonin, int *nlonout, int *ierr)
return;
}
static int
nlat2nlon(int nlat)
static long
nlat2nlon(long nlat)
{
if (nlat == 0) cdoAbort("nlat = 0!");
int nlon = 2 * nlat;
long nlon = 2 * nlat;
int m, ierr;
long m;
int ierr;
fac(nlon, &m, &ierr);
/* adjust till fft is possible */
while (ierr != 0)
......@@ -92,57 +93,68 @@ nlat2nlon(int nlat)
return nlon;
}
int
ngp2ntr(int ngp)
long
ngp2ntr(long ngp)
{
int ntr = (int) std::lround(std::sqrt(0.25 + ngp) - 1.5);
int nlonl = nlat_to_nlon(ntr_to_nlat_linear(ntr));
int nlatl = nlonl / 2;
long ntr = (long) std::lround(std::sqrt(0.25 + ngp) - 1.5);
long nlonl = nlat_to_nlon(ntr_to_nlat_linear(ntr));
long nlatl = nlonl / 2;
ntr = (2 * nlatl - 1) / 2;
return ntr;
}
int
ipow(int i1, int i2)
static long
ipow(long i1, long i2)
{
int i3 = 1;
long i3 = 1;
for (int i = 0; i < i2; ++i) i3 *= i1;
for (long i = 0; i < i2; ++i) i3 *= i1;
return i3;
}
void
lookup_ni(int nsp, int *nroot, int *ni)
static constexpr long NiMax = 12;
static void
lookup_ni(long nsp, long *nroot, long *ni)
{
int tbl2[12], tbl3[12], tbl5[12];
int i, d, d2, n2, d3, n3, d5, n5;
long tbl2[NiMax], tbl3[NiMax], tbl5[NiMax];
long d2 = 0, n2 = 0, d3 = 0, n3 = 0, d5 = 0, n5 = 0;
for (i = 0; i < 12; ++i)
for (long i = 0; i < NiMax; ++i)
{
tbl2[i] = 10 * 2 * 2 * ipow(4, (i + 1)) + 2;
tbl3[i] = 10 * 3 * 3 * ipow(4, (i + 1)) + 2;
tbl5[i] = 10 * 5 * 5 * ipow(4, (i + 1)) + 2;
}
for (i = 0; i < 12; ++i)
if (tbl2[i] >= nsp) break;
n2 = i;
d2 = tbl2[n2] - nsp;
for (i = 0; i < 12; ++i)
if (tbl3[i] >= nsp) break;
n3 = i;
d3 = tbl3[n3] - nsp;
for (i = 0; i < 12; ++i)
if (tbl5[i] >= nsp) break;
n5 = i;
d5 = tbl5[n5] - nsp;
d = d2;
for (long i = 0; i < NiMax; ++i)
if (tbl2[i] >= nsp)
{
n2 = i;
d2 = tbl2[n2] - nsp;
break;
}
for (long i = 0; i < NiMax; ++i)
if (tbl3[i] >= nsp)
{
n3 = i;
d3 = tbl3[n3] - nsp;
break;
}
for (long i = 0; i < NiMax; ++i)
if (tbl5[i] >= nsp)
{
n5 = i;
d5 = tbl5[n5] - nsp;
break;
}
long d = d2;
if (d3 < d) d = d3;
if (d5 < d) d = d5;
......@@ -163,35 +175,44 @@ lookup_ni(int nsp, int *nroot, int *ni)
}
}
void
lookup_rl(int nsp, int *nroot, int *nlevel)
static void
lookup_rl(long nsp, long *nroot, long *nlevel)
{
int tbl2[12], tbl3[12], tbl5[12];
int i, d, d2, n2, d3, n3, d5, n5;
long tbl2[NiMax], tbl3[NiMax], tbl5[NiMax];
long d2 = 0, n2 = 0, d3 = 0, n3 = 0, d5 = 0, n5 = 0;
for (i = 0; i < 12; ++i)
for (long i = 0; i < NiMax; ++i)
{
tbl2[i] = 20 * 2 * 2 * ipow(4, (i + 1));
tbl3[i] = 20 * 3 * 3 * ipow(4, (i + 1));
tbl5[i] = 20 * 5 * 5 * ipow(4, (i + 1));
}
for (i = 0; i < 12; ++i)
if (tbl2[i] >= nsp) break;
n2 = i;
d2 = tbl2[n2] - nsp;
for (i = 0; i < 12; ++i)
if (tbl3[i] >= nsp) break;
n3 = i;
d3 = tbl3[n3] - nsp;
for (i = 0; i < 12; ++i)
if (tbl5[i] >= nsp) break;
n5 = i;
d5 = tbl5[n5] - nsp;
d = d2;
for (long i = 0; i < NiMax; ++i)
if (tbl2[i] >= nsp)
{
n2 = i;
d2 = tbl2[n2] - nsp;
break;
}
for (long i = 0; i < NiMax; ++i)
if (tbl3[i] >= nsp)
{
n3 = i;
d3 = tbl3[n3] - nsp;
break;
}
for (long i = 0; i < NiMax; ++i)
if (tbl5[i] >= nsp)
{
n5 = i;
d5 = tbl5[n5] - nsp;
break;
}
long d = d2;
if (d3 < d) d = d3;
if (d5 < d) d = d5;
......@@ -217,20 +238,20 @@ Specinfo(void *process)
{
char arg[128], *parg;
bool nout1 = false, nout2 = false, nout3 = false;
int i;
int ntr1 = 0, nsp1 = 0, nlat1 = 0, nlon1 = 0, ngp1 = 0, ni1 = 0, ngp_gme1 = 0;
int ntr2 = 0, nsp2 = 0, nlat2 = 0, nlon2 = 0, ngp2 = 0, ni2 = 0, ngp_gme2 = 0;
int ntr3 = 0, nsp3 = 0, nlat3 = 0, nlon3 = 0, ngp3 = 0, ni3 = 0, ngp_gme3 = 0;
int nlevel1 = 0, nlevel2 = 0, nlevel3 = 0;
int ngp_icon1 = 0, ngp_icon2 = 0, ngp_icon3 = 0;
int nrootg1 = 0, nrootg2 = 0, nrootg3 = 0;
int nrooti1 = 0, nrooti2 = 0, nrooti3 = 0;
long i;
long ntr1 = 0, nsp1 = 0, nlat1 = 0, nlon1 = 0, ngp1 = 0, ni1 = 0, ngp_gme1 = 0;
long ntr2 = 0, nsp2 = 0, nlat2 = 0, nlon2 = 0, ngp2 = 0, ni2 = 0, ngp_gme2 = 0;
long ntr3 = 0, nsp3 = 0, nlat3 = 0, nlon3 = 0, ngp3 = 0, ni3 = 0, ngp_gme3 = 0;
long nlevel1 = 0, nlevel2 = 0, nlevel3 = 0;
long ngp_icon1 = 0, ngp_icon2 = 0, ngp_icon3 = 0;
long nrootg1 = 0, nrootg2 = 0, nrootg3 = 0;
long nrooti1 = 0, nrooti2 = 0, nrooti3 = 0;
cdoInitialize(process);
operatorInputArg("Txx, TLxx, NLON=xx, NLAT=xx, NIxx or ICONRyyLxx");
const int len = cdoOperatorArgv(0).size();
const long len = cdoOperatorArgv(0).size();
if ((len + 1) >= 128) cdoAbort("Parameter string too large!");
......@@ -535,15 +556,15 @@ Specinfo(void *process)
fprintf(stdout, "truncation nsp nlon nlat ngp gme ngp_gme icon ngp_icon\n");
if (nout2)
fprintf(stdout, " TL%-4d %8d %5d %5d %8d ni%d %8d R%dB%02d %8d\n", ntr2, nsp2, nlon2, nlat2, ngp2, ni2, ngp_gme2, nrooti2,
fprintf(stdout, " TL%-4ld %8ld %5ld %5ld %8ld ni%ld %8ld R%ldB%02ld %8ld\n", ntr2, nsp2, nlon2, nlat2, ngp2, ni2, ngp_gme2, nrooti2,
nlevel2, ngp_icon2);
if (nout1)
fprintf(stdout, " TQ%-4d %8d %5d %5d %8d ni%d %8d R%dB%02d %8d\n", ntr1, nsp1, nlon1, nlat1, ngp1, ni1, ngp_gme1, nrooti1,
fprintf(stdout, " TQ%-4ld %8ld %5ld %5ld %8ld ni%ld %8ld R%ldB%02ld %8ld\n", ntr1, nsp1, nlon1, nlat1, ngp1, ni1, ngp_gme1, nrooti1,
nlevel1, ngp_icon1);
if (nout3)
fprintf(stdout, " TC%-4d %8d %5d %5d %8d ni%d %8d R%dB%02d %8d\n", ntr3, nsp3, nlon3, nlat3, ngp3, ni3, ngp_gme3, nrooti3,
fprintf(stdout, " TC%-4ld %8ld %5ld %5ld %8ld ni%ld %8ld R%ldB%02ld %8ld\n", ntr3, nsp3, nlon3, nlat3, ngp3, ni3, ngp_gme3, nrooti3,
nlevel3, ngp_icon3);
cdoFinish();
......
......@@ -39,7 +39,7 @@ struct CdoVar
int param;
int nwpv; // number of words per value; real:1 complex:2
CdoVar() : memType(MemType::Native), gridID(-1), zaxisID(-1), nlevels(0), datatype(-1), missval(0), timetype(-1), code(0), param(0), nwpv(1)
CdoVar() : memType(MemType::Native), gridID(-1), zaxisID(-1), gridsize(0), nlevels(0), datatype(-1), missval(0), timetype(-1), code(0), param(0), nwpv(1)
{
name[0] = 0;
};
......
......@@ -197,7 +197,7 @@ fieldNumMV(Field &field)
}
MinMax
fieldMinMax(Field &field)
fieldMinMax(const Field &field)
{
if (field.memType == MemType::Float)
return varrayMinMax(field.vec_f);
......@@ -331,7 +331,6 @@ vfldstd1w(const Field &field)
void
vfldrms(const Field &field, const Field &field2, Field &field3)
{
size_t i;
size_t rnmiss = 0;
auto grid1 = field.grid;
// size_t nmiss1 = field.nmiss;
......@@ -351,7 +350,7 @@ vfldrms(const Field &field, const Field &field2, Field &field3)
if ( nmiss1 )
*/
{
for (i = 0; i < len; i++)
for (size_t i = 0; i < len; i++)
if (!DBL_IS_EQUAL(w[i], missval1))
{
rsum = ADDMN(rsum, MULMN(w[i], MULMN(SUBMN(array2[i], array1[i]), SUBMN(array2[i], array1[i]))));
......
......@@ -93,7 +93,7 @@ void fieldCopy(const Field3D &field_src, int levelID, Field &field_tgt);
void fieldAdd(Field &field1, const Field3D &field2, int levelID);
size_t fieldNumMiss(const Field &field);
size_t fieldNumMV(Field &field);
MinMax fieldMinMax(Field &field);
MinMax fieldMinMax(const Field &field);
// fieldmem.cc
void fieldsFromVlist(int vlistID, FieldVector2D &field2D);
......
......@@ -38,8 +38,8 @@ static constexpr double cpair = 1004.6;
static constexpr double eta_pbl = 0.8; // upper limit of BPL eta coordiante
#if defined(OUTPUT)
static FILE *old, *new;
#ifdef OUTPUT
static FILE *fpold, *fpnew;
#endif
static long
......@@ -152,7 +152,7 @@ hetaeta_sc(bool ltq, int lpsmod, long ij, long ngp, long nlev1, long nlev2, long
fi1[k] = fi1[k + 1] + rair * tv1[k] * (lnph1[k + 1] - lnph1[k]);
}
}
#if defined(OUTPUT)
#ifdef OUTPUT
if (ij == OPOINT)
for (int k = nlev1 - 1; k >= 0; --k)
{
......@@ -169,9 +169,9 @@ hetaeta_sc(bool ltq, int lpsmod, long ij, long ngp, long nlev1, long nlev2, long
q = 0;
fi = 0;
}
fprintf(old, "%3d %18.10f %18.10f %18.10f %18.10f", k, fi / g, pf1[k], t, q);
for (int iv = 0; iv < nvars; ++iv) fprintf(old, " %18.10f", vars1[iv][ijk]);
fprintf(old, "\n");
fprintf(fpold, "%3d %18.10f %18.10f %18.10f %18.10f", k, fi / g, pf1[k], t, q);
for (int iv = 0; iv < nvars; ++iv) fprintf(fpold, " %18.10f", vars1[iv][ijk]);
fprintf(fpold, "\n");
}
#endif
......@@ -428,7 +428,7 @@ hetaeta_sc(bool ltq, int lpsmod, long ij, long ngp, long nlev1, long nlev2, long
for (int k = 0; k < nlev2; ++k) zq2[k] = rh2[k] * epsilon * esat(zt2[k]) / pf2[k];
}
#if defined(OUTPUT)
#ifdef OUTPUT
if (ij == OPOINT)
for (int k = nlev2 - 1; k >= 0; --k)
{
......@@ -445,9 +445,9 @@ hetaeta_sc(bool ltq, int lpsmod, long ij, long ngp, long nlev1, long nlev2, long
q = 0;
fi = 0;
}
fprintf(new, "%3d %18.10f %18.10f %18.10f %18.10f", k, fi / g, pf2[k], t, q);
for (int iv = 0; iv < nvars; ++iv) fprintf(new, " %18.10f", vars2[iv][ijk]);
fprintf(new, "\n");
fprintf(fpnew, "%3d %18.10f %18.10f %18.10f %18.10f", k, fi / g, pf2[k], t, q);
for (int iv = 0; iv < nvars; ++iv) fprintf(fpnew, " %18.10f", vars2[iv][ijk]);
fprintf(fpnew, "\n");
}
#endif
......@@ -480,11 +480,11 @@ hetaeta(bool ltq, int ngp, const int *imiss, int nlev1, const double *ah1, const
long jlev = 0;
int lpsmod = 1;
double *vars_pbl[MAX_VARS];
#if defined(OUTPUT)
#ifdef OUTPUT
double t, q, fi;
old = fopen("old.dat", "w");
new = fopen("new.dat", "w");
fpold = fopen("old.dat", "w");
fpnew = fopen("new.dat", "w");
#endif
long nlev1p1 = nlev1 + 1;
......@@ -639,15 +639,15 @@ hetaeta(bool ltq, int ngp, const int *imiss, int nlev1, const double *ah1, const
} /* end for ij */
#if defined(OUTPUT)
fclose(old);
fclose(new);
#ifdef OUTPUT
fclose(fpold);
fclose(fpnew);
#endif
return;
}
#if defined(TEST_HETAETA)
#ifdef TEST_HETAETA
#define NGP (512)
int Threading::ompNumThreads = 2;
......
......@@ -280,7 +280,7 @@ registerOperatorsFromModules()
* @note: if an error happens while adding the new module cdo will exit.
*/
void
add_module(const std::string &module_name, const module_t new_module)
add_module(const std::string &module_name, const module_t &new_module)
{
if (modules.find(module_name) == modules.end())
{
......
......@@ -45,8 +45,8 @@ struct module_t
short streamOutCnt; // Number of output streams
ModuleRestrictions restrictions = NoRestriction;
module_t(){};
module_t(void *(*p_func)(void *), std::vector<std::string> p_help, std::vector<std::string> p_opers, short p_m, short p_n,
short p_siC, short p_soC, ModuleRestrictions p_onlyFirst)
module_t(void *(*p_func)(void *), const std::vector<std::string> &p_help, const std::vector<std::string> &p_opers,
short p_m, short p_n, short p_siC, short p_soC, ModuleRestrictions p_onlyFirst)
: func(p_func), help(p_help), operators(p_opers), mode(p_m), number(p_n), streamInCnt(p_siC), streamOutCnt(p_soC),
restrictions(p_onlyFirst)
{
......@@ -89,7 +89,7 @@ int operatorStreamNumber(const char *operatorName);
void operatorPrintAll(void);
void operatorPrintList(bool print_no_output);
const char *get_original(const char *operatorName);
void add_module(const std::string &module_name, const module_t new_module);
void add_module(const std::string &module_name, const module_t &new_module);
int add_alias(const std::string &alias, const std::string &original);
#ifdef CUSTOM_MODULES
......
......@@ -58,6 +58,7 @@ main(int argc, char *argv[])
if (nitems != filesize)
{
fprintf(stderr, "Read failed on %s!\n", filename);
free(buffer);
return -1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment