From: ejjordan Date: Mon, 19 Apr 2021 18:29:05 +0000 (+0200) Subject: Apply clang-tidy11 to gmxana files with no dependencies X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=ae6a98a9fd9bad151aa791c133722f03d16cb7c4;p=alexxy%2Fgromacs.git Apply clang-tidy11 to gmxana files with no dependencies Splitt off from !1433. These are only the gmxana files that do not depend on other clang-tidy11 changes. The files gmx_analyze.cpp, gmx_nmr.cpp, gmx_bar.cpp, gmx_wheel.cpp and gmx_energy.cpp all have dependencies, mostly on enum modernization. They can be a subsequent MR. --- diff --git a/src/gromacs/gmxana/fitahx.cpp b/src/gromacs/gmxana/fitahx.cpp index 82660f232c..6ee406803b 100644 --- a/src/gromacs/gmxana/fitahx.cpp +++ b/src/gromacs/gmxana/fitahx.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team. - * Copyright (c) 2019,2020, by the GROMACS development team, led by + * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -40,9 +40,11 @@ #include "fitahx.h" #include +#include #include "gromacs/math/do_fit.h" #include "gromacs/math/vec.h" +#include "gromacs/math/vectypes.h" #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/smalloc.h" @@ -75,24 +77,24 @@ static void my_sub_xcm(int nbb, const int bbind[], rvec x[], rvec xcm) real fit_ahx(int nres, t_bb bb[], int natoms, int nall, int allindex[], rvec x[], int nca, int caindex[], gmx_bool bFit) { - static rvec* xref = nullptr; - static real* mass = nullptr; - const real d = 0.15; /* Rise per residue (nm) */ - const real tw = 1.745; /* Twist per residue (rad) */ - const real rad = 0.23; /* Radius of the helix (nm) */ - real phi0, trms, rms; - rvec dx, xcm; - int ai, i, nmass; + static std::vector xref; + static std::vector mass; + const real d = 0.15; /* Rise per residue (nm) */ + const real tw = 1.745; /* Twist per residue (rad) */ + const real rad = 0.23; /* Radius of the helix (nm) */ + real phi0, trms, rms; + rvec dx, xcm; + int ai, i, nmass; if (nca < 3) { gmx_fatal(FARGS, "Need at least 3 Calphas to fit to, (now %d)...\n", nca); } - if (xref == nullptr) + if (xref.empty()) { - snew(xref, natoms); - snew(mass, natoms); + xref.resize(natoms); + mass.resize(natoms); } phi0 = 0; for (i = 0; (i < nca); i++) @@ -120,8 +122,8 @@ real fit_ahx(int nres, t_bb bb[], int natoms, int nall, int allindex[], rvec x[] } /* Center the referece around the origin */ - my_calc_xcm(nca, caindex, xref, xcm); - my_sub_xcm(nca, caindex, xref, xcm); + my_calc_xcm(nca, caindex, as_rvec_array(xref.data()), xcm); + my_sub_xcm(nca, caindex, as_rvec_array(xref.data()), xcm); if (bFit) { @@ -149,7 +151,7 @@ real fit_ahx(int nres, t_bb bb[], int natoms, int nall, int allindex[], rvec x[] /* Now call the fitting routine */ if (bFit) { - do_fit(natoms, mass, xref, x); + do_fit(natoms, mass.data(), as_rvec_array(xref.data()), x); } /* Reset masses and calc rms */ diff --git a/src/gromacs/gmxana/gmx_anaeig.cpp b/src/gromacs/gmxana/gmx_anaeig.cpp index 76baee59ac..b64b1bae02 100644 --- a/src/gromacs/gmxana/gmx_anaeig.cpp +++ b/src/gromacs/gmxana/gmx_anaeig.cpp @@ -70,8 +70,6 @@ #include "thermochemistry.h" -static const char* proj_unit; - static real tick_spacing(real range, int minticks) { real sp; @@ -473,6 +471,7 @@ static void project(const char* trajfile, const char* twodplotfile, const char* threedplotfile, const char* filterfile, + const char* projUnit, int skip, const char* extremefile, gmx_bool bExtrAll, @@ -649,7 +648,7 @@ static void project(const char* trajfile, sprintf(str, "vec %d", eignr[outvec[v]] + 1); ylabel[v] = gmx_strdup(str); } - sprintf(str, "projection on eigenvectors (%s)", proj_unit); + sprintf(str, "projection on eigenvectors (%s)", projUnit); write_xvgr_graphs(projfile, noutvec, 1, @@ -669,8 +668,8 @@ static void project(const char* trajfile, if (twodplotfile) { - sprintf(str, "projection on eigenvector %d (%s)", eignr[outvec[0]] + 1, proj_unit); - sprintf(str2, "projection on eigenvector %d (%s)", eignr[outvec[noutvec - 1]] + 1, proj_unit); + sprintf(str, "projection on eigenvector %d (%s)", eignr[outvec[0]] + 1, projUnit); + sprintf(str2, "projection on eigenvector %d (%s)", eignr[outvec[noutvec - 1]] + 1, projUnit); xvgrout = xvgropen(twodplotfile, "2D projection of trajectory", str, str2, oenv); for (i = 0; i < nframes; i++) { @@ -1383,9 +1382,10 @@ int gmx_anaeig(int argc, char* argv[]) } snew(sqrtm, natoms); + std::string projUnit; if (bM && bDMA1) { - proj_unit = "u\\S1/2\\Nnm"; + projUnit = "u\\S1/2\\Nnm"; for (i = 0; (i < natoms); i++) { sqrtm[i] = std::sqrt(atoms->atom[index[i]].m); @@ -1393,7 +1393,7 @@ int gmx_anaeig(int argc, char* argv[]) } else { - proj_unit = "nm"; + projUnit = "nm"; for (i = 0; (i < natoms); i++) { sqrtm[i] = 1.0; @@ -1523,6 +1523,7 @@ int gmx_anaeig(int argc, char* argv[]) TwoDPlotFile, ThreeDPlotFile, FilterFile, + projUnit.c_str(), skip, ExtremeFile, bFirstLastSet, diff --git a/src/gromacs/gmxana/gmx_bundle.cpp b/src/gromacs/gmxana/gmx_bundle.cpp index c52eb19edb..c3daa88a03 100644 --- a/src/gromacs/gmxana/gmx_bundle.cpp +++ b/src/gromacs/gmxana/gmx_bundle.cpp @@ -39,6 +39,7 @@ #include #include +#include #include "gromacs/commandline/pargs.h" #include "gromacs/fileio/confio.h" @@ -157,14 +158,14 @@ static void calc_axes(rvec x[], t_atom atom[], const int gnx[], int* index[], gm static void dump_axes(t_trxstatus* status, t_trxframe* fr, t_atoms* outat, t_bundle* bun) { - t_trxframe frout; - static rvec* xout = nullptr; - int i; + t_trxframe frout; + static std::vector xout; + int i; GMX_ASSERT(outat->nr >= bun->n, ""); - if (xout == nullptr) + if (xout.empty()) { - snew(xout, outat->nr); + xout.resize(outat->nr); } for (i = 0; i < bun->n; i++) @@ -187,7 +188,7 @@ static void dump_axes(t_trxstatus* status, t_trxframe* fr, t_atoms* outat, t_bun frout.bAtoms = TRUE; frout.natoms = outat->nr; frout.atoms = outat; - frout.x = xout; + frout.x = as_rvec_array(xout.data()); write_trxframe(status, &frout, nullptr); } diff --git a/src/gromacs/gmxana/gmx_disre.cpp b/src/gromacs/gmxana/gmx_disre.cpp index 3490334d18..7333fbb6cc 100644 --- a/src/gromacs/gmxana/gmx_disre.cpp +++ b/src/gromacs/gmxana/gmx_disre.cpp @@ -83,8 +83,10 @@ typedef struct real v; } t_toppop; -static t_toppop* top = nullptr; -static int ntop = 0; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +static t_toppop* top = nullptr; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +static int ntop = 0; typedef struct { diff --git a/src/gromacs/gmxana/gmx_do_dssp.cpp b/src/gromacs/gmxana/gmx_do_dssp.cpp index 71c8c5ddc0..206e33b1cc 100644 --- a/src/gromacs/gmxana/gmx_do_dssp.cpp +++ b/src/gromacs/gmxana/gmx_do_dssp.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2012,2013,2014,2015,2017 by the GROMACS development team. - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -111,13 +111,13 @@ static int strip_dssp(FILE* tapeout, int average_area[], const gmx_output_env_t* oenv) { - static gmx_bool bFirst = TRUE; - static char* ssbuf; - char buf[STRLEN + 1]; - char SSTP; - int nr, iacc, nresidues; - int naccf, naccb; /* Count hydrophobic and hydrophilic residues */ - real iaccf, iaccb; + static gmx_bool bFirst = TRUE; + static std::string ssbuf; + char buf[STRLEN + 1]; + char SSTP; + int nr, iacc, nresidues; + int naccf, naccb; /* Count hydrophobic and hydrophilic residues */ + real iaccf, iaccb; /* Skip header */ @@ -133,7 +133,7 @@ static int strip_dssp(FILE* tapeout, * we allocate 2*nres-1, since for each chain there is a * separating line in the temp file. (At most each residue * could have been defined as a separate chain.) */ - snew(ssbuf, 2 * nres - 1); + ssbuf.resize(2 * nres - 1); } iaccb = iaccf = 0; diff --git a/src/gromacs/gmxana/gmx_enemat.cpp b/src/gromacs/gmxana/gmx_enemat.cpp index fcc13f7bb1..ae4341958d 100644 --- a/src/gromacs/gmxana/gmx_enemat.cpp +++ b/src/gromacs/gmxana/gmx_enemat.cpp @@ -94,6 +94,8 @@ enum egLJ14, egNR }; + +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static const char* egrp_nm[egNR + 1] = { "Coul-SR", "LJ-SR", "Buck-SR", "Coul-14", "LJ-14", nullptr }; diff --git a/src/gromacs/gmxana/gmx_gyrate.cpp b/src/gromacs/gmxana/gmx_gyrate.cpp index d28fb68d1e..540c790472 100644 --- a/src/gromacs/gmxana/gmx_gyrate.cpp +++ b/src/gromacs/gmxana/gmx_gyrate.cpp @@ -39,6 +39,7 @@ #include #include +#include #include "gromacs/commandline/pargs.h" #include "gromacs/commandline/viewit.h" @@ -121,15 +122,15 @@ static real calc_gyro(rvec x[], static void calc_gyro_z(rvec x[], matrix box, int gnx, const int index[], t_atom atom[], int nz, real time, FILE* out) { - static dvec* inertia = nullptr; - static double* tm = nullptr; - int i, ii, j, zi; - real zf, w, sdet, e1, e2; + static std::vector inertia; + static std::vector tm; + int i, ii, j, zi; + real zf, w, sdet, e1, e2; - if (inertia == nullptr) + if (inertia.empty()) { - snew(inertia, nz); - snew(tm, nz); + inertia.resize(nz); + tm.resize(nz); } for (i = 0; i < nz; i++) diff --git a/src/gromacs/gmxana/gmx_hbond.cpp b/src/gromacs/gmxana/gmx_hbond.cpp index 04ca7d6bef..7cb4a978d7 100644 --- a/src/gromacs/gmxana/gmx_hbond.cpp +++ b/src/gromacs/gmxana/gmx_hbond.cpp @@ -81,6 +81,7 @@ #define max_hx 7 typedef int t_hx[max_hx]; #define NRHXTYPES max_hx +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static const char* hxtypenames[NRHXTYPES] = { "n-n", "n-n+1", "n-n+2", "n-n+3", "n-n+4", "n-n+5", "n-n>6" }; #define MAXHH 4 @@ -108,9 +109,9 @@ static const unsigned char c_acceptorMask = (1 << 0); static const unsigned char c_donorMask = (1 << 1); static const unsigned char c_inGroupMask = (1 << 2); - +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static const char* grpnames[grNR] = { "0", "1", "I" }; - +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static gmx_bool bDebug = FALSE; #define HB_NO 0 @@ -266,7 +267,7 @@ static void add_frames(t_hbdata* hb, int nframes) #define OFFSET(frame) ((frame) / 32) #define MASK(frame) (1 << ((frame) % 32)) -static void _set_hb(unsigned int hbexist[], unsigned int frame, gmx_bool bValue) +static void set_hb_function(unsigned int hbexist[], unsigned int frame, gmx_bool bValue) { if (bValue) { @@ -300,7 +301,7 @@ static void set_hb(t_hbdata* hb, int id, int ih, int ia, int frame, int ihb) gmx_fatal(FARGS, "Incomprehensible iValue %d in set_hb", ihb); } - _set_hb(ghptr, frame - hb->hbmap[id][ia]->n0, TRUE); + set_hb_function(ghptr, frame - hb->hbmap[id][ia]->n0, TRUE); } static void add_ff(t_hbdata* hbd, int id, int h, int ia, int frame, int ihb) @@ -369,7 +370,7 @@ static void inc_nhbonds(t_donors* ddd, int d, int h) } } -static int _acceptor_index(t_acceptors* a, int grp, int i, const char* file, int line) +static int acceptor_index_function(t_acceptors* a, int grp, int i, const char* file, int line) { int ai = a->aptr[i]; @@ -386,9 +387,9 @@ static int _acceptor_index(t_acceptors* a, int grp, int i, const char* file, int return ai; } } -#define acceptor_index(a, grp, i) _acceptor_index(a, grp, i, __FILE__, __LINE__) +#define acceptor_index(a, grp, i) acceptor_index_function(a, grp, i, __FILE__, __LINE__) -static int _donor_index(t_donors* d, int grp, int i, const char* file, int line) +static int donor_index_function(t_donors* d, int grp, int i, const char* file, int line) { int di = d->dptr[i]; @@ -410,7 +411,7 @@ static int _donor_index(t_donors* d, int grp, int i, const char* file, int line) return di; } } -#define donor_index(d, grp, i) _donor_index(d, grp, i, __FILE__, __LINE__) +#define donor_index(d, grp, i) donor_index_function(d, grp, i, __FILE__, __LINE__) static gmx_bool isInterchangable(t_hbdata* hb, int d, int a, int grpa, int grpd) { @@ -1461,8 +1462,8 @@ static void do_merge(t_hbdata* hb, int ntmp, bool htmp[], bool gtmp[], t_hbond* /* Copy temp array to target array */ for (m = 0; (m <= nnframes); m++) { - _set_hb(hb0->h[0], m, htmp[m]); - _set_hb(hb0->g[0], m, gtmp[m]); + set_hb_function(hb0->h[0], m, htmp[m]); + set_hb_function(hb0->g[0], m, gtmp[m]); } /* Set scalar variables */ @@ -2916,17 +2917,17 @@ int gmx_hbond(int argc, char* argv[]) snew(rdist, nrbin + 1); #if !GMX_OPENMP -# define __ADIST adist -# define __RDIST rdist -# define __HBDATA hb -#else /* GMX_OPENMP ================================================== \ - * Set up the OpenMP stuff, | \ - * like the number of threads and such | \ - * Also start the parallel loop. | \ - */ -# define __ADIST p_adist[threadNr] -# define __RDIST p_rdist[threadNr] -# define __HBDATA p_hb[threadNr] +# define __ADIST adist // NOLINT(bugprone-reserved-identifier) +# define __RDIST rdist // NOLINT(bugprone-reserved-identifier) +# define __HBDATA hb // NOLINT(bugprone-reserved-identifier) +#else /* GMX_OPENMP ================================================== \ + * Set up the OpenMP stuff, | \ + * like the number of threads and such | \ + * Also start the parallel loop. | \ + */ +# define __ADIST p_adist[threadNr] // NOLINT(bugprone-reserved-identifier) +# define __RDIST p_rdist[threadNr] // NOLINT(bugprone-reserved-identifier) +# define __HBDATA p_hb[threadNr] // NOLINT(bugprone-reserved-identifier) #endif if (bOMP) { diff --git a/src/gromacs/gmxana/gmx_potential.cpp b/src/gromacs/gmxana/gmx_potential.cpp index 32083d0077..8138ec4162 100644 --- a/src/gromacs/gmxana/gmx_potential.cpp +++ b/src/gromacs/gmxana/gmx_potential.cpp @@ -73,11 +73,9 @@ /* This probably sucks but it seems to work. */ /****************************************************************************/ -static int ce = 0, cb = 0; - /* this routine integrates the array data and returns the resulting array */ /* routine uses simple trapezoid rule */ -static void p_integrate(double* result, const double data[], int ndata, double slWidth) +static void p_integrate(double* result, const double data[], int ndata, double slWidth, int cb, int ce) { int i, slice; double sum; @@ -117,6 +115,8 @@ static void calc_potential(const char* fn, double fudge_z, gmx_bool bSpherical, gmx_bool bCorrect, + int cb, + int ce, const gmx_output_env_t* oenv) { rvec* x0; /* coordinates without pbc */ @@ -317,7 +317,7 @@ static void calc_potential(const char* fn, for (n = 0; n < nr_grps; n++) { /* integrate twice to get field and potential */ - p_integrate((*slField)[n], (*slCharge)[n], *nslices, *slWidth); + p_integrate((*slField)[n], (*slCharge)[n], *nslices, *slWidth, cb, ce); } @@ -348,7 +348,7 @@ static void calc_potential(const char* fn, for (n = 0; n < nr_grps; n++) { - p_integrate((*slPotential)[n], (*slField)[n], *nslices, *slWidth); + p_integrate((*slPotential)[n], (*slField)[n], *nslices, *slWidth, cb, ce); } /* Now correct for eps0 and in spherical case for r*/ @@ -382,6 +382,8 @@ static void plot_potential(double* potential[], int nr_grps, const char* const grpname[], double slWidth, + int cb, + int ce, const gmx_output_env_t* oenv) { FILE *pot, /* xvgr file with potential */ @@ -443,6 +445,8 @@ int gmx_potential(int argc, char* argv[]) static gmx_bool bSpherical = FALSE; /* default is bilayer types */ static real fudge_z = 0; /* translate coordinates */ static gmx_bool bCorrect = false; + int cb = 0; + int ce = 0; t_pargs pa[] = { { "-d", FALSE, @@ -534,6 +538,8 @@ int gmx_potential(int argc, char* argv[]) fudge_z, bSpherical, bCorrect, + cb, + ce, oenv); plot_potential(potential, @@ -546,6 +552,8 @@ int gmx_potential(int argc, char* argv[]) ngrps, grpname, slWidth, + cb, + ce, oenv); do_view(oenv, opt2fn("-o", NFILE, fnm), nullptr); /* view xvgr file */ diff --git a/src/gromacs/gmxana/gmx_rmsdist.cpp b/src/gromacs/gmxana/gmx_rmsdist.cpp index 950565b796..709018ef49 100644 --- a/src/gromacs/gmxana/gmx_rmsdist.cpp +++ b/src/gromacs/gmxana/gmx_rmsdist.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team. - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -150,7 +150,7 @@ static void calc_nmr(int nind, int nframes, real** dtot1_3, real** dtot1_6, real } } -static char Hnum[] = "123"; +static const char Hnum[] = "123"; typedef struct { diff --git a/src/gromacs/gmxana/gmx_tcaf.cpp b/src/gromacs/gmxana/gmx_tcaf.cpp index 92f543e294..95b0cc1c00 100644 --- a/src/gromacs/gmxana/gmx_tcaf.cpp +++ b/src/gromacs/gmxana/gmx_tcaf.cpp @@ -70,16 +70,19 @@ #define NKC0 4 static const int kset_c[NKC + 1] = { 0, 3, 9, 13, 16, 19, NK }; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static rvec v0[NK] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 1, 0 }, { 1, -1, 0 }, { 1, 0, 1 }, { 1, 0, -1 }, { 0, 1, 1 }, { 0, 1, -1 }, { 1, 1, 1 }, { 1, 1, -1 }, { 1, -1, 1 }, { -1, 1, 1 }, { 2, 0, 0 }, { 0, 2, 0 }, { 0, 0, 2 }, { 3, 0, 0 }, { 0, 3, 0 }, { 0, 0, 3 }, { 4, 0, 0 }, { 0, 4, 0 }, { 0, 0, 4 } }; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static rvec v1[NK] = { { 0, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 0, 0, 1 }, { 0, 0, 1 }, { 0, 1, 0 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 0, 0 }, { 1, -1, 0 }, { 1, -1, 0 }, { 1, 0, -1 }, { 0, 1, -1 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 } }; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static rvec v2[NK] = { { 0, 0, 1 }, { 1, 0, 0 }, { 0, 1, 0 }, { 1, -1, 0 }, { 1, 1, 0 }, { 1, 0, -1 }, { 1, 0, 1 }, { 0, 1, -1 }, { 0, 1, 1 }, { 1, 1, -2 }, { 1, 1, 2 }, { 1, 2, 1 }, { 2, 1, 1 }, { 0, 0, 1 }, { 1, 0, 0 }, diff --git a/src/gromacs/gmxana/gmx_traj.cpp b/src/gromacs/gmxana/gmx_traj.cpp index 6526ccd7a2..4ba21505de 100644 --- a/src/gromacs/gmxana/gmx_traj.cpp +++ b/src/gromacs/gmxana/gmx_traj.cpp @@ -43,6 +43,7 @@ #include #include +#include #include "gromacs/commandline/pargs.h" #include "gromacs/commandline/viewit.h" @@ -160,16 +161,16 @@ static void print_data(FILE* fp, gmx_bool bDim[], const char* sffmt) { - static rvec* xav = nullptr; + static std::vector xav; if (bCom) { - if (xav == nullptr) + if (xav.empty()) { - snew(xav, ngrps); + xav.resize(ngrps); } - average_data(x, xav, mass, ngrps, isize, index); - low_print_data(fp, time, xav, ngrps, nullptr, bDim, sffmt); + average_data(x, as_rvec_array(xav.data()), mass, ngrps, isize, index); + low_print_data(fp, time, as_rvec_array(xav.data()), ngrps, nullptr, bDim, sffmt); } else { @@ -185,16 +186,17 @@ static void write_trx_x(t_trxstatus* status, int isize[], int** index) { - static rvec* xav = nullptr; + static std::vector xav; + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static t_atoms* atoms = nullptr; t_trxframe fr_av; int i; if (bCom) { - if (xav == nullptr) + if (xav.empty()) { - snew(xav, ngrps); + xav.resize(ngrps); snew(atoms, 1); *atoms = *fr->atoms; snew(atoms->atom, ngrps); @@ -208,11 +210,11 @@ static void write_trx_x(t_trxstatus* status, atoms->atomname[i] = fr->atoms->atomname[index[i][0]]; } } - average_data(fr->x, xav, mass, ngrps, isize, index); + average_data(fr->x, as_rvec_array(xav.data()), mass, ngrps, isize, index); fr_av = *fr; fr_av.natoms = ngrps; fr_av.atoms = atoms; - fr_av.x = xav; + fr_av.x = as_rvec_array(xav.data()); write_trxframe(status, &fr_av, nullptr); } else diff --git a/src/gromacs/gmxana/gmx_trjorder.cpp b/src/gromacs/gmxana/gmx_trjorder.cpp index 4c4a9470bf..386b4a745d 100644 --- a/src/gromacs/gmxana/gmx_trjorder.cpp +++ b/src/gromacs/gmxana/gmx_trjorder.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team. - * Copyright (c) 2019,2020, by the GROMACS development team, led by + * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -63,6 +63,7 @@ typedef struct real d2; } t_order; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static t_order* order; static int ocomp(const void* a, const void* b) diff --git a/src/gromacs/gmxana/gmx_xpm2ps.cpp b/src/gromacs/gmxana/gmx_xpm2ps.cpp index 6b79fa1e83..2062a46951 100644 --- a/src/gromacs/gmxana/gmx_xpm2ps.cpp +++ b/src/gromacs/gmxana/gmx_xpm2ps.cpp @@ -207,10 +207,13 @@ static void get_params(const char* mpin, const char* mpout, t_psrec* psr) done_warning(wi, FARGS); } +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static t_rgb black = { 0, 0, 0 }; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static t_rgb white = { 1, 1, 1 }; #define BLACK (&black) /* this must correspond to *colors[] in get_params */ +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static t_rgb* linecolors[] = { nullptr, &black, &white, nullptr }; static void leg_discrete(t_psdata* ps, diff --git a/src/gromacs/gmxana/nrama.cpp b/src/gromacs/gmxana/nrama.cpp index 3e8c5fdcf0..c5f6ccce60 100644 --- a/src/gromacs/gmxana/nrama.cpp +++ b/src/gromacs/gmxana/nrama.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team. - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -51,7 +51,7 @@ #include "gromacs/utility/futil.h" #include "gromacs/utility/smalloc.h" -static const char* pp_pat[] = { "C", "N", "CA", "C", "N" }; +static const char* const pp_pat[] = { "C", "N", "CA", "C", "N" }; #define NPP (sizeof(pp_pat) / sizeof(pp_pat[0])) static bool d_comp(const t_dih& a, const t_dih& b) diff --git a/src/gromacs/gmxana/sfactor.cpp b/src/gromacs/gmxana/sfactor.cpp index 8db06a4e2a..164c8cb556 100644 --- a/src/gromacs/gmxana/sfactor.cpp +++ b/src/gromacs/gmxana/sfactor.cpp @@ -612,7 +612,6 @@ extern void save_data(structure_factor_t* sft, xvgrclose(fp); } - extern double CMSF(gmx_structurefactors_t* gsf, int type, int nh, double lambda, double sin_theta) /* * return Cromer-Mann fit for the atomic scattering factor: diff --git a/src/gromacs/gmxana/tests/.clang-tidy b/src/gromacs/gmxana/tests/.clang-tidy new file mode 100644 index 0000000000..0adf51e3ee --- /dev/null +++ b/src/gromacs/gmxana/tests/.clang-tidy @@ -0,0 +1,91 @@ +# List of rationales for check suppressions (where known). +# This have to precede the list because inline comments are not +# supported by clang-tidy. +# +# -cppcoreguidelines-non-private-member-variables-in-classes, +# -misc-non-private-member-variables-in-classes, +# We intend a gradual transition to conform to this guideline, but it +# is not practical to implement yet. +# +# -readability-isolate-declaration, +# Declarations like "int a, b;" are readable. Some forms are not, and +# those might reasonably be suggested against during code review. +# +# -cppcoreguidelines-avoid-c-arrays, +# C arrays are still necessary in many places with legacy code +# +# -cppcoreguidelines-avoid-magic-numbers, +# -readability-magic-numbers, +# We have many legitimate use cases for magic numbers +# +# -cppcoreguidelines-macro-usage, +# We do use too many macros, and we should fix many of them, but there +# is no reasonable way to suppress the check e.g. in src/config.h and +# configuring the build is a major legitimate use of macros. +# +# -cppcoreguidelines-narrowing-conversions, +# -bugprone-narrowing-conversions +# We have many cases where int is converted to float and we don't care +# enough about such potential loss of precision to use explicit casts +# in large numbers of places. +# +# -google-readability-avoid-underscore-in-googletest-name +# We need to use underscores for readability for our legacy types +# and command-line parameter names +# +# -misc-no-recursion +# We have way too many functions and methods relying on recursion +# +# -cppcoreguidelines-avoid-non-const-global-variables +# There are quite a lot of static variables in the test code that +# can not be replaced. +# +# -modernize-avoid-bind +# Some code needs to use std::bind and can't be modernized quickly. +Checks: clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy, + bugprone-*,misc-*,readability-*,performance-*,mpi-*, + -readability-inconsistent-declaration-parameter-name, + -readability-function-size,-readability-else-after-return, + modernize-use-nullptr,modernize-use-emplace, + modernize-make-unique,modernize-make-shared, + modernize-avoid-bind, + modernize-use-override, + modernize-redundant-void-arg,modernize-use-bool-literals, + cppcoreguidelines-*,-cppcoreguidelines-pro-*,-cppcoreguidelines-owning-memory, + -cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions, + -cppcoreguidelines-avoid-goto, + google-*,-google-build-using-namespace,-google-explicit-constructor, + -google-readability-function-size,-google-readability-todo,-google-runtime-int, + -cppcoreguidelines-non-private-member-variables-in-classes, + -misc-non-private-member-variables-in-classes, + -readability-isolate-declaration, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-magic-numbers, + -readability-magic-numbers, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-narrowing-conversions, + -bugprone-narrowing-conversions, + -google-readability-avoid-underscore-in-googletest-name, + -cppcoreguidelines-init-variables, + -misc-no-recursion, + -cppcoreguidelines-avoid-non-const-global-variables, + -modernize-avoid-bind +HeaderFilterRegex: .* +CheckOptions: + - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor + value: 1 + - key: modernize-make-unique.IncludeStyle + value: google + - key: modernize-make-shared.IncludeStyle + value: google + - key: readability-implicit-bool-conversion.AllowIntegerConditions + value: 1 + - key: readability-implicit-bool-conversion.AllowPointerConditions + value: 1 + - key: bugprone-dangling-handle.HandleClasses + value: std::basic_string_view; nonstd::sv_lite::basic_string_view +# Permit passing shard pointers by value for sink parameters + - key: performance-unnecessary-copy-initialization.AllowedTypes + value: shared_ptr + - key: performance-unnecessary-value-param.AllowedTypes + value: shared_ptr diff --git a/src/gromacs/gmxana/thermochemistry.cpp b/src/gromacs/gmxana/thermochemistry.cpp index 2b5d68988f..ca80d660f3 100644 --- a/src/gromacs/gmxana/thermochemistry.cpp +++ b/src/gromacs/gmxana/thermochemistry.cpp @@ -55,7 +55,7 @@ double calcZeroPointEnergy(gmx::ArrayRef eigval, real scale_factor) // Convert frequency (ps^-1) to energy (kJ/mol) double factor = gmx::c_planck * gmx::c_pico / (2.0 * M_PI); double zpe = 0; - for (auto& r : eigval) + for (const auto& r : eigval) { double omega = eigval_to_frequency(r); zpe += 0.5 * factor * scale_factor * omega;