Refactor preprocessing atom types.
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / topshake.cpp
index 49dea59eeec68632c6e27efc5d0e00ce516d7f7e..ca0b56ff7b5c7bcdd0100c41a6a577254dbf839c 100644 (file)
@@ -83,7 +83,7 @@ static void copy_bond (InteractionTypeParameters *pr, int to, int from)
 
 static int count_hydrogens (char ***atomname, int nra, const int a[])
 {
-    int  i, nh;
+    int  nh;
 
     if (!atomname)
     {
@@ -92,7 +92,7 @@ static int count_hydrogens (char ***atomname, int nra, const int a[])
     }
 
     nh = 0;
-    for (i = 0; (i < nra); i++)
+    for (int i = 0; (i < nra); i++)
     {
         if (toupper(**(atomname[a[i]])) == 'H')
         {
@@ -105,13 +105,9 @@ static int count_hydrogens (char ***atomname, int nra, const int a[])
 
 void make_shake(gmx::ArrayRef<InteractionTypeParameters> plist, t_atoms *atoms, int nshake)
 {
-    char                           ***info = atoms->atomname;
-    InteractionTypeParameters        *pr;
-    InteractionTypeParameters        *bonds;
-    t_param                           p, *bond, *ang;
-    real                              b_ij, b_jk;
-    int                               i, j, ftype, ftype_a;
-    bool                              bFound;
+    char                  ***info = atoms->atomname;
+    real                     b_ij, b_jk;
+    int                      i, j;
 
     if (nshake != eshNONE)
     {
@@ -138,27 +134,25 @@ void make_shake(gmx::ArrayRef<InteractionTypeParameters> plist, t_atoms *atoms,
             /* Add all the angles with hydrogens to the shake list
              * and remove them from the bond list
              */
-            for (ftype = 0; (ftype < F_NRE); ftype++)
+            for (int ftype = 0; (ftype < F_NRE); ftype++)
             {
                 if (interaction_function[ftype].flags & IF_BTYPE)
                 {
-                    bonds = &(plist[ftype]);
+                    InteractionTypeParameters *bonds = &(plist[ftype]);
 
-                    for (ftype_a = 0; (bonds->nr > 0 && ftype_a < F_NRE); ftype_a++)
+                    for (int ftype_a = 0; (bonds->nr > 0 && ftype_a < F_NRE); ftype_a++)
                     {
                         if (interaction_function[ftype_a].flags & IF_ATYPE)
                         {
-                            pr = &(plist[ftype_a]);
+                            InteractionTypeParameters *pr = &(plist[ftype_a]);
 
-                            for (i = 0; (i < pr->nr); )
+                            for (int i = 0; (i < pr->nr); )
                             {
-                                int numhydrogens;
-
-                                ang = &(pr->param[i]);
+                                t_param *ang = &(pr->param[i]);
 #ifdef DEBUG
                                 printf("Angle: %d-%d-%d\n", ang->ai(), ang->aj(), ang->ak());
 #endif
-                                numhydrogens = count_hydrogens(info, 3, ang->a);
+                                int numhydrogens = count_hydrogens(info, 3, ang->a);
                                 if ((nshake == eshALLANGLES) ||
                                     (numhydrogens > 1) ||
                                     (numhydrogens == 1 && toupper(**(info[ang->a[1]])) == 'O'))
@@ -167,15 +161,16 @@ void make_shake(gmx::ArrayRef<InteractionTypeParameters> plist, t_atoms *atoms,
                                      * are constrained.
                                      * append this angle to the shake list
                                      */
+                                    t_param p;
                                     p.ai() = ang->ai();
                                     p.aj() = ang->ak();
 
                                     /* Calculate length of constraint */
-                                    bFound = FALSE;
+                                    bool bFound = false;
                                     b_ij   = b_jk = 0.0;
-                                    for (j = 0; !bFound && (j < bonds->nr); j++)
+                                    for (int j = 0; !bFound && (j < bonds->nr); j++)
                                     {
-                                        bond = &(bonds->param[j]);
+                                        t_param *bond = &(bonds->param[j]);
                                         if (((bond->ai() == ang->ai()) &&
                                              (bond->aj() == ang->aj())) ||
                                             ((bond->ai() == ang->aj()) &&
@@ -222,11 +217,11 @@ void make_shake(gmx::ArrayRef<InteractionTypeParameters> plist, t_atoms *atoms,
         /* Add all the bonds with hydrogens to the shake list
          * and remove them from the bond list
          */
-        for (ftype = 0; (ftype < F_NRE); ftype++)
+        for (int ftype = 0; (ftype < F_NRE); ftype++)
         {
             if (interaction_function[ftype].flags & IF_BTYPE)
             {
-                pr = &(plist[ftype]);
+                InteractionTypeParameters *pr = &(plist[ftype]);
                 j  = 0;
                 for (i = 0; i < pr->nr; i++)
                 {
@@ -234,6 +229,7 @@ void make_shake(gmx::ArrayRef<InteractionTypeParameters> plist, t_atoms *atoms,
                          (count_hydrogens (info, 2, pr->param[i].a) > 0) )
                     {
                         /* append this bond to the shake list */
+                        t_param p;
                         p.ai() = pr->param[i].ai();
                         p.aj() = pr->param[i].aj();
                         p.c0() = pr->param[i].c0();