Merge branch release-2016
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_trjconv.cpp
index 0b9173470599d79cc61f89270d3cc031d777d69f..92c192830d97015a21247d12f83dc094dca83748 100644 (file)
@@ -49,7 +49,7 @@
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/groio.h"
 #include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/tngio_for_tools.h"
+#include "gromacs/fileio/tngio.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trrio.h"
 #include "gromacs/fileio/trxio.h"
@@ -492,7 +492,7 @@ void do_trunc(const char *fn, real t0)
 
     in   = gmx_trr_open(fn, "r");
     fp   = gmx_fio_getfp(in);
-    if (fp == NULL)
+    if (fp == nullptr)
     {
         fprintf(stderr, "Sorry, can not trunc %s, truncation of this filetype is not supported\n", fn);
         gmx_trr_close(in);
@@ -504,7 +504,7 @@ void do_trunc(const char *fn, real t0)
         bStop = FALSE;
         while (!bStop && gmx_trr_read_frame_header(in, &sh, &bOK))
         {
-            gmx_trr_read_frame_data(in, &sh, NULL, NULL, NULL, NULL);
+            gmx_trr_read_frame_data(in, &sh, nullptr, nullptr, nullptr, nullptr);
             fpos = gmx_ftell(fp);
             t    = sh.t;
             if (t >= t0)
@@ -568,7 +568,7 @@ static gmx_mtop_t *read_mtop_for_tng(const char *tps_file,
                                      const char *input_file,
                                      const char *output_file)
 {
-    gmx_mtop_t *mtop = NULL;
+    gmx_mtop_t *mtop = nullptr;
 
     if (fn2bTPX(tps_file) &&
         efTNG != fn2ftp(input_file) &&
@@ -576,8 +576,8 @@ static gmx_mtop_t *read_mtop_for_tng(const char *tps_file,
     {
         int temp_natoms = -1;
         snew(mtop, 1);
-        read_tpx(tps_file, NULL, NULL, &temp_natoms,
-                 NULL, NULL, mtop);
+        read_tpx(tps_file, nullptr, nullptr, &temp_natoms,
+                 nullptr, nullptr, mtop);
     }
 
     return mtop;
@@ -738,20 +738,20 @@ int gmx_trjconv(int argc, char *argv[])
     };
     const char *pbc_opt[epNR + 1] =
     {
-        NULL, "none", "mol", "res", "atom", "nojump", "cluster", "whole",
-        NULL
+        nullptr, "none", "mol", "res", "atom", "nojump", "cluster", "whole",
+        nullptr
     };
 
     int         unitcell_enum;
     const char *unitcell_opt[euNR+1] =
-    { NULL, "rect", "tric", "compact", NULL };
+    { nullptr, "rect", "tric", "compact", nullptr };
 
     enum
     {
         ecSel, ecTric, ecRect, ecZero, ecNR
     };
     const char *center_opt[ecNR+1] =
-    { NULL, "tric", "rect", "zero", NULL };
+    { nullptr, "tric", "rect", "zero", nullptr };
     int         ecenter;
 
     int         fit_enum;
@@ -761,8 +761,8 @@ int gmx_trjconv(int argc, char *argv[])
     };
     const char *fit[efNR + 1] =
     {
-        NULL, "none", "rot+trans", "rotxy+transxy", "translation", "transxy",
-        "progressive", NULL
+        nullptr, "none", "rot+trans", "rotxy+transxy", "translation", "transxy",
+        "progressive", nullptr
     };
 
     static gmx_bool  bSeparate     = FALSE, bVels = TRUE, bForce = FALSE, bCONECT = FALSE;
@@ -770,7 +770,7 @@ int gmx_trjconv(int argc, char *argv[])
     static int       skip_nr       = 1, ndec = 3, nzero = 0;
     static real      tzero         = 0, delta_t = 0, timestep = 0, ttrunc = -1, tdump = -1, split_t = 0;
     static rvec      newbox        = {0, 0, 0}, shift = {0, 0, 0}, trans = {0, 0, 0};
-    static char     *exec_command  = NULL;
+    static char     *exec_command  = nullptr;
     static real      dropunder     = 0, dropover = 0;
     static gmx_bool  bRound        = FALSE;
 
@@ -854,22 +854,22 @@ int gmx_trjconv(int argc, char *argv[])
     };
 #define NPA asize(pa)
 
-    FILE             *out    = NULL;
-    t_trxstatus      *trxout = NULL;
+    FILE             *out    = nullptr;
+    t_trxstatus      *trxout = nullptr;
     t_trxstatus      *trxin;
     int               file_nr;
     t_trxframe        fr, frout;
     int               flags;
-    rvec             *xmem  = NULL, *vmem = NULL, *fmem = NULL;
-    rvec             *xp    = NULL, x_shift, hbox;
-    real             *w_rls = NULL;
+    rvec             *xmem  = nullptr, *vmem = nullptr, *fmem = nullptr;
+    rvec             *xp    = nullptr, x_shift, hbox;
+    real             *w_rls = nullptr;
     int               m, i, d, frame, outframe, natoms, nout, ncent, newstep = 0, model_nr;
 #define SKIP 10
     t_topology        top;
-    gmx_mtop_t       *mtop  = NULL;
-    gmx_conect        gc    = NULL;
+    gmx_mtop_t       *mtop  = nullptr;
+    gmx_conect        gc    = nullptr;
     int               ePBC  = -1;
-    t_atoms          *atoms = NULL, useatoms;
+    t_atoms          *atoms = nullptr, useatoms;
     matrix            top_box;
     int              *index, *cindex;
     char             *grpnm;
@@ -878,35 +878,35 @@ int gmx_trjconv(int argc, char *argv[])
     int               ifit, my_clust = -1;
     int              *ind_fit;
     char             *gn_fit;
-    t_cluster_ndx    *clust           = NULL;
-    t_trxstatus     **clust_status    = NULL;
-    int              *clust_status_id = NULL;
+    t_cluster_ndx    *clust           = nullptr;
+    t_trxstatus     **clust_status    = nullptr;
+    int              *clust_status_id = nullptr;
     int               ntrxopen        = 0;
-    int              *nfwritten       = NULL;
+    int              *nfwritten       = nullptr;
     int               ndrop           = 0, ncol, drop0 = 0, drop1 = 0, dropuse = 0;
     double          **dropval;
     real              tshift = 0, t0 = -1, dt = 0.001, prec;
     gmx_bool          bFit, bPFit, bReset;
     int               nfitdim;
-    gmx_rmpbc_t       gpbc = NULL;
+    gmx_rmpbc_t       gpbc = nullptr;
     gmx_bool          bRmPBC, bPBCWhole, bPBCcomRes, bPBCcomMol, bPBCcomAtom, bPBC, bNoJump, bCluster;
     gmx_bool          bCopy, bDoIt, bIndex, bTDump, bSetTime, bTPS = FALSE, bDTset = FALSE;
     gmx_bool          bExec, bTimeStep = FALSE, bDumpFrame = FALSE, bSetPrec, bNeedPrec;
     gmx_bool          bHaveFirstFrame, bHaveNextFrame, bSetBox, bSetUR, bSplit = FALSE;
     gmx_bool          bSubTraj = FALSE, bDropUnder = FALSE, bDropOver = FALSE, bTrans = FALSE;
     gmx_bool          bWriteFrame, bSplitHere;
-    const char       *top_file, *in_file, *out_file = NULL;
+    const char       *top_file, *in_file, *out_file = nullptr;
     char              out_file2[256], *charpt;
-    char             *outf_base = NULL;
-    const char       *outf_ext  = NULL;
+    char             *outf_base = nullptr;
+    const char       *outf_ext  = nullptr;
     char              top_title[256], title[256], filemode[5];
     gmx_output_env_t *oenv;
 
     t_filenm          fnm[] = {
-        { efTRX, "-f",   NULL,      ffREAD  },
-        { efTRO, "-o",   NULL,      ffWRITE },
-        { efTPS, NULL,   NULL,      ffOPTRD },
-        { efNDX, NULL,   NULL,      ffOPTRD },
+        { efTRX, "-f",   nullptr,      ffREAD  },
+        { efTRO, "-o",   nullptr,      ffWRITE },
+        { efTPS, nullptr,   nullptr,      ffOPTRD },
+        { efNDX, nullptr,   nullptr,      ffOPTRD },
         { efNDX, "-fr",  "frames",  ffOPTRD },
         { efNDX, "-sub", "cluster", ffOPTRD },
         { efXVG, "-drop", "drop",    ffOPTRD }
@@ -917,7 +917,7 @@ int gmx_trjconv(int argc, char *argv[])
                            PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_VIEW |
                            PCA_TIME_UNIT,
                            NFILE, fnm, NPA, pa, asize(desc), desc,
-                           0, NULL, &oenv))
+                           0, nullptr, &oenv))
     {
         return 0;
     }
@@ -1026,7 +1026,7 @@ int gmx_trjconv(int argc, char *argv[])
         if (bSeparate || bSplit)
         {
             outf_ext = std::strrchr(out_file, '.');
-            if (outf_ext == NULL)
+            if (outf_ext == nullptr)
             {
                 gmx_fatal(FARGS, "Output file name '%s' does not contain a '.'", out_file);
             }
@@ -1044,7 +1044,7 @@ int gmx_trjconv(int argc, char *argv[])
                 gmx_fatal(FARGS, "Can only use the sub option with output file types "
                           "xtc and trr");
             }
-            clust = cluster_index(NULL, opt2fn("-sub", NFILE, fnm));
+            clust = cluster_index(nullptr, opt2fn("-sub", NFILE, fnm));
 
             /* Check for number of files disabled, as FOPEN_MAX is not the correct
              * number to check for. In my linux box it is only 16.
@@ -1067,7 +1067,7 @@ int gmx_trjconv(int argc, char *argv[])
             snew(nfwritten, clust->clust->nr);
             for (i = 0; (i < clust->clust->nr); i++)
             {
-                clust_status[i]    = NULL;
+                clust_status[i]    = nullptr;
                 clust_status_id[i] = -1;
             }
             bSeparate = bSplit = FALSE;
@@ -1089,7 +1089,7 @@ int gmx_trjconv(int argc, char *argv[])
 
         if (bTPS)
         {
-            read_tps_conf(top_file, &top, &ePBC, &xp, NULL, top_box,
+            read_tps_conf(top_file, &top, &ePBC, &xp, nullptr, top_box,
                           bReset || bPBCcomRes);
             std::strncpy(top_title, *top.name, 255);
             top_title[255] = '\0';
@@ -1120,7 +1120,7 @@ int gmx_trjconv(int argc, char *argv[])
         }
 
         /* get frame number index */
-        frindex = NULL;
+        frindex = nullptr;
         if (opt2bSet("-fr", NFILE, fnm))
         {
             printf("Select groups of frame number indices:\n");
@@ -1211,7 +1211,7 @@ int gmx_trjconv(int argc, char *argv[])
                 gmx_rmpbc(gpbc, top.atoms.nr, top_box, xp);
             }
             copy_rvec(xp[index[0]], x_shift);
-            reset_x_ndim(nfitdim, ifit, ind_fit, atoms->nr, NULL, xp, w_rls);
+            reset_x_ndim(nfitdim, ifit, ind_fit, atoms->nr, nullptr, xp, w_rls);
             rvec_dec(x_shift, xp[index[0]]);
         }
         else
@@ -1240,14 +1240,14 @@ int gmx_trjconv(int argc, char *argv[])
             /* get memory for stuff to go in .pdb file, and initialize
              * the pdbinfo structure part if the input has it.
              */
-            init_t_atoms(&useatoms, atoms->nr, (atoms->pdbinfo != NULL));
+            init_t_atoms(&useatoms, atoms->nr, atoms->havePdbInfo);
             sfree(useatoms.resinfo);
             useatoms.resinfo = atoms->resinfo;
             for (i = 0; (i < nout); i++)
             {
                 useatoms.atomname[i] = atoms->atomname[index[i]];
                 useatoms.atom[i]     = atoms->atom[index[i]];
-                if (atoms->pdbinfo != NULL)
+                if (atoms->havePdbInfo)
                 {
                     useatoms.pdbinfo[i]  = atoms->pdbinfo[index[i]];
                 }
@@ -1332,7 +1332,7 @@ int gmx_trjconv(int argc, char *argv[])
                                                      filemode[0],
                                                      trxin,
                                                      &trxout,
-                                                     NULL,
+                                                     nullptr,
                                                      nout,
                                                      mtop,
                                                      index,
@@ -1340,7 +1340,7 @@ int gmx_trjconv(int argc, char *argv[])
                     break;
                 case efXTC:
                 case efTRR:
-                    out = NULL;
+                    out = nullptr;
                     if (!bSplit && !bSubTraj)
                     {
                         trxout = open_trx(out_file, filemode);
@@ -1510,14 +1510,14 @@ int gmx_trjconv(int argc, char *argv[])
                         gmx_rmpbc_trxfr(gpbc, &fr);
                     }
 
-                    reset_x_ndim(nfitdim, ifit, ind_fit, natoms, NULL, fr.x, w_rls);
+                    reset_x_ndim(nfitdim, ifit, ind_fit, natoms, nullptr, fr.x, w_rls);
                     do_fit(natoms, w_rls, xp, fr.x);
                 }
 
                 /* store this set of coordinates for future use */
                 if (bPFit || bNoJump)
                 {
-                    if (xp == NULL)
+                    if (xp == nullptr)
                     {
                         snew(xp, natoms);
                     }
@@ -1632,7 +1632,7 @@ int gmx_trjconv(int argc, char *argv[])
 
                             if (bReset)
                             {
-                                reset_x_ndim(nfitdim, ifit, ind_fit, natoms, NULL, fr.x, w_rls);
+                                reset_x_ndim(nfitdim, ifit, ind_fit, natoms, nullptr, fr.x, w_rls);
                                 if (bFit)
                                 {
                                     do_fit_ndim(nfitdim, natoms, w_rls, xp, fr.x);
@@ -1783,7 +1783,7 @@ int gmx_trjconv(int argc, char *argv[])
                                              clust->clust->index[my_clust]))
                                         {
                                             close_trx(clust_status[my_clust]);
-                                            clust_status[my_clust]    = NULL;
+                                            clust_status[my_clust]    = nullptr;
                                             clust_status_id[my_clust] = -2;
                                             ntrxopen--;
                                             if (ntrxopen < 0)
@@ -1811,7 +1811,7 @@ int gmx_trjconv(int argc, char *argv[])
                                 {
                                     case efGRO:
                                         write_hconf_p(out, title, &useatoms,
-                                                      frout.x, frout.bV ? frout.v : NULL, frout.box);
+                                                      frout.x, frout.bV ? frout.v : nullptr, frout.box);
                                         break;
                                     case efPDB:
                                         fprintf(out, "REMARK    GENERATED BY TRJCONV\n");
@@ -1850,12 +1850,12 @@ int gmx_trjconv(int argc, char *argv[])
                                             frout.bStep  = TRUE;
                                             frout.bTime  = TRUE;
                                         }
-                                        write_g96_conf(out, &frout, -1, NULL);
+                                        write_g96_conf(out, &frout, -1, nullptr);
                                 }
                                 if (bSeparate || bSplitHere)
                                 {
                                     gmx_ffclose(out);
-                                    out = NULL;
+                                    out = nullptr;
                                 }
                                 break;
                             default:
@@ -1905,7 +1905,7 @@ int gmx_trjconv(int argc, char *argv[])
         {
             close_trx(trxout);
         }
-        else if (out != NULL)
+        else if (out != nullptr)
         {
             gmx_ffclose(out);
         }
@@ -1923,7 +1923,7 @@ int gmx_trjconv(int argc, char *argv[])
 
     sfree(mtop);
 
-    do_view(oenv, out_file, NULL);
+    do_view(oenv, out_file, nullptr);
 
     return 0;
 }