Fixed g_bar bug in lambda value parsing from path.
authorSzilard Pall <pszilard@cbr.su.se>
Sun, 4 Apr 2010 02:19:08 +0000 (04:19 +0200)
committerSzilard Pall <pszilard@cbr.su.se>
Sun, 4 Apr 2010 02:19:08 +0000 (04:19 +0200)
When extracting the lambda values from file path, if the directory
with the lambda value in its name was preceeded by a directory name
with a number in it, g_bar picked this up istead of lambda.

src/tools/gmx_bar.c

index 12a005d8cbf321014d5bc8714cfc6d92275b8c5e..14f2600a4a6b26f145b65b95d5bddf7079bdbaf3 100644 (file)
@@ -499,18 +499,33 @@ static double filename2lambda(char *fn)
     char   *ptr,*endptr;
     
     ptr = fn;
-    while (ptr[0] != '\0' && !isdigit(ptr[0]))
+    /* go to the end of the path string and search backward 
+       because there might be numbers in the directory names 
+       before the directory in which the lambda value is
+     */
+    while (ptr[1] != '\0')
     {
         ptr++;
     }
+    while (!isdigit(*ptr) && ptr > fn)
+    {
+        ptr--;
+    }
     if (!isdigit(ptr[0]))
     {
         gmx_fatal(FARGS,"While trying to read the lambda value from the filename: filename '%s' does not contain a number",fn);
     }
-    if (ptr > fn && fn[ptr-fn-1] == '-')
+    /* now that we have the last digit of the number we are looking for 
+       let's find the beginning of the number and the sign if it has one
+     */
+    while ((isdigit(*ptr) || ptr[0] == '.') && ptr > fn)
     {
         ptr--;
     }
+    if (ptr[0] != '-')
+    {
+        ptr++;
+    }
 
     lambda = strtod(ptr,&endptr);
     if (endptr == ptr)