Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / fileio / confio.c
index ef01aa45f771f253c55c0b94b7ee93e5ce333e86..c8a35d79cf6d19ab7eaf45eb710c8f5e39b792d4 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, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
@@ -923,6 +923,7 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
                            rvec x[], rvec *v, matrix box)
 {
     char       name[6];
+    char       resname[6], oldresname[6];
     char       line[STRLEN+1], *ptr;
     char       buf[256];
     double     x1, y1, z1, x2, y2, z2;
@@ -953,6 +954,9 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
 
     bVel = FALSE;
 
+    resname[0]     = '\0';
+    oldresname[0]  = '\0';
+
     /* just pray the arrays are big enough */
     for (i = 0; (i < natoms); i++)
     {
@@ -1000,9 +1004,9 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
         memcpy(name, line, 5);
         name[5] = '\0';
         sscanf(name, "%d", &resnr);
-        memcpy(name, line+5, 5);
-        name[5] = '\0';
-        if (resnr != oldres)
+        sscanf(line+5, "%5s", resname);
+
+        if (resnr != oldres || strncmp(resname, oldresname, sizeof(resname)))
         {
             oldres = resnr;
             newres++;
@@ -1012,7 +1016,7 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
                           infile, natoms);
             }
             atoms->atom[i].resind = newres;
-            t_atoms_set_resinfo(atoms, i, symtab, name, resnr, ' ', 0, ' ');
+            t_atoms_set_resinfo(atoms, i, symtab, resname, resnr, ' ', 0, ' ');
         }
         else
         {
@@ -1023,6 +1027,9 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
         memcpy(name, line+10, 5);
         atoms->atomname[i] = put_symtab(symtab, name);
 
+        /* Copy resname to oldresname after we are done with the sanity check above */
+        strncpy(oldresname, resname, sizeof(oldresname));
+
         /* eventueel controle atomnumber met i+1 */
 
         /* coordinates (start after residue data) */