Merge branch 'master' into pygromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_sorient.cpp
similarity index 95%
rename from src/gromacs/gmxana/gmx_sorient.c
rename to src/gromacs/gmxana/gmx_sorient.cpp
index ac01e53622643043d4b52931743c9c9ad6994fc9..8acf9a03f92205f5f46241c3cd8ba3b648d93797 100644 (file)
@@ -36,6 +36,8 @@
  */
 #include "gmxpre.h"
 
+#include <cmath>
+
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
@@ -90,7 +92,7 @@ static void calc_com_pbc(int nrefat, t_topology *top, rvec x[], t_pbc *pbc,
                 rvec_add(xref, dx, xtest);
                 for (j = 0; (j < DIM); j++)
                 {
-                    if (fabs(xtest[j]-x[ai][j]) > tol)
+                    if (std::abs(xtest[j]-x[ai][j]) > tol)
                     {
                         /* Here we have used the wrong image for contributing to the COM */
                         xref[j] += mass*(xtest[j]-x[ai][j]);
@@ -121,13 +123,13 @@ int gmx_sorient(int argc, char *argv[])
     matrix          box;
 
     FILE           *fp;
-    int             i, j, p, sa0, sa1, sa2, n, ntot, nf, m, *hist1, *hist2, *histn, nbin1, nbin2, nrbin;
+    int             i, p, sa0, sa1, sa2, n, ntot, nf, m, *hist1, *hist2, *histn, nbin1, nbin2, nrbin;
     real           *histi1, *histi2, invbw, invrbw;
     double          sum1, sum2;
     int            *isize, nrefgrp, nrefat;
     atom_id       **index;
     char          **grpname;
-    real            inp, outp, two_pi, nav, normfac, rmin2, rmax2, rcut, rcut2, r2, r, mass, mtot;
+    real            inp, outp, nav, normfac, rmin2, rmax2, rcut, rcut2, r2, r;
     real            c1, c2;
     char            str[STRLEN];
     gmx_bool        bTPS;
@@ -201,8 +203,6 @@ int gmx_sorient(int argc, char *argv[])
         return 0;
     }
 
-    two_pi = 2/M_PI;
-
     bTPS = (opt2bSet("-s", NFILE, fnm) || !opt2bSet("-n", NFILE, fnm) || bCom);
     if (bTPS)
     {
@@ -246,7 +246,7 @@ int gmx_sorient(int argc, char *argv[])
 
     rmin2 = sqr(rmin);
     rmax2 = sqr(rmax);
-    rcut  = 0.99*sqrt(max_cutoff2(guess_ePBC(box), box));
+    rcut  = 0.99*std::sqrt(max_cutoff2(guess_ePBC(box), box));
     if (rcut == 0)
     {
         rcut = 10*rmax;
@@ -254,14 +254,14 @@ int gmx_sorient(int argc, char *argv[])
     rcut2 = sqr(rcut);
 
     invbw = 1/binwidth;
-    nbin1 = 1+(int)(2*invbw + 0.5);
-    nbin2 = 1+(int)(invbw + 0.5);
+    nbin1 = 1+static_cast<int>(2*invbw + 0.5);
+    nbin2 = 1+static_cast<int>(invbw + 0.5);
 
     invrbw = 1/rbinw;
 
     snew(hist1, nbin1);
     snew(hist2, nbin2);
-    nrbin = 1+(int)(rcut/rbinw);
+    nrbin = 1+static_cast<int>(rcut/rbinw);
     if (nrbin == 0)
     {
         nrbin = 1;
@@ -292,7 +292,6 @@ int gmx_sorient(int argc, char *argv[])
         set_pbc(&pbc, ePBC, box);
         n    = 0;
         inp  = 0;
-        outp = 0;
         for (p = 0; (p < nrefgrp); p++)
         {
             if (bCom)
@@ -316,7 +315,7 @@ int gmx_sorient(int argc, char *argv[])
                 r2  = norm2(dx);
                 if (r2 < rcut2)
                 {
-                    r = sqrt(r2);
+                    r = std::sqrt(r2);
                     if (!bVec23)
                     {
                         /* Determine the normal to the plain */
@@ -338,7 +337,7 @@ int gmx_sorient(int argc, char *argv[])
                         outp = iprod(dx, dxh2)/r;
                     }
                     {
-                        int ii = (int)(invrbw*r);
+                        int ii = static_cast<int>(invrbw*r);
                         range_check(ii, 0, nrbin);
                         histi1[ii] += inp;
                         histi2[ii] += 3*sqr(outp) - 1;
@@ -346,8 +345,8 @@ int gmx_sorient(int argc, char *argv[])
                     }
                     if ((r2 >= rmin2) && (r2 < rmax2))
                     {
-                        int ii1 = (int)(invbw*(inp + 1));
-                        int ii2 = (int)(invbw*fabs(outp));
+                        int ii1 = static_cast<int>(invbw*(inp + 1));
+                        int ii2 = static_cast<int>(invbw*std::abs(outp));
 
                         range_check(ii1, 0, nbin1);
                         range_check(ii2, 0, nbin2);
@@ -375,7 +374,7 @@ int gmx_sorient(int argc, char *argv[])
     hist1[nbin1-1] += hist1[nbin1];
     hist2[nbin2-1] += hist2[nbin2];
 
-    nav     = (real)ntot/(nrefgrp*nf);
+    nav     = static_cast<real>(ntot)/(nrefgrp*nf);
     normfac = invbw/ntot;
 
     fprintf(stderr,  "Average nr of molecules between %g and %g nm: %.1f\n",