Apply clang-tidy11 to gmxana files with no dependencies
authorejjordan <ejjordan@kth.se>
Mon, 19 Apr 2021 18:29:05 +0000 (20:29 +0200)
committerPascal Merz <pascal.merz@me.com>
Tue, 20 Apr 2021 00:09:37 +0000 (00:09 +0000)
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.

18 files changed:
src/gromacs/gmxana/fitahx.cpp
src/gromacs/gmxana/gmx_anaeig.cpp
src/gromacs/gmxana/gmx_bundle.cpp
src/gromacs/gmxana/gmx_disre.cpp
src/gromacs/gmxana/gmx_do_dssp.cpp
src/gromacs/gmxana/gmx_enemat.cpp
src/gromacs/gmxana/gmx_gyrate.cpp
src/gromacs/gmxana/gmx_hbond.cpp
src/gromacs/gmxana/gmx_potential.cpp
src/gromacs/gmxana/gmx_rmsdist.cpp
src/gromacs/gmxana/gmx_tcaf.cpp
src/gromacs/gmxana/gmx_traj.cpp
src/gromacs/gmxana/gmx_trjorder.cpp
src/gromacs/gmxana/gmx_xpm2ps.cpp
src/gromacs/gmxana/nrama.cpp
src/gromacs/gmxana/sfactor.cpp
src/gromacs/gmxana/tests/.clang-tidy [new file with mode: 0644]
src/gromacs/gmxana/thermochemistry.cpp

index 82660f232c110d1080a9d300be623b432ea56337..6ee406803b927a3c803b1eafd0a518d04d32db7d 100644 (file)
@@ -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.
 #include "fitahx.h"
 
 #include <cmath>
+#include <vector>
 
 #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      = 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<gmx::RVec> xref;
+    static std::vector<real>      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 */
index 76baee59acfd4a85867abac9fbac432b272fe10e..b64b1bae02e0e29ca0a40bda91ccb110bb6a332c 100644 (file)
@@ -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,
index c52eb19edbc4e2550e758717a9e7e5a5f01f44b2..c3daa88a03647dc1dc0ccc66f83a1bfc192fe1bb 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <cmath>
 #include <cstring>
+#include <vector>
 
 #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<gmx::RVec> 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);
 }
 
index 3490334d18206266fac92800c9be2367da3554e1..7333fbb6cc4b63d042b63f865cbef17f1d795259 100644 (file)
@@ -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
 {
index 71c8c5ddc006c179309c6c0558864532fd3a7bd1..206e33b1cc251d584e7740e71a11d9a9d5cf91fd 100644 (file)
@@ -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;
index fcc13f7bb10c6a760cb827ac01ae762c6e816e94..ae4341958dd14fe4a33ca86067884734faa0aa98 100644 (file)
@@ -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 };
 
 
index d28fb68d1e7fe1c17718a3f45ffe79fadc119373..540c7904723b4e990a5677738e4f0724f4b2aa62 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <cmath>
 #include <cstring>
+#include <vector>
 
 #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<gmx::DVec> inertia;
+    static std::vector<double>    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++)
index 04ca7d6bef6d9e4c26b10389f788430cd37f5f9a..7cb4a978d7d13c7928c38021dad3dd7c0ec8310c 100644 (file)
@@ -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)
     {
index 32083d0077b049a2a4dc946fa02ce05848fbaf2f..8138ec4162f509fafdb8353dfd8937e3836354d6 100644 (file)
 /* 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 */
index 950565b7969aa2e16e21fb5087450335be13d30d..709018ef49d9b58681c505798b89212201c5b6be 100644 (file)
@@ -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
 {
index 92f543e2949bac187ceb8c8e997d614f25175c1f..95b0cc1c0003c40e60d2972936729d5c467ece7c 100644 (file)
 #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 },
index 6526ccd7a26341508687e57a8bda682e5f47ef09..4ba21505de49542cf59c48fc5a5725664e481c99 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <algorithm>
 #include <string>
+#include <vector>
 
 #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<gmx::RVec> 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<gmx::RVec> 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
index 4c4a9470bffdfb51616d5cb33c2290ea3fb23d96..386b4a745d0d0607fc650fb01d0c877abe3fde68 100644 (file)
@@ -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)
index 6b79fa1e83e26ccd4c485e732bc7356dc8d16e11..2062a4695116bc6d5b270fd944b70afca336281f 100644 (file)
@@ -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,
index 3e8c5fdcf032945d03207ca0388a2d15c084151d..c5f6ccce607874c9ed6f4760eb5d74de2a9a9a90 100644 (file)
@@ -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)
index 8db06a4e2a9ca634ffc1cf56f44d6885bdc1dff7..164c8cb556f8309edc02c75d08bf2db39c4bf3da 100644 (file)
@@ -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 (file)
index 0000000..0adf51e
--- /dev/null
@@ -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
index 2b5d68988f386b3e03b7d65c91fd00df19d8b3ce..ca80d660f3390780338fd5b1ba10acc5900903d6 100644 (file)
@@ -55,7 +55,7 @@ double calcZeroPointEnergy(gmx::ArrayRef<const real> 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;