Fixed bug in statistics which did not allow fitting with weights.
authorDavid van der Spoel <spoel@xray.bmc.uu.se>
Thu, 23 Dec 2010 08:19:48 +0000 (09:19 +0100)
committerDavid van der Spoel <spoel@xray.bmc.uu.se>
Thu, 23 Dec 2010 08:19:48 +0000 (09:19 +0100)
Added check for return value from statistics codes in g_analyze.

src/gmxlib/statistics/gmx_statistics.c
src/tools/gmx_analyze.c

index eb723bed61e13c1f96c3338abbd16fc9f5e2b7b1..7b50f924ae28a92aa4cb5ca9c2f94d808218457c 100644 (file)
@@ -180,11 +180,6 @@ static int gmx_stats_compute(gmx_stats *stats,int weight)
             return estatsNO_POINTS;
         }
       
-        if (weight != elsqWEIGHT_NONE)
-        {
-            return estatsNOT_IMPLEMENTED;
-        }
-        
         xx = xx_nw = 0;
         yy = yy_nw = 0;
         yx = yx_nw = 0;
index 4eaf3ea9a5d6c2ea9bf7bf7801a42996aec43866..5ea19fe52839b1a89a2aaeadde2b21b8cdd61775 100644 (file)
@@ -139,7 +139,8 @@ static void regression_analysis(int n,gmx_bool bXYdy,
                                 real *x,int nset,real **val)
 {
   real S,chi2,a,b,da,db,r=0;
-
+  int ok;
+  
   if (bXYdy || (nset == 1)) 
   {
       printf("Fitting data to a function f(x) = ax + b\n");
@@ -147,9 +148,17 @@ static void regression_analysis(int n,gmx_bool bXYdy,
       printf("Error estimates will be given if w_i (sigma) values are given\n");
       printf("(use option -xydy).\n\n");
       if (bXYdy) 
-          lsq_y_ax_b_error(n,x,val[0],val[1],&a,&b,&da,&db,&r,&S);
+      {
+          if ((ok = lsq_y_ax_b_error(n,x,val[0],val[1],&a,&b,&da,&db,&r,&S)) != estatsOK)
+              gmx_fatal(FARGS,"Error fitting the data: %s",
+                        gmx_stats_message(ok));
+      }
       else
-          lsq_y_ax_b(n,x,val[0],&a,&b,&r,&S);
+      {
+          if ((ok = lsq_y_ax_b(n,x,val[0],&a,&b,&r,&S)) != estatsOK)
+              gmx_fatal(FARGS,"Error fitting the data: %s",
+                        gmx_stats_message(ok));
+      }
       chi2 = sqr((n-2)*S);
       printf("Chi2                    = %g\n",chi2);
       printf("S (Sqrt(Chi2/(n-2))     = %g\n",S);