Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / correlationfunctions / expfit.cpp
index a1bfe445be6f1c9d1cc7ec0e82ffc9aa65197323..d57ba055c9670e9b76e1b42596b9678e77874ab6 100644 (file)
@@ -3,7 +3,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,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013-2019, 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.
@@ -69,26 +69,25 @@ static const int nfp_ffn[effnNR] = { 0, 1, 2, 3, 5, 7, 9, 2, 4, 3, 6 };
  * hence there are many more NULL field (which have to be at the end of
  * the array).
  */
-const char      *s_ffn[effnNR+2] = {
-    nullptr, "none", "exp", "aexp", "exp_exp",
-    "exp5", "exp7", "exp9",
-    nullptr, nullptr, nullptr, nullptr, nullptr
-};
+const char* s_ffn[effnNR + 2] = { nullptr, "none",  "exp",   "aexp",  "exp_exp", "exp5", "exp7",
+                                  "exp9",  nullptr, nullptr, nullptr, nullptr,   nullptr };
 
+// clang-format off
+// needed because clang-format wants to break the lines below
 /*! \brief Long description for each fitting function type */
-static const char *longs_ffn[effnNR] = {
-    "no fit",
-    "y = exp(-x/|a0|)",
-    "y = a1 exp(-x/|a0|)",
-    "y = a1 exp(-x/|a0|) + (1-a1) exp(-x/(|a2|)), a2 > a0 > 0",
-    "y = a0 exp(-x/|a1|) +  a2 exp(-x/|a3|) + a4, a3 >= a1",
-    "y = a0 exp(-x/|a1|) +  a2 exp(-x/|a3|) + a4 exp(-x/|a5|) + a6, a5 >= a3 >= a1",
-    "y = a0 exp(-x/|a1|) +  a2 exp(-x/|a3|) + a4 exp(-x/|a5|) + a6 exp(-x/|a7|) + a8, a7 >= a5 >= a3 >= a1",
-    "y = exp(-v) (cosh(wv) + 1/w sinh(wv)), v = x/(2 a0), w = sqrt(1 - a1)",
-    "y = 1/2*(a0+a1) - 1/2*(a0-a1)*erf( (x-a2) /a3^2)",
-    "y = a1 *2*a0*((exp(-x/a0)-1)*(a0/x)+1)+(1-a1)*2*a2*((exp(-x/a2)-1)*(a2/x)+1)",
-    "y = (1-a0)*cos(x*a1)*exp(-(x/a2)^a3) + a0*exp(-(x/a4)^a5)"
-};
+static const char* longs_ffn[effnNR]
+        = { "no fit",
+            "y = exp(-x/|a0|)",
+            "y = a1 exp(-x/|a0|)",
+            "y = a1 exp(-x/|a0|) + (1-a1) exp(-x/(|a2|)), a2 > a0 > 0",
+            "y = a0 exp(-x/|a1|) +  a2 exp(-x/|a3|) + a4, a3 >= a1",
+            "y = a0 exp(-x/|a1|) +  a2 exp(-x/|a3|) + a4 exp(-x/|a5|) + a6, a5 >= a3 >= a1",
+            "y = a0 exp(-x/|a1|) +  a2 exp(-x/|a3|) + a4 exp(-x/|a5|) + a6 exp(-x/|a7|) + a8, a7 >= a5 >= a3 >= a1",
+            "y = exp(-v) (cosh(wv) + 1/w sinh(wv)), v = x/(2 a0), w = sqrt(1 - a1)",
+            "y = 1/2*(a0+a1) - 1/2*(a0-a1)*erf( (x-a2) /a3^2)",
+            "y = a1 *2*a0*((exp(-x/a0)-1)*(a0/x)+1)+(1-a1)*2*a2*((exp(-x/a2)-1)*(a2/x)+1)",
+            "y = (1-a0)*cos(x*a1)*exp(-(x/a2)^a3) + a0*exp(-(x/a4)^a5)" };
+// clang-format on
 
 int effnNparams(int effn)
 {
@@ -102,7 +101,7 @@ int effnNparams(int effn)
     }
 }
 
-const char *effnDescription(int effn)
+const chareffnDescription(int effn)
 {
     if ((0 <= effn) && (effn < effnNR))
     {
@@ -114,14 +113,14 @@ const char *effnDescription(int effn)
     }
 }
 
-int sffn2effn(const char **sffn)
+int sffn2effn(const char** sffn)
 {
     int eFitFn, i;
 
     eFitFn = 0;
     for (i = 0; i < effnNR; i++)
     {
-        if (sffn[i+1] && strcmp(sffn[0], sffn[i+1]) == 0)
+        if (sffn[i + 1] && strcmp(sffn[0], sffn[i + 1]) == 0)
         {
             eFitFn = i;
         }
@@ -137,18 +136,18 @@ static double myexp(double x, double A, double tau)
     {
         return 0;
     }
-    return A*exp(-x/tau);
+    return A * exp(-x / tau);
 }
 
 /*! \brief Compute y=(a0+a1)/2-(a0-a1)/2*erf((x-a2)/a3^2) */
-static double lmc_erffit (double x, const double *a)
+static double lmc_erffit(double x, const double* a)
 {
     double erfarg;
     double myerf;
 
     if (a[3] != 0)
     {
-        erfarg = (x-a[2])/(a[3]*a[3]);
+        erfarg = (x - a[2]) / (a[3] * a[3]);
         myerf  = std::erf(erfarg);
     }
     else
@@ -163,7 +162,7 @@ static double lmc_erffit (double x, const double *a)
             myerf = 1;
         }
     }
-    return 0.5*((a[0]+a[1]) - (a[0]-a[1])*myerf);
+    return 0.5 * ((a[0] + a[1]) - (a[0] - a[1]) * myerf);
 }
 
 /*! \brief Exponent function that prevents overflow */
@@ -205,35 +204,35 @@ static double safe_expm1(double x)
 }
 
 /*! \brief Compute y = exp(-x/|a0|) */
-static double lmc_exp_one_parm(double x, const double *a)
+static double lmc_exp_one_parm(double x, const doublea)
 {
-    return safe_exp(-x/fabs(a[0]));
+    return safe_exp(-x / fabs(a[0]));
 }
 
 /*! \brief Compute y = a1 exp(-x/|a0|) */
-static double lmc_exp_two_parm(double x, const double *a)
+static double lmc_exp_two_parm(double x, const doublea)
 {
-    return a[1]*safe_exp(-x/fabs(a[0]));
+    return a[1] * safe_exp(-x / fabs(a[0]));
 }
 
 /*! \brief Compute y = a1 exp(-x/|a0|) + (1-a1) exp(-x/|a2|) */
-static double lmc_exp_exp(double x, const double *a)
+static double lmc_exp_exp(double x, const doublea)
 {
     double e1, e2;
 
-    e1      = safe_exp(-x/fabs(a[0]));
-    e2      = safe_exp(-x/(fabs(a[0])+fabs(a[2])));
-    return a[1]*e1 + (1-a[1])*e2;
+    e1 = safe_exp(-x / fabs(a[0]));
+    e2 = safe_exp(-x / (fabs(a[0]) + fabs(a[2])));
+    return a[1] * e1 + (1 - a[1]) * e2;
 }
 
 /*! \brief Compute y = a0 exp(-x/|a1|) + a2 exp(-x/(|a1|+|a3|)) + a4 */
-static double lmc_exp_5_parm(double x, const double *a)
+static double lmc_exp_5_parm(double x, const doublea)
 {
     double e1, e2;
 
-    e1      = safe_exp(-x/fabs(a[1]));
-    e2      = safe_exp(-x/(fabs(a[1])+fabs(a[3])));
-    return a[0]*e1 + a[2]*e2 + a[4];
+    e1 = safe_exp(-x / fabs(a[1]));
+    e2 = safe_exp(-x / (fabs(a[1]) + fabs(a[3])));
+    return a[0] * e1 + a[2] * e2 + a[4];
 }
 
 /*! \brief Compute 7 parameter exponential function value.
@@ -241,7 +240,7 @@ static double lmc_exp_5_parm(double x, const double *a)
  * Compute y = a0 exp(-x/|a1|) + a2 exp(-x/(|a1|+|a3|)) +
  * a4 exp(-x/(|a1|+|a3|+|a5|)) + a6
  */
-static double lmc_exp_7_parm(double x, const double *a)
+static double lmc_exp_7_parm(double x, const doublea)
 {
     double e1, e2, e3;
     double fa1, fa3, fa5;
@@ -249,10 +248,10 @@ static double lmc_exp_7_parm(double x, const double *a)
     fa1 = fabs(a[1]);
     fa3 = fa1 + fabs(a[3]);
     fa5 = fa3 + fabs(a[5]);
-    e1  = safe_exp(-x/fa1);
-    e2  = safe_exp(-x/fa3);
-    e3  = safe_exp(-x/fa5);
-    return a[0]*e1 + a[2]*e2 + a[4]*e3 + a[6];
+    e1  = safe_exp(-x / fa1);
+    e2  = safe_exp(-x / fa3);
+    e3  = safe_exp(-x / fa5);
+    return a[0] * e1 + a[2] * e2 + a[4] * e3 + a[6];
 }
 
 /*! \brief Compute 9 parameter exponential function value.
@@ -260,7 +259,7 @@ static double lmc_exp_7_parm(double x, const double *a)
  * Compute y = a0 exp(-x/|a1|) + a2 exp(-x/(|a1|+|a3|)) +
  * a4 exp(-x/(|a1|+|a3|+|a5|)) + a6 exp(-x/(|a1|+|a3|+|a5|+|a7|)) + a8
  */
-static double lmc_exp_9_parm(double x, const double *a)
+static double lmc_exp_9_parm(double x, const doublea)
 {
     double e1, e2, e3, e4;
     double fa1, fa3, fa5, fa7;
@@ -270,39 +269,39 @@ static double lmc_exp_9_parm(double x, const double *a)
     fa5 = fa3 + fabs(a[5]);
     fa7 = fa5 + fabs(a[7]);
 
-    e1      = safe_exp(-x/fa1);
-    e2      = safe_exp(-x/fa3);
-    e3      = safe_exp(-x/fa5);
-    e4      = safe_exp(-x/fa7);
-    return a[0]*e1 + a[2]*e2 + a[4]*e3 + a[6]*e4 + a[8];
+    e1 = safe_exp(-x / fa1);
+    e2 = safe_exp(-x / fa3);
+    e3 = safe_exp(-x / fa5);
+    e4 = safe_exp(-x / fa7);
+    return a[0] * e1 + a[2] * e2 + a[4] * e3 + a[6] * e4 + a[8];
 }
 
 /*! \brief Compute y = (1-a0)*exp(-(x/|a2|)^|a3|)*cos(x*|a1|) + a0*exp(-(x/|a4|)^|a5|) */
-static double lmc_pres_6_parm(double x, const double *a)
+static double lmc_pres_6_parm(double x, const doublea)
 {
     double term1, term2, term3;
     double pow_max = 10;
 
-    term3  = 0;
+    term3 = 0;
     if ((a[4] != 0) && (a[0] != 0))
     {
         double power = std::min(fabs(a[5]), pow_max);
-        term3        = a[0] * safe_exp(-pow((x/fabs(a[4])), power));
+        term3        = a[0] * safe_exp(-pow((x / fabs(a[4])), power));
     }
 
-    term1  = 1-a[0];
-    term2  = 0;
+    term1 = 1 - a[0];
+    term2 = 0;
     if ((term1 != 0) && (a[2] != 0))
     {
         double power = std::min(fabs(a[3]), pow_max);
-        term2        = safe_exp(-pow((x/fabs(a[2])), power)) * cos(x*fabs(a[1]));
+        term2        = safe_exp(-pow((x / fabs(a[2])), power)) * cos(x * fabs(a[1]));
     }
 
-    return term1*term2 + term3;
+    return term1 * term2 + term3;
 }
 
 /*! \brief Compute vac function */
-static double lmc_vac_2_parm(double x, const double *a)
+static double lmc_vac_2_parm(double x, const doublea)
 {
     /* Fit to function
      *
@@ -322,44 +321,44 @@ static double lmc_vac_2_parm(double x, const double *a)
     double y, v, det, omega, wv, em, ec, es;
     double wv_max = 100;
 
-    v   = x/(2*fabs(a[0]));
+    v   = x / (2 * fabs(a[0]));
     det = 1 - a[1];
     em  = safe_exp(-v);
     if (det != 0)
     {
         omega = sqrt(fabs(det));
-        wv    = std::min(omega*v, wv_max);
+        wv    = std::min(omega * v, wv_max);
 
         if (det > 0)
         {
-            ec = em*0.5*(safe_exp(wv)+safe_exp(-wv));
-            es = em*0.5*(safe_exp(wv)-safe_exp(-wv))/omega;
+            ec = em * 0.5 * (safe_exp(wv) + safe_exp(-wv));
+            es = em * 0.5 * (safe_exp(wv) - safe_exp(-wv)) / omega;
         }
         else
         {
-            ec = em*cos(wv);
-            es = em*sin(wv)/omega;
+            ec = em * cos(wv);
+            es = em * sin(wv) / omega;
         }
-        y      = ec + es;
+        y = ec + es;
     }
     else
     {
-        y      = (1+v)*em;
+        y = (1 + v) * em;
     }
     return y;
 }
 
 /*! \brief Compute error estimate */
-static double lmc_errest_3_parm(double x, const double *a)
+static double lmc_errest_3_parm(double x, const doublea)
 {
     double e1, e2, v1, v2;
     double fa0 = fabs(a[0]);
     double fa1;
-    double fa2 = fa0+fabs(a[2]);
+    double fa2 = fa0 + fabs(a[2]);
 
     if (a[0] != 0)
     {
-        e1 = safe_expm1(-x/fa0);
+        e1 = safe_expm1(-x / fa0);
     }
     else
     {
@@ -367,7 +366,7 @@ static double lmc_errest_3_parm(double x, const double *a)
     }
     if (a[2] != 0)
     {
-        e2 = safe_expm1(-x/fa2);
+        e2 = safe_expm1(-x / fa2);
     }
     else
     {
@@ -376,12 +375,12 @@ static double lmc_errest_3_parm(double x, const double *a)
 
     if (x > 0)
     {
-        v1      = 2*fa0*(e1*fa0/x + 1);
-        v2      = 2*fa2*(e2*fa2/x + 1);
+        v1 = 2 * fa0 * (e1 * fa0 / x + 1);
+        v2 = 2 * fa2 * (e2 * fa2 / x + 1);
         /* We need 0 <= a1 <= 1 */
-        fa1     = std::min(1.0, std::max(0.0, a[1]));
+        fa1 = std::min(1.0, std::max(0.0, a[1]));
 
-        return fa1*v1 + (1-fa1)*v2;
+        return fa1 * v1 + (1 - fa1) * v2;
     }
     else
     {
@@ -390,19 +389,16 @@ static double lmc_errest_3_parm(double x, const double *a)
 }
 
 /*! \brief array of fitting functions corresponding to the pre-defined types */
-t_lmcurve lmcurves[effnNR+1] = {
-    lmc_exp_one_parm, lmc_exp_one_parm, lmc_exp_two_parm,
-    lmc_exp_exp,      lmc_exp_5_parm,   lmc_exp_7_parm,
-    lmc_exp_9_parm,
-    lmc_vac_2_parm,   lmc_erffit,  lmc_errest_3_parm, lmc_pres_6_parm
-};
+t_lmcurve lmcurves[effnNR + 1] = { lmc_exp_one_parm,  lmc_exp_one_parm, lmc_exp_two_parm,
+                                   lmc_exp_exp,       lmc_exp_5_parm,   lmc_exp_7_parm,
+                                   lmc_exp_9_parm,    lmc_vac_2_parm,   lmc_erffit,
+                                   lmc_errest_3_parm, lmc_pres_6_parm };
 
 double fit_function(const int eFitFn, const double parm[], const double x)
 {
     if ((eFitFn < 0) || (eFitFn >= effnNR))
     {
-        fprintf(stderr, "fitfn = %d, should be in the range 0..%d\n",
-                eFitFn, effnNR-1);
+        fprintf(stderr, "fitfn = %d, should be in the range 0..%d\n", eFitFn, effnNR - 1);
         return 0.0;
     }
     return lmcurves[eFitFn](x, parm);
@@ -420,8 +416,7 @@ double fit_function(const int eFitFn, const double parm[], const double x)
  * previous ones and during fitting we enforce the they remain larger.
  * It may very well help the convergence of the fitting routine.
  */
-static void initiate_fit_params(int    eFitFn,
-                                double params[])
+static void initiate_fit_params(int eFitFn, double params[])
 {
     int i, nparm;
 
@@ -429,9 +424,7 @@ static void initiate_fit_params(int    eFitFn,
 
     switch (eFitFn)
     {
-        case effnVAC:
-            GMX_ASSERT(params[0] >= 0, "parameters should be >= 0");
-            break;
+        case effnVAC: GMX_ASSERT(params[0] >= 0, "parameters should be >= 0"); break;
         case effnEXP1:
         case effnEXP2:
         case effnEXPEXP:
@@ -444,7 +437,7 @@ static void initiate_fit_params(int    eFitFn,
                  * params[2]-params[0] and in the add add in params[0]
                  * again.
                  */
-                params[2] = std::max(fabs(params[2])-params[0], params[0]);
+                params[2] = std::max(fabs(params[2]) - params[0], params[0]);
             }
             break;
         case effnEXP5:
@@ -456,17 +449,17 @@ static void initiate_fit_params(int    eFitFn,
             {
                 GMX_ASSERT(params[3] >= 0, "parameters should be >= 0");
                 /* See comment under effnEXPEXP */
-                params[3] = std::max(fabs(params[3])-params[1], params[1]);
+                params[3] = std::max(fabs(params[3]) - params[1], params[1]);
                 if (nparm > 5)
                 {
                     GMX_ASSERT(params[5] >= 0, "parameters should be >= 0");
                     /* See comment under effnEXPEXP */
-                    params[5] = std::max(fabs(params[5])-params[3], params[3]);
+                    params[5] = std::max(fabs(params[5]) - params[3], params[3]);
                     if (nparm > 7)
                     {
                         GMX_ASSERT(params[7] >= 0, "parameters should be >= 0");
                         /* See comment under effnEXPEXP */
-                        params[7] = std::max(fabs(params[7])-params[5], params[5]);
+                        params[7] = std::max(fabs(params[7]) - params[5], params[5]);
                     }
                 }
             }
@@ -476,7 +469,7 @@ static void initiate_fit_params(int    eFitFn,
             GMX_ASSERT(params[1] >= 0 && params[1] <= 1, "parameter 1 should in 0 .. 1");
             GMX_ASSERT(params[2] >= 0, "parameters should be >= 0");
             /* See comment under effnEXPEXP */
-            params[2] = fabs(params[2])-params[0];
+            params[2] = fabs(params[2]) - params[0];
             break;
         case effnPRES:
             for (i = 1; (i < nparm); i++)
@@ -484,8 +477,7 @@ static void initiate_fit_params(int    eFitFn,
                 GMX_ASSERT(params[i] >= 0, "parameters should be >= 0");
             }
             break;
-        default:
-            break;
+        default: break;
     }
 }
 
@@ -493,8 +485,7 @@ static void initiate_fit_params(int    eFitFn,
  *
  * See comment at the previous function.
  */
-static void extract_fit_params(int    eFitFn,
-                               double params[])
+static void extract_fit_params(int eFitFn, double params[])
 {
     int i, nparm;
 
@@ -502,9 +493,7 @@ static void extract_fit_params(int    eFitFn,
 
     switch (eFitFn)
     {
-        case effnVAC:
-            params[0] = fabs(params[0]);
-            break;
+        case effnVAC: params[0] = fabs(params[0]); break;
         case effnEXP1:
         case effnEXP2:
         case effnEXPEXP:
@@ -514,7 +503,7 @@ static void extract_fit_params(int    eFitFn,
                 /* Back conversion of parameters from the fitted difference
                  * to the absolute value.
                  */
-                params[2] = fabs(params[2])+params[0];
+                params[2] = fabs(params[2]) + params[0];
             }
             break;
         case effnEXP5:
@@ -524,15 +513,15 @@ static void extract_fit_params(int    eFitFn,
             if (nparm > 3)
             {
                 /* See comment under effnEXPEXP */
-                params[3] = fabs(params[3])+params[1];
+                params[3] = fabs(params[3]) + params[1];
                 if (nparm > 5)
                 {
                     /* See comment under effnEXPEXP */
-                    params[5] = fabs(params[5])+params[3];
+                    params[5] = fabs(params[5]) + params[3];
                     if (nparm > 7)
                     {
                         /* See comment under effnEXPEXP */
-                        params[7] = fabs(params[7])+params[5];
+                        params[7] = fabs(params[7]) + params[5];
                     }
                 }
             }
@@ -548,7 +537,7 @@ static void extract_fit_params(int    eFitFn,
                 params[1] = 1;
             }
             /* See comment under effnEXPEXP */
-            params[2] = params[0]+fabs(params[2]);
+            params[2] = params[0] + fabs(params[2]);
             break;
         case effnPRES:
             for (i = 1; (i < nparm); i++)
@@ -556,16 +545,15 @@ static void extract_fit_params(int    eFitFn,
                 params[i] = fabs(params[i]);
             }
             break;
-        default:
-            break;
+        default: break;
     }
 }
 
 /*! \brief Print chi-squared value and the parameters */
-static void print_chi2_params(FILE        *fp,
+static void print_chi2_params(FILE*        fp,
                               const int    eFitFn,
                               const double fitparms[],
-                              const char  *label,
+                              const char*  label,
                               const int    nfitpnts,
                               const double x[],
                               const double y[])
@@ -578,8 +566,8 @@ static void print_chi2_params(FILE        *fp,
         double yfit = lmcurves[eFitFn](x[i], fitparms);
         chi2 += gmx::square(y[i] - yfit);
     }
-    fprintf(fp, "There are %d data points, %d parameters, %s chi2 = %g\nparams:",
-            nfitpnts, effnNparams(eFitFn), label, chi2);
+    fprintf(fp, "There are %d data points, %d parameters, %s chi2 = %g\nparams:", nfitpnts,
+            effnNparams(eFitFn), label, chi2);
     for (i = 0; (i < effnNparams(eFitFn)); i++)
     {
         fprintf(fp, "  %10g", fitparms[i]);
@@ -587,15 +575,24 @@ static void print_chi2_params(FILE        *fp,
     fprintf(fp, "\n");
 }
 
-real do_lmfit(int ndata, const real c1[], real sig[], real dt, const real *x0,
-              real begintimefit, real endtimefit, const gmx_output_env_t *oenv,
-              gmx_bool bVerbose, int eFitFn, double fitparms[], int fix,
-              const char *fn_fitted)
+real do_lmfit(int                     ndata,
+              const real              c1[],
+              real                    sig[],
+              real                    dt,
+              const real*             x0,
+              real                    begintimefit,
+              real                    endtimefit,
+              const gmx_output_env_t* oenv,
+              gmx_bool                bVerbose,
+              int                     eFitFn,
+              double                  fitparms[],
+              int                     fix,
+              const char*             fn_fitted)
 {
-    FILE    *fp;
-    int      i, j, nfitpnts;
-    double   integral, ttt;
-    double  *x, *y, *dy;
+    FILE*   fp;
+    int     i, j, nfitpnts;
+    double  integral, ttt;
+    double *x, *y, *dy;
 
     if (0 != fix)
     {
@@ -604,21 +601,21 @@ real do_lmfit(int ndata, const real c1[], real sig[], real dt, const real *x0,
     if (debug)
     {
         fprintf(debug, "There are %d points to fit %d vars!\n", ndata, effnNparams(eFitFn));
-        fprintf(debug, "Fit to function %d from %g through %g, dt=%g\n",
-                eFitFn, begintimefit, endtimefit, dt);
+        fprintf(debug, "Fit to function %d from %g through %g, dt=%g\n", eFitFn, begintimefit,
+                endtimefit, dt);
     }
 
     snew(x, ndata);
     snew(y, ndata);
     snew(dy, ndata);
-    j    = 0;
+    j = 0;
     for (i = 0; i < ndata; i++)
     {
-        ttt = x0 ? x0[i] : dt*i;
+        ttt = x0 ? x0[i] : dt * i;
         if (ttt >= begintimefit && ttt <= endtimefit)
         {
-            x[j]  = ttt;
-            y[j]  = c1[i];
+            x[j] = ttt;
+            y[j] = c1[i];
             if (nullptr == sig)
             {
                 // No weighting if all values are divided by 1.
@@ -630,8 +627,7 @@ real do_lmfit(int ndata, const real c1[], real sig[], real dt, const real *x0,
             }
             if (debug)
             {
-                fprintf(debug, "j= %d, i= %d, x= %g, y= %g, dy=%g, ttt=%g\n",
-                        j, i, x[j], y[j], dy[j], ttt);
+                fprintf(debug, "j= %d, i= %d, x= %g, y= %g, dy=%g, ttt=%g\n", j, i, x[j], y[j], dy[j], ttt);
             }
             j++;
         }
@@ -640,8 +636,7 @@ real do_lmfit(int ndata, const real c1[], real sig[], real dt, const real *x0,
     integral = 0;
     if (nfitpnts < effnNparams(eFitFn))
     {
-        fprintf(stderr, "Not enough (%d) data points for fitting, dt = %g!\n",
-                nfitpnts, dt);
+        fprintf(stderr, "Not enough (%d) data points for fitting, dt = %g!\n", nfitpnts, dt);
     }
     else
     {
@@ -668,33 +663,32 @@ real do_lmfit(int ndata, const real c1[], real sig[], real dt, const real *x0,
             }
             switch (eFitFn)
             {
-                case effnEXP1:
-                    integral = fitparms[0]*myexp(begintimefit, 1,  fitparms[0]);
-                    break;
+                case effnEXP1: integral = fitparms[0] * myexp(begintimefit, 1, fitparms[0]); break;
                 case effnEXP2:
-                    integral = fitparms[0]*myexp(begintimefit, fitparms[1],  fitparms[0]);
+                    integral = fitparms[0] * myexp(begintimefit, fitparms[1], fitparms[0]);
                     break;
                 case effnEXPEXP:
-                    integral = (fitparms[0]*myexp(begintimefit, fitparms[1],  fitparms[0]) +
-                                fitparms[2]*myexp(begintimefit, 1-fitparms[1], fitparms[2]));
+                    integral = (fitparms[0] * myexp(begintimefit, fitparms[1], fitparms[0])
+                                + fitparms[2] * myexp(begintimefit, 1 - fitparms[1], fitparms[2]));
                     break;
                 case effnEXP5:
                 case effnEXP7:
                 case effnEXP9:
                     integral = 0;
-                    for (i = 0; (i < (effnNparams(eFitFn)-1)/2); i++)
+                    for (i = 0; (i < (effnNparams(eFitFn) - 1) / 2); i++)
                     {
-                        integral += fitparms[2*i]*myexp(begintimefit, fitparms[2*i+1], fitparms[2*i]);
+                        integral += fitparms[2 * i]
+                                    * myexp(begintimefit, fitparms[2 * i + 1], fitparms[2 * i]);
                     }
                     break;
                 default:
                     /* Do numerical integration */
                     integral = 0;
-                    for (i = 0; (i < nfitpnts-1); i++)
+                    for (i = 0; (i < nfitpnts - 1); i++)
                     {
                         double y0 = lmcurves[eFitFn](x[i], fitparms);
-                        double y1 = lmcurves[eFitFn](x[i+1], fitparms);
-                        integral += (x[i+1]-x[i])*(y1+y0)*0.5;
+                        double y1 = lmcurves[eFitFn](x[i + 1], fitparms);
+                        integral += (x[i + 1] - x[i]) * (y1 + y0) * 0.5;
                     }
                     break;
             }
@@ -704,23 +698,22 @@ real do_lmfit(int ndata, const real c1[], real sig[], real dt, const real *x0,
                 printf("FIT: Integral of fitted function: %g\n", integral);
                 if ((effnEXP5 == eFitFn) || (effnEXP7 == eFitFn) || (effnEXP9 == eFitFn))
                 {
-                    printf("FIT: Note that the constant term is not taken into account when computing integral.\n");
+                    printf("FIT: Note that the constant term is not taken into account when "
+                           "computing integral.\n");
                 }
             }
             /* Generate debug output */
             if (nullptr != fn_fitted)
             {
-                fp = xvgropen(fn_fitted, "Data + Fit", "Time (ps)",
-                              "Data (t)", oenv);
+                fp = xvgropen(fn_fitted, "Data + Fit", "Time (ps)", "Data (t)", oenv);
                 for (i = 0; (i < effnNparams(eFitFn)); i++)
                 {
                     fprintf(fp, "# fitparms[%d] = %g\n", i, fitparms[i]);
                 }
                 for (j = 0; (j < nfitpnts); j++)
                 {
-                    real ttt = x0 ? x0[j] : dt*j;
-                    fprintf(fp, "%10.5e  %10.5e  %10.5e\n",
-                            x[j], y[j], (lmcurves[eFitFn])(ttt, fitparms));
+                    real ttt = x0 ? x0[j] : dt * j;
+                    fprintf(fp, "%10.5e  %10.5e  %10.5e\n", x[j], y[j], (lmcurves[eFitFn])(ttt, fitparms));
                 }
                 xvgrclose(fp);
             }
@@ -734,16 +727,23 @@ real do_lmfit(int ndata, const real c1[], real sig[], real dt, const real *x0,
     return integral;
 }
 
-real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbose,
-             real tbeginfit, real tendfit, real dt, real c1[], real *fit)
+real fit_acf(int                     ncorr,
+             int                     fitfn,
+             const gmx_output_env_t* oenv,
+             gmx_bool                bVerbose,
+             real                    tbeginfit,
+             real                    tendfit,
+             real                    dt,
+             real                    c1[],
+             real*                   fit)
 {
-    double      fitparm[3];
-    double      tStart, tail_corr, sum, sumtot = 0, c_start, ct_estimate;
-    real       *sig;
-    int         i, j, jmax, nf_int;
-    gmx_bool    bPrint;
+    double   fitparm[3];
+    double   tStart, tail_corr, sum, sumtot = 0, c_start, ct_estimate;
+    real*    sig;
+    int      i, j, jmax, nf_int;
+    gmx_bool bPrint;
 
-    GMX_ASSERT(effnNparams(fitfn) < static_cast<int>(sizeof(fitparm)/sizeof(double)),
+    GMX_ASSERT(effnNparams(fitfn) < static_cast<int>(sizeof(fitparm) / sizeof(double)),
                "Fitting function with more than 3 parameters not supported!");
     bPrint = bVerbose || bDebugMode();
 
@@ -754,26 +754,26 @@ real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbo
 
     if (tendfit <= 0)
     {
-        tendfit = ncorr*dt;
+        tendfit = ncorr * dt;
     }
-    nf_int = std::min(ncorr, static_cast<int>(tendfit/dt));
+    nf_int = std::min(ncorr, static_cast<int>(tendfit / dt));
     sum    = print_and_integrate(debug, nf_int, dt, c1, nullptr, 1);
 
     if (bPrint)
     {
-        printf("COR: Correlation time (plain integral from %6.3f to %6.3f ps) = %8.5f ps\n",
-               0.0, dt*nf_int, sum);
+        printf("COR: Correlation time (plain integral from %6.3f to %6.3f ps) = %8.5f ps\n", 0.0,
+               dt * nf_int, sum);
         printf("COR: Relaxation times are computed as fit to an exponential:\n");
         printf("COR:   %s\n", effnDescription(fitfn));
-        printf("COR: Fit to correlation function from %6.3f ps to %6.3f ps, results in a\n", tbeginfit, std::min(ncorr*dt, tendfit));
+        printf("COR: Fit to correlation function from %6.3f ps to %6.3f ps, results in a\n",
+               tbeginfit, std::min(ncorr * dt, tendfit));
     }
 
     tStart = 0;
     if (bPrint)
     {
-        printf("COR:%11s%11s%11s%11s%11s%11s%11s\n",
-               "Fit from", "Integral", "Tail Value", "Sum (ps)", " a1 (ps)",
-               (effnNparams(fitfn) >= 2) ? " a2 ()" : "",
+        printf("COR:%11s%11s%11s%11s%11s%11s%11s\n", "Fit from", "Integral", "Tail Value",
+               "Sum (ps)", " a1 (ps)", (effnNparams(fitfn) >= 2) ? " a2 ()" : "",
                (effnNparams(fitfn) >= 3) ? " a3 (ps)" : "");
     }
 
@@ -787,19 +787,19 @@ real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbo
     {
         jmax = 1;
     }
-    for (j = 0; ((j < jmax) && (tStart < tendfit) && (tStart < ncorr*dt)); j++)
+    for (j = 0; ((j < jmax) && (tStart < tendfit) && (tStart < ncorr * dt)); j++)
     {
         /* Estimate the correlation time for better fitting */
         c_start     = -1;
         ct_estimate = 0;
-        for (i = 0; (i < ncorr) && (dt*i < tStart || c1[i] > 0); i++)
+        for (i = 0; (i < ncorr) && (dt * i < tStart || c1[i] > 0); i++)
         {
             if (c_start < 0)
             {
-                if (dt*i >= tStart)
+                if (dt * i >= tStart)
                 {
                     c_start     = c1[i];
-                    ct_estimate = 0.5*c1[i];
+                    ct_estimate = 0.5 * c1[i];
                 }
             }
             else
@@ -809,7 +809,7 @@ real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbo
         }
         if (c_start > 0)
         {
-            ct_estimate *= dt/c_start;
+            ct_estimate *= dt / c_start;
         }
         else
         {
@@ -823,9 +823,9 @@ real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbo
 
         if (fitfn == effnEXPEXP)
         {
-            fitparm[0] = 0.002*ncorr*dt;
+            fitparm[0] = 0.002 * ncorr * dt;
             fitparm[1] = 0.95;
-            fitparm[2] = 0.2*ncorr*dt;
+            fitparm[2] = 0.2 * ncorr * dt;
         }
         else
         {
@@ -838,14 +838,14 @@ real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbo
         /* Generate more or less appropriate sigma's */
         for (i = 0; i < ncorr; i++)
         {
-            sig[i] = sqrt(ct_estimate+dt*i);
+            sig[i] = sqrt(ct_estimate + dt * i);
         }
 
-        nf_int    = std::min(ncorr, static_cast<int>((tStart+1e-4)/dt));
+        nf_int    = std::min(ncorr, static_cast<int>((tStart + 1e-4) / dt));
         sum       = print_and_integrate(debug, nf_int, dt, c1, nullptr, 1);
-        tail_corr = do_lmfit(ncorr, c1, sig, dt, nullptr, tStart, tendfit, oenv,
-                             bDebugMode(), fitfn, fitparm, 0, nullptr);
-        sumtot = sum+tail_corr;
+        tail_corr = do_lmfit(ncorr, c1, sig, dt, nullptr, tStart, tendfit, oenv, bDebugMode(),
+                             fitfn, fitparm, 0, nullptr);
+        sumtot    = sum + tail_corr;
         if (fit && ((jmax == 1) || (j == 1)))
         {
             double mfp[3];
@@ -855,7 +855,7 @@ real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbo
             }
             for (i = 0; (i < ncorr); i++)
             {
-                fit[i] = lmcurves[fitfn](i*dt, mfp);
+                fit[i] = lmcurves[fitfn](i * dt, mfp);
             }
         }
         if (bPrint)