Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / fileio / trxio.cpp
index 846bb2a0a160453eb37892d2d69ac1508bf766db..34ee2995c915914ba3159cb2f591dfbf0335bd97 100644 (file)
 #include "gromacs/utility/smalloc.h"
 
 #if GMX_USE_PLUGINS
-#include "gromacs/fileio/vmdio.h"
+#    include "gromacs/fileio/vmdio.h"
 #endif
 
 /* defines for frame counter output */
-#define SKIP1   10
-#define SKIP2  100
+#define SKIP1 10
+#define SKIP2 100
 #define SKIP3 1000
 
 struct t_trxstatus
 {
-    int                     flags;            /* flags for read_first/next_frame  */
-    int                     __frame;
-    real                    t0;               /* time of the first frame, needed  *
-                                               * for skipping frames with -dt     */
-    real                    tf;               /* internal frame time              */
-    t_trxframe             *xframe;
-    t_fileio               *fio;
-    gmx_tng_trajectory_t    tng;
-    int                     natoms;
-    double                  DT, BOX[3];
-    gmx_bool                bReadBox;
-    char                   *persistent_line; /* Persistent line for reading g96 trajectories */
+    int  flags; /* flags for read_first/next_frame  */
+    int  __frame;
+    real t0;                 /* time of the first frame, needed  *
+                              * for skipping frames with -dt     */
+    real                 tf; /* internal frame time              */
+    t_trxframe*          xframe;
+    t_fileio*            fio;
+    gmx_tng_trajectory_t tng;
+    int                  natoms;
+    double               DT, BOX[3];
+    gmx_bool             bReadBox;
+    char*                persistent_line; /* Persistent line for reading g96 trajectories */
 #if GMX_USE_PLUGINS
-    gmx_vmdplugin_t        *vmdplugin;
+    gmx_vmdplugin_tvmdplugin;
 #endif
 };
 
@@ -105,18 +105,17 @@ gmx_bool bRmod_fd(double a, double b, double c, gmx_bool bDouble)
     int    iq;
     double tol;
 
-    tol = 2*(bDouble ? GMX_DOUBLE_EPS : GMX_FLOAT_EPS);
+    tol = 2 * (bDouble ? GMX_DOUBLE_EPS : GMX_FLOAT_EPS);
 
-    iq = static_cast<int>((a - b + tol*a)/c);
+    iq = static_cast<int>((a - b + tol * a) / c);
 
-    return fabs(a - b - c*iq) <= tol*fabs(a);
+    return fabs(a - b - c * iq) <= tol * fabs(a);
 }
 
 
-
 int check_times2(real t, real t0, gmx_bool bDouble)
 {
-    int  r;
+    int r;
 
 #if !GMX_DOUBLE
     /* since t is float, we can not use double precision for bRmod */
@@ -124,8 +123,7 @@ int check_times2(real t, real t0, gmx_bool bDouble)
 #endif
 
     r = -1;
-    if ((!bTimeSet(TBEGIN) || (t >= rTimeValue(TBEGIN)))  &&
-        (!bTimeSet(TEND)   || (t <= rTimeValue(TEND))))
+    if ((!bTimeSet(TBEGIN) || (t >= rTimeValue(TBEGIN))) && (!bTimeSet(TEND) || (t <= rTimeValue(TEND))))
     {
         if (bTimeSet(TDELTA) && !bRmod_fd(t, t0, rTimeValue(TDELTA), bDouble))
         {
@@ -142,8 +140,8 @@ int check_times2(real t, real t0, gmx_bool bDouble)
     }
     if (debug)
     {
-        fprintf(debug, "t=%g, t0=%g, b=%g, e=%g, dt=%g: r=%d\n",
-                t, t0, rTimeValue(TBEGIN), rTimeValue(TEND), rTimeValue(TDELTA), r);
+        fprintf(debug, "t=%g, t0=%g, b=%g, e=%g, dt=%g: r=%d\n", t, t0, rTimeValue(TBEGIN),
+                rTimeValue(TEND), rTimeValue(TDELTA), r);
     }
     return r;
 }
@@ -153,12 +151,12 @@ int check_times(real t)
     return check_times2(t, t, FALSE);
 }
 
-static void initcount(t_trxstatus *status)
+static void initcount(t_trxstatusstatus)
 {
     status->__frame = -1;
 }
 
-static void status_init(t_trxstatus *status)
+static void status_init(t_trxstatusstatus)
 {
     status->flags           = 0;
     status->xframe          = nullptr;
@@ -171,50 +169,45 @@ static void status_init(t_trxstatus *status)
 }
 
 
-int nframes_read(t_trxstatus *status)
+int nframes_read(t_trxstatusstatus)
 {
     return status->__frame;
 }
 
-static void printcount_(t_trxstatus *status, const gmx_output_env_t *oenv,
-                        const char *l, real t)
+static void printcount_(t_trxstatus* status, const gmx_output_env_t* oenv, const char* l, real t)
 {
-    if ((status->__frame < 2*SKIP1 || status->__frame % SKIP1 == 0) &&
-        (status->__frame < 2*SKIP2 || status->__frame % SKIP2 == 0) &&
-        (status->__frame < 2*SKIP3 || status->__frame % SKIP3 == 0) &&
-        output_env_get_trajectory_io_verbosity(oenv) != 0)
+    if ((status->__frame < 2 * SKIP1 || status->__frame % SKIP1 == 0)
+        && (status->__frame < 2 * SKIP2 || status->__frame % SKIP2 == 0)
+        && (status->__frame < 2 * SKIP3 || status->__frame % SKIP3 == 0)
+        && output_env_get_trajectory_io_verbosity(oenv) != 0)
     {
-        fprintf(stderr, "\r%-14s %6d time %8.3f   ", l, status->__frame,
-                output_env_conv_time(oenv, t));
+        fprintf(stderr, "\r%-14s %6d time %8.3f   ", l, status->__frame, output_env_conv_time(oenv, t));
         fflush(stderr);
     }
 }
 
-static void printcount(t_trxstatus *status, const gmx_output_env_t *oenv, real t,
-                       gmx_bool bSkip)
+static void printcount(t_trxstatus* status, const gmx_output_env_t* oenv, real t, gmx_bool bSkip)
 {
     status->__frame++;
     printcount_(status, oenv, bSkip ? "Skipping frame" : "Reading frame", t);
 }
 
-static void printlast(t_trxstatus *status, const gmx_output_env_t *oenv, real t)
+static void printlast(t_trxstatus* status, const gmx_output_env_t* oenv, real t)
 {
     printcount_(status, oenv, "Last frame", t);
     fprintf(stderr, "\n");
     fflush(stderr);
 }
 
-static void printincomp(t_trxstatus *status, t_trxframe *fr)
+static void printincomp(t_trxstatus* status, t_trxframe* fr)
 {
     if (fr->not_ok & HEADER_NOT_OK)
     {
-        fprintf(stderr, "WARNING: Incomplete header: nr %d time %g\n",
-                status->__frame+1, fr->time);
+        fprintf(stderr, "WARNING: Incomplete header: nr %d time %g\n", status->__frame + 1, fr->time);
     }
     else if (fr->not_ok)
     {
-        fprintf(stderr, "WARNING: Incomplete frame: nr %d time %g\n",
-                status->__frame+1, fr->time);
+        fprintf(stderr, "WARNING: Incomplete frame: nr %d time %g\n", status->__frame + 1, fr->time);
     }
     fflush(stderr);
 }
@@ -226,7 +219,7 @@ int prec2ndec(real prec)
         gmx_fatal(FARGS, "DEATH HORROR prec (%g) <= 0 in prec2ndec", prec);
     }
 
-    return gmx::roundToInt(log(prec)/log(10.0));
+    return gmx::roundToInt(log(prec) / log(10.0));
 }
 
 real ndec2prec(int ndec)
@@ -234,27 +227,25 @@ real ndec2prec(int ndec)
     return pow(10.0, ndec);
 }
 
-t_fileio *trx_get_fileio(t_trxstatus *status)
+t_fileio* trx_get_fileio(t_trxstatus* status)
 {
     return status->fio;
 }
 
-float trx_get_time_of_final_frame(t_trxstatus *status)
+float trx_get_time_of_final_frame(t_trxstatusstatus)
 {
-    t_fileio *stfio    = trx_get_fileio(status);
+    t_fileiostfio    = trx_get_fileio(status);
     int       filetype = gmx_fio_getftp(stfio);
     gmx_bool  bOK;
     float     lasttime = -1;
 
     if (filetype == efXTC)
     {
-        lasttime =
-            xdr_xtc_get_last_frame_time(gmx_fio_getfp(stfio),
-                                        gmx_fio_getxdr(stfio),
-                                        status->natoms, &bOK);
+        lasttime = xdr_xtc_get_last_frame_time(gmx_fio_getfp(stfio), gmx_fio_getxdr(stfio),
+                                               status->natoms, &bOK);
         if (!bOK)
         {
-            gmx_fatal(FARGS, "Error reading last frame. Maybe seek not supported." );
+            gmx_fatal(FARGS, "Error reading last frame. Maybe seek not supported.");
         }
     }
     else if (filetype == efTNG)
@@ -273,7 +264,7 @@ float trx_get_time_of_final_frame(t_trxstatus *status)
     return lasttime;
 }
 
-void clear_trxframe(t_trxframe *fr, gmx_bool bFirst)
+void clear_trxframe(t_trxframefr, gmx_bool bFirst)
 {
     fr->not_ok    = 0;
     fr->bStep     = FALSE;
@@ -300,19 +291,18 @@ void clear_trxframe(t_trxframe *fr, gmx_bool bFirst)
         fr->v         = nullptr;
         fr->f         = nullptr;
         clear_mat(fr->box);
-        fr->bPBC   = FALSE;
-        fr->ePBC   = -1;
+        fr->bPBC = FALSE;
+        fr->ePBC = -1;
     }
 }
 
-void set_trxframe_ePBC(t_trxframe *fr, int ePBC)
+void set_trxframe_ePBC(t_trxframefr, int ePBC)
 {
     fr->bPBC = (ePBC == -1);
     fr->ePBC = ePBC;
 }
 
-int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind,
-                           const int *ind, gmx_conect gc)
+int write_trxframe_indexed(t_trxstatus* status, const t_trxframe* fr, int nind, const int* ind, gmx_conect gc)
 {
     char  title[STRLEN];
     rvec *xout = nullptr, *vout = nullptr, *fout = nullptr;
@@ -344,13 +334,11 @@ int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind,
     switch (ftp)
     {
         case efTRR:
-        case efTNG:
-            break;
+        case efTNG: break;
         default:
             if (!fr->bX)
             {
-                gmx_fatal(FARGS, "Need coordinates to write a %s trajectory",
-                          ftp2ext(ftp));
+                gmx_fatal(FARGS, "Need coordinates to write a %s trajectory", ftp2ext(ftp));
             }
             break;
     }
@@ -394,21 +382,16 @@ int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind,
                 }
             }
             break;
-        default:
-            break;
+        default: break;
     }
 
     switch (ftp)
     {
-        case efTNG:
-            gmx_write_tng_from_trxframe(status->tng, fr, nind);
-            break;
-        case efXTC:
-            write_xtc(status->fio, nind, fr->step, fr->time, fr->box, xout, prec);
-            break;
+        case efTNG: gmx_write_tng_from_trxframe(status->tng, fr, nind); break;
+        case efXTC: write_xtc(status->fio, nind, fr->step, fr->time, fr->box, xout, prec); break;
         case efTRR:
-            gmx_trr_write_frame(status->fio, nframes_read(status),
-                                fr->time, fr->step, fr->box, nind, xout, vout, fout);
+            gmx_trr_write_frame(status->fio, nframes_read(status), fr->time, fr->step, fr->box,
+                                nind, xout, vout, fout);
             break;
         case efGRO:
         case efPDB:
@@ -416,8 +399,7 @@ int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind,
         case efENT:
             if (!fr->bAtoms)
             {
-                gmx_fatal(FARGS, "Can not write a %s file without atom names",
-                          ftp2ext(ftp));
+                gmx_fatal(FARGS, "Can not write a %s file without atom names", ftp2ext(ftp));
             }
             sprintf(title, "frame t= %.3f", fr->time);
             if (ftp == efGRO)
@@ -427,17 +409,15 @@ int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind,
             }
             else
             {
-                write_pdbfile_indexed(gmx_fio_getfp(status->fio), title, fr->atoms,
-                                      fr->x, -1, fr->box, ' ', fr->step, nind, ind, gc, FALSE);
+                write_pdbfile_indexed(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x, -1,
+                                      fr->box, ' ', fr->step, nind, ind, gc, FALSE);
             }
             break;
         case efG96:
             sprintf(title, "frame t= %.3f", fr->time);
             write_g96_conf(gmx_fio_getfp(status->fio), title, fr, nind, ind);
             break;
-        default:
-            gmx_fatal(FARGS, "Sorry, write_trxframe_indexed can not write %s",
-                      ftp2ext(ftp));
+        default: gmx_fatal(FARGS, "Sorry, write_trxframe_indexed can not write %s", ftp2ext(ftp));
     }
 
     switch (ftp)
@@ -454,43 +434,33 @@ int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind,
             }
             sfree(xout);
             break;
-        case efXTC:
-            sfree(xout);
-            break;
-        default:
-            break;
+        case efXTC: sfree(xout); break;
+        default: break;
     }
 
     return 0;
 }
 
-t_trxstatus *
-trjtools_gmx_prepare_tng_writing(const char              *filename,
-                                 char                     filemode,
-                                 t_trxstatus             *in,
-                                 const char              *infile,
-                                 const int                natoms,
-                                 const gmx_mtop_t        *mtop,
-                                 gmx::ArrayRef<const int> index,
-                                 const char              *index_group_name)
+t_trxstatus* trjtools_gmx_prepare_tng_writing(const char*              filename,
+                                              char                     filemode,
+                                              t_trxstatus*             in,
+                                              const char*              infile,
+                                              const int                natoms,
+                                              const gmx_mtop_t*        mtop,
+                                              gmx::ArrayRef<const int> index,
+                                              const char*              index_group_name)
 {
     if (filemode != 'w' && filemode != 'a')
     {
         gmx_incons("Sorry, can only prepare for TNG output.");
     }
-    t_trxstatus *out;
+    t_trxstatusout;
     snew(out, 1);
     status_init(out);
 
     if (in != nullptr)
     {
-        gmx_prepare_tng_writing(filename,
-                                filemode,
-                                &in->tng,
-                                &out->tng,
-                                natoms,
-                                mtop,
-                                index,
+        gmx_prepare_tng_writing(filename, filemode, &in->tng, &out->tng, natoms, mtop, index,
                                 index_group_name);
     }
     else if ((infile) && (efTNG == fn2ftp(infile)))
@@ -498,38 +468,25 @@ trjtools_gmx_prepare_tng_writing(const char              *filename,
         gmx_tng_trajectory_t tng_in;
         gmx_tng_open(infile, 'r', &tng_in);
 
-        gmx_prepare_tng_writing(filename,
-                                filemode,
-                                &tng_in,
-                                &out->tng,
-                                natoms,
-                                mtop,
-                                index,
+        gmx_prepare_tng_writing(filename, filemode, &tng_in, &out->tng, natoms, mtop, index,
                                 index_group_name);
     }
     else
     {
         // we start from a file that is not a tng file or have been unable to load the
         // input file, so we need to populate the fields independently of it
-        gmx_prepare_tng_writing(filename,
-                                filemode,
-                                nullptr,
-                                &out->tng,
-                                natoms,
-                                mtop,
-                                index,
+        gmx_prepare_tng_writing(filename, filemode, nullptr, &out->tng, natoms, mtop, index,
                                 index_group_name);
     }
     return out;
 }
 
-void write_tng_frame(t_trxstatus *status,
-                     t_trxframe  *frame)
+void write_tng_frame(t_trxstatus* status, t_trxframe* frame)
 {
     gmx_write_tng_from_trxframe(status->tng, frame, -1);
 }
 
-int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc)
+int write_trxframe(t_trxstatus* status, t_trxframe* fr, gmx_conect gc)
 {
     char title[STRLEN];
     title[0] = '\0';
@@ -554,8 +511,7 @@ int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc)
 
     switch (gmx_fio_getftp(status->fio))
     {
-        case efTRR:
-            break;
+        case efTRR: break;
         default:
             if (!fr->bX)
             {
@@ -572,7 +528,8 @@ int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc)
             break;
         case efTRR:
             gmx_trr_write_frame(status->fio, fr->step, fr->time, fr->lambda, fr->box, fr->natoms,
-                                fr->bX ? fr->x : nullptr, fr->bV ? fr->v : nullptr, fr->bF ? fr->f : nullptr);
+                                fr->bX ? fr->x : nullptr, fr->bV ? fr->v : nullptr,
+                                fr->bF ? fr->f : nullptr);
             break;
         case efGRO:
         case efPDB:
@@ -586,19 +543,16 @@ int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc)
             sprintf(title, "frame t= %.3f", fr->time);
             if (gmx_fio_getftp(status->fio) == efGRO)
             {
-                write_hconf_p(gmx_fio_getfp(status->fio), title, fr->atoms,
-                              fr->x, fr->bV ? fr->v : nullptr, fr->box);
+                write_hconf_p(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x,
+                              fr->bV ? fr->v : nullptr, fr->box);
             }
             else
             {
-                write_pdbfile(gmx_fio_getfp(status->fio), title,
-                              fr->atoms, fr->x, fr->bPBC ? fr->ePBC : -1, fr->box,
-                              ' ', fr->step, gc);
+                write_pdbfile(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x,
+                              fr->bPBC ? fr->ePBC : -1, fr->box, ' ', fr->step, gc);
             }
             break;
-        case efG96:
-            write_g96_conf(gmx_fio_getfp(status->fio), title, fr, -1, nullptr);
-            break;
+        case efG96: write_g96_conf(gmx_fio_getfp(status->fio), title, fr, -1, nullptr); break;
         default:
             gmx_fatal(FARGS, "Sorry, write_trxframe can not write %s",
                       ftp2ext(gmx_fio_getftp(status->fio)));
@@ -607,9 +561,16 @@ int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc)
     return 0;
 }
 
-int write_trx(t_trxstatus *status, int nind, const int *ind, const t_atoms *atoms,
-              int step, real time, matrix box, rvec x[], rvec *v,
-              gmx_conect gc)
+int write_trx(t_trxstatus*   status,
+              int            nind,
+              const int*     ind,
+              const t_atoms* atoms,
+              int            step,
+              real           time,
+              matrix         box,
+              rvec           x[],
+              rvec*          v,
+              gmx_conect     gc)
 {
     t_trxframe fr;
 
@@ -619,7 +580,7 @@ int write_trx(t_trxstatus *status, int nind, const int *ind, const t_atoms *atom
     fr.bTime  = TRUE;
     fr.time   = time;
     fr.bAtoms = atoms != nullptr;
-    fr.atoms  = const_cast<t_atoms *>(atoms);
+    fr.atoms  = const_cast<t_atoms*>(atoms);
     fr.bX     = TRUE;
     fr.x      = x;
     fr.bV     = v != nullptr;
@@ -630,7 +591,7 @@ int write_trx(t_trxstatus *status, int nind, const int *ind, const t_atoms *atom
     return write_trxframe_indexed(status, &fr, nind, ind, gc);
 }
 
-void close_trx(t_trxstatus *status)
+void close_trx(t_trxstatusstatus)
 {
     if (status == nullptr)
     {
@@ -652,9 +613,9 @@ void close_trx(t_trxstatus *status)
     sfree(status);
 }
 
-t_trxstatus *open_trx(const char *outfile, const char *filemode)
+t_trxstatus* open_trx(const char* outfile, const char* filemode)
 {
-    t_trxstatus *stat;
+    t_trxstatusstat;
     if (filemode[0] != 'w' && filemode[0] != 'a' && filemode[1] != '+')
     {
         gmx_fatal(FARGS, "Sorry, write_trx can only write");
@@ -667,7 +628,7 @@ t_trxstatus *open_trx(const char *outfile, const char *filemode)
     return stat;
 }
 
-static gmx_bool gmx_next_frame(t_trxstatus *status, t_trxframe *fr)
+static gmx_bool gmx_next_frame(t_trxstatus* status, t_trxframe* fr)
 {
     gmx_trr_header_t sh;
     gmx_bool         bOK, bRet;
@@ -727,17 +688,17 @@ static gmx_bool gmx_next_frame(t_trxstatus *status, t_trxframe *fr)
     return bRet;
 }
 
-static gmx_bool pdb_next_x(t_trxstatus *status, FILE *fp, t_trxframe *fr)
+static gmx_bool pdb_next_x(t_trxstatus* status, FILE* fp, t_trxframe* fr)
 {
     t_atoms   atoms;
-    t_symtab *symtab;
+    t_symtabsymtab;
     matrix    boxpdb;
     // Initiate model_nr to -1 rather than NOTSET.
     // It is not worthwhile introducing extra variables in the
     // read_pdbfile call to verify that a model_nr was read.
-    int       ePBC, model_nr = -1, na;
-    char      title[STRLEN], *time, *step;
-    double    dbl;
+    int    ePBC, model_nr = -1, na;
+    char   title[STRLEN], *time, *step;
+    double dbl;
 
     atoms.nr      = fr->natoms;
     atoms.atom    = nullptr;
@@ -745,7 +706,7 @@ static gmx_bool pdb_next_x(t_trxstatus *status, FILE *fp, t_trxframe *fr)
     /* the other pointers in atoms should not be accessed if these are NULL */
     snew(symtab, 1);
     open_symtab(symtab);
-    na       = read_pdbfile(fp, title, &model_nr, &atoms, symtab, fr->x, &ePBC, boxpdb, TRUE, nullptr);
+    na = read_pdbfile(fp, title, &model_nr, &atoms, symtab, fr->x, &ePBC, boxpdb, TRUE, nullptr);
     free_symtab(symtab);
     sfree(symtab);
     set_trxframe_ePBC(fr, ePBC);
@@ -764,11 +725,11 @@ static gmx_bool pdb_next_x(t_trxstatus *status, FILE *fp, t_trxframe *fr)
 
     fr->step  = 0;
     step      = std::strstr(title, " step= ");
-    fr->bStep = ((step != nullptr) && sscanf(step+7, "%" SCNd64, &fr->step) == 1);
+    fr->bStep = ((step != nullptr) && sscanf(step + 7, "%" SCNd64, &fr->step) == 1);
 
     dbl       = 0.0;
     time      = std::strstr(title, " t= ");
-    fr->bTime = ((time != nullptr) && sscanf(time+4, "%lf", &dbl) == 1);
+    fr->bTime = ((time != nullptr) && sscanf(time + 4, "%lf", &dbl) == 1);
     fr->time  = dbl;
 
     if (na == 0)
@@ -786,7 +747,7 @@ static gmx_bool pdb_next_x(t_trxstatus *status, FILE *fp, t_trxframe *fr)
     }
 }
 
-static int pdb_first_x(t_trxstatus *status, FILE *fp, t_trxframe *fr)
+static int pdb_first_x(t_trxstatus* status, FILE* fp, t_trxframe* fr)
 {
     initcount(status);
 
@@ -804,7 +765,7 @@ static int pdb_first_x(t_trxstatus *status, FILE *fp, t_trxframe *fr)
     return fr->natoms;
 }
 
-bool read_next_frame(const gmx_output_env_t *oenv, t_trxstatus *status, t_trxframe *fr)
+bool read_next_frame(const gmx_output_env_t* oenv, t_trxstatus* status, t_trxframe* fr)
 {
     real     pt;
     int      ct;
@@ -812,7 +773,7 @@ bool read_next_frame(const gmx_output_env_t *oenv, t_trxstatus *status, t_trxfra
     bool     bRet = false;
     int      ftp;
 
-    pt   = status->tf;
+    pt = status->tf;
 
     do
     {
@@ -829,17 +790,15 @@ bool read_next_frame(const gmx_output_env_t *oenv, t_trxstatus *status, t_trxfra
         }
         switch (ftp)
         {
-            case efTRR:
-                bRet = gmx_next_frame(status, fr);
-                break;
+            case efTRR: bRet = gmx_next_frame(status, fr); break;
             case efCPT:
                 /* Checkpoint files can not contain mulitple frames */
                 break;
             case efG96:
             {
-                t_symtab *symtab = nullptr;
-                read_g96_conf(gmx_fio_getfp(status->fio), nullptr, nullptr, fr,
-                              symtab, status->persistent_line);
+                t_symtabsymtab = nullptr;
+                read_g96_conf(gmx_fio_getfp(status->fio), nullptr, nullptr, fr, symtab,
+                              status->persistent_line);
                 bRet = (fr->natoms > 0);
                 break;
             }
@@ -848,13 +807,16 @@ bool read_next_frame(const gmx_output_env_t *oenv, t_trxstatus *status, t_trxfra
                 {
                     if (xtc_seek_time(status->fio, rTimeValue(TBEGIN), fr->natoms, TRUE))
                     {
-                        gmx_fatal(FARGS, "Specified frame (time %f) doesn't exist or file corrupt/inconsistent.",
+                        gmx_fatal(FARGS,
+                                  "Specified frame (time %f) doesn't exist or file "
+                                  "corrupt/inconsistent.",
                                   rTimeValue(TBEGIN));
                     }
                     initcount(status);
                 }
-                bRet = (read_next_xtc(status->fio, fr->natoms, &fr->step, &fr->time, fr->box,
-                                      fr->x, &fr->prec, &bOK) != 0);
+                bRet = (read_next_xtc(status->fio, fr->natoms, &fr->step, &fr->time, fr->box, fr->x,
+                                      &fr->prec, &bOK)
+                        != 0);
                 fr->bPrec = (bRet && fr->prec > 0);
                 fr->bStep = bRet;
                 fr->bTime = bRet;
@@ -867,32 +829,25 @@ bool read_next_frame(const gmx_output_env_t *oenv, t_trxstatus *status, t_trxfra
                     fr->not_ok = DATA_NOT_OK;
                 }
                 break;
-            case efTNG:
-                bRet = gmx_read_next_tng_frame(status->tng, fr, nullptr, 0);
-                break;
-            case efPDB:
-                bRet = pdb_next_x(status, gmx_fio_getfp(status->fio), fr);
-                break;
-            case efGRO:
-                bRet = gro_next_x_or_v(gmx_fio_getfp(status->fio), fr);
-                break;
+            case efTNG: bRet = gmx_read_next_tng_frame(status->tng, fr, nullptr, 0); break;
+            case efPDB: bRet = pdb_next_x(status, gmx_fio_getfp(status->fio), fr); break;
+            case efGRO: bRet = gro_next_x_or_v(gmx_fio_getfp(status->fio), fr); break;
             default:
 #if GMX_USE_PLUGINS
                 bRet = read_next_vmd_frame(status->vmdplugin, fr);
 #else
                 gmx_fatal(FARGS, "DEATH HORROR in read_next_frame ftp=%s,status=%s",
-                          ftp2ext(gmx_fio_getftp(status->fio)),
-                          gmx_fio_getname(status->fio));
+                          ftp2ext(gmx_fio_getftp(status->fio)), gmx_fio_getname(status->fio));
 #endif
         }
         status->tf = fr->time;
 
         if (bRet)
         {
-            bMissingData = ((((status->flags & TRX_NEED_X) != 0) && !fr->bX) ||
-                            (((status->flags & TRX_NEED_V) != 0) && !fr->bV) ||
-                            (((status->flags & TRX_NEED_F) != 0) && !fr->bF));
-            bSkip = FALSE;
+            bMissingData = ((((status->flags & TRX_NEED_X) != 0) && !fr->bX)
+                            || (((status->flags & TRX_NEED_V) != 0) && !fr->bV)
+                            || (((status->flags & TRX_NEED_F) != 0) && !fr->bF));
+            bSkip        = FALSE;
             if (!bMissingData)
             {
                 ct = check_times2(fr->time, status->t0, fr->bDouble);
@@ -912,8 +867,7 @@ bool read_next_frame(const gmx_output_env_t *oenv, t_trxstatus *status, t_trxfra
             }
         }
 
-    }
-    while (bRet && (bMissingData || bSkip));
+    } while (bRet && (bMissingData || bSkip));
 
     if (!bRet)
     {
@@ -927,12 +881,11 @@ bool read_next_frame(const gmx_output_env_t *oenv, t_trxstatus *status, t_trxfra
     return bRet;
 }
 
-bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
-                      const char *fn, t_trxframe *fr, int flags)
+bool read_first_frame(const gmx_output_env_t* oenv, t_trxstatus** status, const char* fn, t_trxframe* fr, int flags)
 {
-    t_fileio      *fio = nullptr;
-    gmx_bool       bFirst, bOK;
-    int            ftp   = fn2ftp(fn);
+    t_fileiofio = nullptr;
+    gmx_bool  bFirst, bOK;
+    int       ftp = fn2ftp(fn);
 
     clear_trxframe(fr, TRUE);
 
@@ -940,7 +893,7 @@ bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
 
     snew((*status), 1);
 
-    status_init( *status );
+    status_init(*status);
     initcount(*status);
     (*status)->flags = flags;
 
@@ -955,8 +908,7 @@ bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
     }
     switch (ftp)
     {
-        case efTRR:
-            break;
+        case efTRR: break;
         case efCPT:
             read_checkpoint_trxframe(fio, fr);
             bFirst = FALSE;
@@ -967,9 +919,9 @@ bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
             if (!(*status)->persistent_line)
             {
                 /* allocate the persistent line */
-                snew((*status)->persistent_line, STRLEN+1);
+                snew((*status)->persistent_line, STRLEN + 1);
             }
-            t_symtab *symtab = nullptr;
+            t_symtabsymtab = nullptr;
             read_g96_conf(gmx_fio_getfp(fio), fn, nullptr, fr, symtab, (*status)->persistent_line);
             gmx_fio_close(fio);
             clear_trxframe(fr, FALSE);
@@ -985,10 +937,11 @@ bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
             break;
         }
         case efXTC:
-            if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x,
-                               &fr->prec, &bOK) == 0)
+            if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x, &fr->prec, &bOK) == 0)
             {
-                GMX_RELEASE_ASSERT(!bOK, "Inconsistent results - OK status from read_first_xtc, but 0 atom coords read");
+                GMX_RELEASE_ASSERT(!bOK,
+                                   "Inconsistent results - OK status from read_first_xtc, but 0 "
+                                   "atom coords read");
                 fr->not_ok = DATA_NOT_OK;
             }
             if (fr->not_ok)
@@ -1038,19 +991,28 @@ bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
             break;
         default:
 #if GMX_USE_PLUGINS
-            fprintf(stderr, "The file format of %s is not a known trajectory format to GROMACS.\n"
+            fprintf(stderr,
+                    "The file format of %s is not a known trajectory format to GROMACS.\n"
                     "Please make sure that the file is a trajectory!\n"
-                    "GROMACS will now assume it to be a trajectory and will try to open it using the VMD plug-ins.\n"
-                    "This will only work in case the VMD plugins are found and it is a trajectory format supported by VMD.\n", fn);
+                    "GROMACS will now assume it to be a trajectory and will try to open it using "
+                    "the VMD plug-ins.\n"
+                    "This will only work in case the VMD plugins are found and it is a trajectory "
+                    "format supported by VMD.\n",
+                    fn);
             gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/
             if (!read_first_vmd_frame(fn, &(*status)->vmdplugin, fr))
             {
                 gmx_fatal(FARGS, "Not supported in read_first_frame: %s", fn);
             }
 #else
-            gmx_fatal(FARGS, "Not supported in read_first_frame: %s. Please make sure that the file is a trajectory.\n"
-                      "GROMACS is not compiled with plug-in support. Thus it cannot read non-GROMACS trajectory formats using the VMD plug-ins.\n"
-                      "Please compile with plug-in support if you want to read non-GROMACS trajectory formats.\n", fn);
+            gmx_fatal(FARGS,
+                      "Not supported in read_first_frame: %s. Please make sure that the file is a "
+                      "trajectory.\n"
+                      "GROMACS is not compiled with plug-in support. Thus it cannot read "
+                      "non-GROMACS trajectory formats using the VMD plug-ins.\n"
+                      "Please compile with plug-in support if you want to read non-GROMACS "
+                      "trajectory formats.\n",
+                      fn);
 #endif
     }
     (*status)->tf = fr->time;
@@ -1062,8 +1024,7 @@ bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
         return FALSE;
     }
 
-    if (bFirst ||
-        (!(flags & TRX_DONT_SKIP) && check_times(fr->time) < 0))
+    if (bFirst || (!(flags & TRX_DONT_SKIP) && check_times(fr->time) < 0))
     {
         /* Read a frame when no frame was read or the first was skipped */
         if (!read_next_frame(oenv, *status, fr))
@@ -1083,8 +1044,7 @@ bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
 
 /***** C O O R D I N A T E   S T U F F *****/
 
-int read_first_x(const gmx_output_env_t *oenv, t_trxstatus **status, const char *fn,
-                 real *t, rvec **x, matrix box)
+int read_first_x(const gmx_output_env_t* oenv, t_trxstatus** status, const char* fn, real* t, rvec** x, matrix box)
 {
     t_trxframe fr;
 
@@ -1099,8 +1059,7 @@ int read_first_x(const gmx_output_env_t *oenv, t_trxstatus **status, const char
     return (*status)->xframe->natoms;
 }
 
-gmx_bool read_next_x(const gmx_output_env_t *oenv, t_trxstatus *status, real *t,
-                     rvec x[], matrix box)
+gmx_bool read_next_x(const gmx_output_env_t* oenv, t_trxstatus* status, real* t, rvec x[], matrix box)
 {
     gmx_bool bRet;
 
@@ -1113,7 +1072,7 @@ gmx_bool read_next_x(const gmx_output_env_t *oenv, t_trxstatus *status, real *t,
     return bRet;
 }
 
-void rewind_trj(t_trxstatus *status)
+void rewind_trj(t_trxstatusstatus)
 {
     initcount(status);
 
@@ -1122,10 +1081,10 @@ void rewind_trj(t_trxstatus *status)
 
 /***** T O P O L O G Y   S T U F F ******/
 
-t_topology *read_top(const char *fn, int *ePBC)
+t_topology* read_top(const char* fn, int* ePBC)
 {
     int         epbc, natoms;
-    t_topology *top;
+    t_topologytop;
 
     snew(top, 1);
     epbc = read_tpx_top(fn, nullptr, nullptr, &natoms, nullptr, nullptr, top);