Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / fileio / g96io.cpp
index ff4dfbf16e55cfb22dba524f41770ecdbd49e666..89c3557f51dd1a9e984f4871cf5c7a5ee6d66b68 100644 (file)
 
 #define CHAR_SHIFT 24
 
-static int read_g96_pos(char line[], t_symtab *symtab,
-                        FILE *fp, const char *infile,
-                        t_trxframe *fr)
+static int read_g96_pos(char line[], t_symtab* symtab, FILE* fp, const char* infile, t_trxframe* fr)
 {
-    t_atoms   *atoms;
-    gmx_bool   bEnd;
-    int        nwanted, natoms, atnr, resnr = 0, oldres, newres, shift;
-    char       anm[STRLEN], resnm[STRLEN];
-    char       c1, c2;
-    double     db1, db2, db3;
+    t_atomsatoms;
+    gmx_bool bEnd;
+    int      nwanted, natoms, atnr, resnr = 0, oldres, newres, shift;
+    char     anm[STRLEN], resnm[STRLEN];
+    char     c1, c2;
+    double   db1, db2, db3;
 
     nwanted = fr->natoms;
 
     if (fr->atoms != nullptr)
     {
-        GMX_RELEASE_ASSERT(symtab != nullptr, "Reading a conformation from a g96 format with atom data requires a valid symbol table");
+        GMX_RELEASE_ASSERT(symtab != nullptr,
+                           "Reading a conformation from a g96 format with atom data requires a "
+                           "valid symbol table");
     }
     atoms = fr->atoms;
     if (atoms != nullptr)
@@ -92,30 +92,27 @@ static int read_g96_pos(char line[], t_symtab *symtab,
         {
             shift = 0;
         }
-        newres  = -1;
-        oldres  = -666; /* Unlikely number for the first residue! */
-        bEnd    = FALSE;
+        newres = -1;
+        oldres = -666; /* Unlikely number for the first residue! */
+        bEnd   = FALSE;
         while (!bEnd && fgets2(line, STRLEN, fp))
         {
             bEnd = (std::strncmp(line, "END", 3) == 0);
-            if (!bEnd  && (line[0] != '#'))
+            if (!bEnd && (line[0] != '#'))
             {
-                if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
+                if (sscanf(line + shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
                 {
-                    gmx_fatal(FARGS, "Did not find 3 coordinates for atom %d in %s\n",
-                              natoms+1, infile);
+                    gmx_fatal(FARGS, "Did not find 3 coordinates for atom %d in %s\n", natoms + 1, infile);
                 }
                 if ((nwanted != -1) && (natoms >= nwanted))
                 {
-                    gmx_fatal(FARGS,
-                              "Found more coordinates (%d) in %s than expected %d\n",
-                              natoms, infile, nwanted);
+                    gmx_fatal(FARGS, "Found more coordinates (%d) in %s than expected %d\n", natoms,
+                              infile, nwanted);
                 }
                 if (atoms)
                 {
-                    if (fr->bAtoms &&
-                        (sscanf(line, "%5d%c%5s%c%5s%7d", &resnr, &c1, resnm, &c2, anm, &atnr)
-                         != 6))
+                    if (fr->bAtoms
+                        && (sscanf(line, "%5d%c%5s%c%5s%7d", &resnr, &c1, resnm, &c2, anm, &atnr) != 6))
                     {
                         if (oldres >= 0)
                         {
@@ -123,10 +120,10 @@ static int read_g96_pos(char line[], t_symtab *symtab,
                         }
                         else
                         {
-                            resnr    = 1;
-                            strncpy(resnm, "???", sizeof(resnm)-1);
+                            resnr = 1;
+                            strncpy(resnm, "???", sizeof(resnm) - 1);
                         }
-                        strncpy(anm, "???", sizeof(anm)-1);
+                        strncpy(anm, "???", sizeof(anm) - 1);
                     }
                     atoms->atomname[natoms] = put_symtab(symtab, anm);
                     if (resnr != oldres)
@@ -135,13 +132,13 @@ static int read_g96_pos(char line[], t_symtab *symtab,
                         newres++;
                         if (newres >= atoms->nr)
                         {
-                            gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)",
-                                      infile, atoms->nr);
+                            gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)", infile,
+                                      atoms->nr);
                         }
                         atoms->atom[natoms].resind = newres;
-                        if (newres+1 > atoms->nres)
+                        if (newres + 1 > atoms->nres)
                         {
-                            atoms->nres = newres+1;
+                            atoms->nres = newres + 1;
                         }
                         t_atoms_set_resinfo(atoms, natoms, symtab, resnm, resnr, ' ', 0, ' ');
                     }
@@ -161,9 +158,8 @@ static int read_g96_pos(char line[], t_symtab *symtab,
         }
         if ((nwanted != -1) && natoms != nwanted)
         {
-            fprintf(stderr,
-                    "Warning: found less coordinates (%d) in %s than expected %d\n",
-                    natoms, infile, nwanted);
+            fprintf(stderr, "Warning: found less coordinates (%d) in %s than expected %d\n", natoms,
+                    infile, nwanted);
         }
     }
 
@@ -172,12 +168,11 @@ static int read_g96_pos(char line[], t_symtab *symtab,
     return natoms;
 }
 
-static int read_g96_vel(char line[], FILE *fp, const char *infile,
-                        t_trxframe *fr)
+static int read_g96_vel(char line[], FILE* fp, const char* infile, t_trxframe* fr)
 {
-    gmx_bool   bEnd;
-    int        nwanted, natoms = -1, shift;
-    double     db1, db2, db3;
+    gmx_bool bEnd;
+    int      nwanted, natoms = -1, shift;
+    double   db1, db2, db3;
 
     nwanted = fr->natoms;
 
@@ -198,15 +193,14 @@ static int read_g96_vel(char line[], FILE *fp, const char *infile,
             bEnd = (strncmp(line, "END", 3) == 0);
             if (!bEnd && (line[0] != '#'))
             {
-                if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
+                if (sscanf(line + shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
                 {
-                    gmx_fatal(FARGS, "Did not find 3 velocities for atom %d in %s",
-                              natoms+1, infile);
+                    gmx_fatal(FARGS, "Did not find 3 velocities for atom %d in %s", natoms + 1, infile);
                 }
                 if ((nwanted != -1) && (natoms >= nwanted))
                 {
-                    gmx_fatal(FARGS, "Found more velocities (%d) in %s than expected %d\n",
-                              natoms, infile, nwanted);
+                    gmx_fatal(FARGS, "Found more velocities (%d) in %s than expected %d\n", natoms,
+                              infile, nwanted);
                 }
                 if (fr->v)
                 {
@@ -219,21 +213,19 @@ static int read_g96_vel(char line[], FILE *fp, const char *infile,
         }
         if ((nwanted != -1) && (natoms != nwanted))
         {
-            fprintf(stderr,
-                    "Warning: found less velocities (%d) in %s than expected %d\n",
-                    natoms, infile, nwanted);
+            fprintf(stderr, "Warning: found less velocities (%d) in %s than expected %d\n", natoms,
+                    infile, nwanted);
         }
     }
 
     return natoms;
 }
 
-int read_g96_conf(FILE *fp, const char *infile, char **name, t_trxframe *fr,
-                  t_symtab *symtab, char *line)
+int read_g96_conf(FILE* fp, const char* infile, char** name, t_trxframe* fr, t_symtab* symtab, char* line)
 {
-    gmx_bool   bAtStart, bTime, bAtoms, bPos, bVel, bBox, bEnd, bFinished;
-    int        natoms, nbp;
-    double     db1, db2, db3, db4, db5, db6, db7, db8, db9;
+    gmx_bool bAtStart, bTime, bAtoms, bPos, bVel, bBox, bEnd, bFinished;
+    int      natoms, nbp;
+    double   db1, db2, db3, db4, db5, db6, db7, db8, db9;
 
     bAtStart = (ftell(fp) == 0);
 
@@ -282,8 +274,7 @@ int read_g96_conf(FILE *fp, const char *infile, char **name, t_trxframe *fr,
                 do
                 {
                     bFinished = (fgets2(line, STRLEN, fp) == nullptr);
-                }
-                while (!bFinished && (line[0] == '#'));
+                } while (!bFinished && (line[0] == '#'));
                 sscanf(line, "%15" SCNd64 "%15lf", &(fr->step), &db1);
                 fr->time = db1;
             }
@@ -320,8 +311,8 @@ int read_g96_conf(FILE *fp, const char *infile, char **name, t_trxframe *fr,
                 bEnd = (strncmp(line, "END", 3) == 0);
                 if (!bEnd && (line[0] != '#'))
                 {
-                    nbp = sscanf(line, "%15lf%15lf%15lf%15lf%15lf%15lf%15lf%15lf%15lf",
-                                 &db1, &db2, &db3, &db4, &db5, &db6, &db7, &db8, &db9);
+                    nbp = sscanf(line, "%15lf%15lf%15lf%15lf%15lf%15lf%15lf%15lf%15lf", &db1, &db2,
+                                 &db3, &db4, &db5, &db6, &db7, &db8, &db9);
                     if (nbp < 3)
                     {
                         gmx_fatal(FARGS, "Found a BOX line, but no box in %s", infile);
@@ -342,18 +333,16 @@ int read_g96_conf(FILE *fp, const char *infile, char **name, t_trxframe *fr,
             }
             bFinished = TRUE;
         }
-    }
-    while (!bFinished && (fgets2(line, STRLEN, fp) != nullptr));
+    } while (!bFinished && (fgets2(line, STRLEN, fp) != nullptr));
 
     fr->natoms = natoms;
 
     return natoms;
 }
 
-void write_g96_conf(FILE *out, const char *title, const t_trxframe *fr,
-                    int nindex, const int *index)
+void write_g96_conf(FILE* out, const char* title, const t_trxframe* fr, int nindex, const int* index)
 {
-    t_atoms *atoms;
+    t_atomsatoms;
     int      nout, i, a;
 
     atoms = fr->atoms;
@@ -390,9 +379,8 @@ void write_g96_conf(FILE *out, const char *title, const t_trxframe *fr,
                 }
                 fprintf(out, "%5d %-5s %-5s%7d%15.9f%15.9f%15.9f\n",
                         (atoms->resinfo[atoms->atom[a].resind].nr) % 100000,
-                        *atoms->resinfo[atoms->atom[a].resind].name,
-                        *atoms->atomname[a], (i+1) % 10000000,
-                        fr->x[a][XX], fr->x[a][YY], fr->x[a][ZZ]);
+                        *atoms->resinfo[atoms->atom[a].resind].name, *atoms->atomname[a],
+                        (i + 1) % 10000000, fr->x[a][XX], fr->x[a][YY], fr->x[a][ZZ]);
             }
         }
         else
@@ -408,8 +396,7 @@ void write_g96_conf(FILE *out, const char *title, const t_trxframe *fr,
                 {
                     a = i;
                 }
-                fprintf(out, "%15.9f%15.9f%15.9f\n",
-                        fr->x[a][XX], fr->x[a][YY], fr->x[a][ZZ]);
+                fprintf(out, "%15.9f%15.9f%15.9f\n", fr->x[a][XX], fr->x[a][YY], fr->x[a][ZZ]);
             }
         }
         fprintf(out, "END\n");
@@ -431,9 +418,8 @@ void write_g96_conf(FILE *out, const char *title, const t_trxframe *fr,
                 }
                 fprintf(out, "%5d %-5s %-5s%7d%15.9f%15.9f%15.9f\n",
                         (atoms->resinfo[atoms->atom[a].resind].nr) % 100000,
-                        *atoms->resinfo[atoms->atom[a].resind].name,
-                        *atoms->atomname[a], (i+1) % 10000000,
-                        fr->v[a][XX], fr->v[a][YY], fr->v[a][ZZ]);
+                        *atoms->resinfo[atoms->atom[a].resind].name, *atoms->atomname[a],
+                        (i + 1) % 10000000, fr->v[a][XX], fr->v[a][YY], fr->v[a][ZZ]);
             }
         }
         else
@@ -449,8 +435,7 @@ void write_g96_conf(FILE *out, const char *title, const t_trxframe *fr,
                 {
                     a = i;
                 }
-                fprintf(out, "%15.9f%15.9f%15.9f\n",
-                        fr->v[a][XX], fr->v[a][YY], fr->v[a][ZZ]);
+                fprintf(out, "%15.9f%15.9f%15.9f\n", fr->v[a][XX], fr->v[a][YY], fr->v[a][ZZ]);
             }
         }
         fprintf(out, "END\n");
@@ -458,14 +443,12 @@ void write_g96_conf(FILE *out, const char *title, const t_trxframe *fr,
     if (fr->bBox)
     {
         fprintf(out, "BOX\n");
-        fprintf(out, "%15.9f%15.9f%15.9f",
-                fr->box[XX][XX], fr->box[YY][YY], fr->box[ZZ][ZZ]);
-        if ((fr->box[XX][YY] != 0.0F) || (fr->box[XX][ZZ] != 0.0F) || (fr->box[YY][XX] != 0.0F) ||
-            (fr->box[YY][ZZ] != 0.0F) || (fr->box[ZZ][XX] != 0.0F) || (fr->box[ZZ][YY] != 0.0F))
+        fprintf(out, "%15.9f%15.9f%15.9f", fr->box[XX][XX], fr->box[YY][YY], fr->box[ZZ][ZZ]);
+        if ((fr->box[XX][YY] != 0.0F) || (fr->box[XX][ZZ] != 0.0F) || (fr->box[YY][XX] != 0.0F)
+            || (fr->box[YY][ZZ] != 0.0F) || (fr->box[ZZ][XX] != 0.0F) || (fr->box[ZZ][YY] != 0.0F))
         {
-            fprintf(out, "%15.9f%15.9f%15.9f%15.9f%15.9f%15.9f",
-                    fr->box[XX][YY], fr->box[XX][ZZ], fr->box[YY][XX],
-                    fr->box[YY][ZZ], fr->box[ZZ][XX], fr->box[ZZ][YY]);
+            fprintf(out, "%15.9f%15.9f%15.9f%15.9f%15.9f%15.9f", fr->box[XX][YY], fr->box[XX][ZZ],
+                    fr->box[YY][XX], fr->box[YY][ZZ], fr->box[ZZ][XX], fr->box[ZZ][YY]);
         }
         fprintf(out, "\n");
         fprintf(out, "END\n");