Remove dependency on TNG in trxio.h
authorRoland Schulz <roland@utk.edu>
Wed, 5 Mar 2014 07:34:17 +0000 (02:34 -0500)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 5 Mar 2014 17:39:11 +0000 (18:39 +0100)
Partial fix for #1452

Change-Id: I59474ea08d40362fa9d10745a5fb1d4e12254b68

src/gromacs/fileio/trxio.c
src/gromacs/fileio/trxio.h
src/gromacs/gmxana/gmx_trjcat.c

index f87eea267c312ffdc74b9931952edec7ee036e1c..52125a634baa2efe5bba9b2ce3ea843a1d030be4 100644 (file)
@@ -65,6 +65,7 @@
 #include "pdbio.h"
 #include "confio.h"
 #include "checkpoint.h"
+#include "xdrf.h"
 
 #include "gromacs/fileio/timecontrol.h"
 
@@ -228,9 +229,38 @@ t_fileio *trx_get_fileio(t_trxstatus *status)
     return status->fio;
 }
 
-tng_trajectory_t trx_get_tng(t_trxstatus *status)
+float trx_get_time_of_final_frame(t_trxstatus *status)
 {
-    return status->tng;
+    t_fileio *stfio    = trx_get_fileio(status);
+    int       filetype = gmx_fio_getftp(stfio);
+    int       bOK;
+    float     lasttime = -1;
+
+    if (filetype == efXTC)
+    {
+        lasttime =
+            xdr_xtc_get_last_frame_time(gmx_fio_getfp(stfio),
+                                        gmx_fio_getxdr(stfio),
+                                        status->xframe->natoms, &bOK);
+        if (!bOK)
+        {
+            gmx_fatal(FARGS, "Error reading last frame. Maybe seek not supported." );
+        }
+    }
+    else if (filetype == efTNG)
+    {
+        tng_trajectory_t tng = status->tng;
+        if (!tng)
+        {
+            gmx_fatal(FARGS, "Error opening TNG file.");
+        }
+        lasttime = gmx_tng_get_time_of_final_frame(tng);
+    }
+    else
+    {
+        gmx_incons("Only supported for TNG and XTC");
+    }
+    return lasttime;
 }
 
 void clear_trxframe(t_trxframe *fr, gmx_bool bFirst)
index 28cc436aef2aba7821549dfd307da7927e706fc7..d3b64a91c87fe2af217e8e3d15c95f0c37b6e146 100644 (file)
@@ -2,8 +2,8 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, 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.
@@ -44,7 +44,6 @@
 #include "pdbio.h"
 #include "../legacyheaders/oenv.h"
 #include "gmxfio.h"
-#include "../../external/tng_io/include/tng_io_fwd.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -144,8 +143,8 @@ t_trxstatus *open_trx(const char *outfile, const char *filemode);
 t_fileio *trx_get_fileio(t_trxstatus *status);
 /* get a fileio from a trxstatus */
 
-tng_trajectory_t trx_get_tng(t_trxstatus *status);
-/* get a tng trajectory container from a trxstatus */
+float trx_get_time_of_final_frame(t_trxstatus *status);
+/* get time of final frame. Only supported for TNG and XTC */
 
 gmx_bool bRmod_fd(double a, double b, double c, gmx_bool bDouble);
 /* Returns TRUE when (a - b) MOD c = 0, using a margin which is slightly
index 2f74331ffe32fa35eb58139d35ac0e7a37b939f9..20bee799490bb72081c8b17bfe84c727d6c0452c 100644 (file)
@@ -62,7 +62,6 @@
 #include "rmpbc.h"
 #include "pbc.h"
 #include "xvgr.h"
-#include "gromacs/fileio/xdrf.h"
 #include "gmx_ana.h"
 
 #define TIME_EXPLICIT 0
@@ -689,26 +688,9 @@ int gmx_trjcat(int argc, char *argv[])
                 /* Fails if last frame is incomplete
                  * We can't do anything about it without overwriting
                  * */
-                if (filetype == efXTC)
+                if (filetype == efXTC || filetype == efTNG)
                 {
-                    lasttime =
-                        xdr_xtc_get_last_frame_time(gmx_fio_getfp(stfio),
-                                                    gmx_fio_getxdr(stfio),
-                                                    fr.natoms, &bOK);
-                    fr.time = lasttime;
-                    if (!bOK)
-                    {
-                        gmx_fatal(FARGS, "Error reading last frame. Maybe seek not supported." );
-                    }
-                }
-                else if (filetype == efTNG)
-                {
-                    tng_trajectory_t tng = trx_get_tng(status);
-                    if (!tng)
-                    {
-                        gmx_fatal(FARGS, "Error opening TNG file.");
-                    }
-                    lasttime = gmx_tng_get_time_of_final_frame(tng);
+                    lasttime = trx_get_time_of_final_frame(status);
                     fr.time  = lasttime;
                 }
                 else
@@ -729,14 +711,8 @@ int gmx_trjcat(int argc, char *argv[])
                 {
                     gmx_fatal(FARGS, "Overwrite only supported for XTC." );
                 }
-                last_frame_time =
-                    xdr_xtc_get_last_frame_time(gmx_fio_getfp(stfio),
-                                                gmx_fio_getxdr(stfio),
-                                                fr.natoms, &bOK);
-                if (!bOK)
-                {
-                    gmx_fatal(FARGS, "Error reading last frame. Maybe seek not supported." );
-                }
+                last_frame_time = trx_get_time_of_final_frame(status);
+
                 /* xtc_seek_time broken for trajectories containing only 1 or 2 frames
                  *     or when seek time = 0 */
                 if (nfile_in > 1 && settime[1] < last_frame_time+timest[0]*0.5)