Manually sort some includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / fileio / tngio_for_tools.cpp
index 9784f890dc51eb490beb8d86e9dc26c197be573d..cdc1263badc34a153dd42962508eb19d2150c77f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * 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.
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
+#include "gmxpre.h"
+
 #include "tngio_for_tools.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include <math.h>
 
-#include "tngio.h"
-#include "trx.h"
+#include "config.h"
 
 #ifdef GMX_USE_TNG
-#include "../../external/tng_io/include/tng_io.h"
+#include "tng/tng_io.h"
 #endif
 
+#include "gromacs/fileio/tngio.h"
+#include "gromacs/fileio/trx.h"
+#include "gromacs/math/units.h"
 #include "gromacs/utility/common.h"
-#include "gromacs/legacyheaders/types/atoms.h"
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/physics.h"
-#include "gromacs/legacyheaders/gmx_fatal.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
 
 void gmx_prepare_tng_writing(const char              *filename,
                              char                     mode,
@@ -75,6 +75,18 @@ void gmx_prepare_tng_writing(const char              *filename,
         "FORCES", "LAMBDAS"
     };
 
+    typedef tng_function_status (*set_writing_interval_func_pointer)(tng_trajectory_t,
+                                                                     const gmx_int64_t,
+                                                                     const gmx_int64_t,
+                                                                     const gmx_int64_t,
+                                                                     const char*,
+                                                                     const char,
+                                                                     const char);
+#ifdef GMX_DOUBLE
+    set_writing_interval_func_pointer set_writing_interval = tng_util_generic_write_interval_double_set;
+#else
+    set_writing_interval_func_pointer set_writing_interval = tng_util_generic_write_interval_set;
+#endif
 
     gmx_tng_open(filename, mode, output);
 
@@ -112,24 +124,24 @@ void gmx_prepare_tng_writing(const char              *filename,
                 {
                     case TNG_TRAJ_POSITIONS:
                     case TNG_TRAJ_VELOCITIES:
-                        tng_util_generic_write_interval_set(*output, interval, 3, fallbackIds[i],
-                                                            fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
-                                                            compression_type);
+                        set_writing_interval(*output, interval, 3, fallbackIds[i],
+                                             fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
+                                             compression_type);
                         break;
                     case TNG_TRAJ_FORCES:
-                        tng_util_generic_write_interval_set(*output, interval, 3, fallbackIds[i],
-                                                            fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
-                                                            TNG_GZIP_COMPRESSION);
+                        set_writing_interval(*output, interval, 3, fallbackIds[i],
+                                             fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
+                                             TNG_GZIP_COMPRESSION);
                         break;
                     case TNG_TRAJ_BOX_SHAPE:
-                        tng_util_generic_write_interval_set(*output, interval, 9, fallbackIds[i],
-                                                            fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
-                                                            TNG_GZIP_COMPRESSION);
+                        set_writing_interval(*output, interval, 9, fallbackIds[i],
+                                             fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
+                                             TNG_GZIP_COMPRESSION);
                         break;
                     case TNG_GMX_LAMBDA:
-                        tng_util_generic_write_interval_set(*output, interval, 1, fallbackIds[i],
-                                                            fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
-                                                            TNG_GZIP_COMPRESSION);
+                        set_writing_interval(*output, interval, 1, fallbackIds[i],
+                                             fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
+                                             TNG_GZIP_COMPRESSION);
                     default:
                         continue;
                 }
@@ -168,6 +180,9 @@ void gmx_prepare_tng_writing(const char              *filename,
     GMX_UNUSED_VALUE(input);
     GMX_UNUSED_VALUE(output);
     GMX_UNUSED_VALUE(nAtoms);
+    GMX_UNUSED_VALUE(mtop);
+    GMX_UNUSED_VALUE(index);
+    GMX_UNUSED_VALUE(indexGroupName);
 #endif
 }
 
@@ -198,6 +213,7 @@ void gmx_write_tng_from_trxframe(tng_trajectory_t        output,
 #else
     GMX_UNUSED_VALUE(output);
     GMX_UNUSED_VALUE(frame);
+    GMX_UNUSED_VALUE(natoms);
 #endif
 }
 
@@ -419,12 +435,12 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
     gmx_bool                bOK = TRUE;
     tng_function_status     stat;
     gmx_int64_t             numberOfAtoms = -1, frameNumber = -1;
-    gmx_int64_t             nBlocks, blockId, *blockIds = NULL;
-    char                    datatype      = -1, codecId;
+    gmx_int64_t             nBlocks, blockId, *blockIds = NULL, codecId;
+    char                    datatype      = -1;
     void                   *values        = NULL;
     double                  frameTime     = -1.0;
     int                     size, blockDependency;
-    float                   prec;
+    double                  prec;
     const int               defaultNumIds = 5;
     static gmx_int64_t      fallbackRequestedIds[defaultNumIds] =
     {
@@ -521,28 +537,27 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
                         size = sizeof(double);
                         break;
                     default:
-                        size = 0; /* Just to make the compiler happy. */
                         gmx_incons("Illegal datatype of box shape values!");
                 }
                 for (int i = 0; i < DIM; i++)
                 {
                     convert_array_to_real_array((char *)(values) + size * i * DIM,
-                                                    (real *) fr->box[i],
-                                                    getDistanceScaleFactor(input),
-                                                    1,
-                                                    DIM,
-                                                    datatype);
+                                                (real *) fr->box[i],
+                                                getDistanceScaleFactor(input),
+                                                1,
+                                                DIM,
+                                                datatype);
                 }
                 fr->bBox = TRUE;
                 break;
             case TNG_TRAJ_POSITIONS:
                 srenew(fr->x, fr->natoms);
                 convert_array_to_real_array(values,
-                                                (real *) fr->x,
-                                                getDistanceScaleFactor(input),
-                                                fr->natoms,
-                                                DIM,
-                                                datatype);
+                                            (real *) fr->x,
+                                            getDistanceScaleFactor(input),
+                                            fr->natoms,
+                                            DIM,
+                                            datatype);
                 fr->bX = TRUE;
                 tng_util_frame_current_compression_get(input, blockId, &codecId, &prec);
                 /* This must be updated if/when more lossy compression methods are added */
@@ -555,11 +570,11 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
             case TNG_TRAJ_VELOCITIES:
                 srenew(fr->v, fr->natoms);
                 convert_array_to_real_array(values,
-                                                (real *) fr->v,
-                                                getDistanceScaleFactor(input),
-                                                fr->natoms,
-                                                DIM,
-                                                datatype);
+                                            (real *) fr->v,
+                                            getDistanceScaleFactor(input),
+                                            fr->natoms,
+                                            DIM,
+                                            datatype);
                 fr->bV = TRUE;
                 tng_util_frame_current_compression_get(input, blockId, &codecId, &prec);
                 /* This must be updated if/when more lossy compression methods are added */
@@ -572,11 +587,11 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
             case TNG_TRAJ_FORCES:
                 srenew(fr->f, fr->natoms);
                 convert_array_to_real_array(values,
-                                                (real *) fr->f,
-                                                getDistanceScaleFactor(input),
-                                                fr->natoms,
-                                                DIM,
-                                                datatype);
+                                            (real *) fr->f,
+                                            getDistanceScaleFactor(input),
+                                            fr->natoms,
+                                            DIM,
+                                            datatype);
                 fr->bF = TRUE;
                 break;
             case TNG_GMX_LAMBDA:
@@ -614,6 +629,7 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
     GMX_UNUSED_VALUE(input);
     GMX_UNUSED_VALUE(fr);
     GMX_UNUSED_VALUE(requestedIds);
+    GMX_UNUSED_VALUE(numRequestedIds);
     return FALSE;
 #endif
 }
@@ -771,10 +787,11 @@ gmx_bool gmx_get_tng_data_next_frame_of_block_type(tng_trajectory_t     input,
 {
 #ifdef GMX_USE_TNG
     tng_function_status stat;
-    char                datatype = -1, codecId;
+    char                datatype = -1;
+    gmx_int64_t         codecId;
     int                 blockDependency;
     void               *data = 0;
-    float               localPrec;
+    double              localPrec;
 
     stat = tng_data_block_name_get(input, blockId, name, maxLen);
     if (stat != TNG_SUCCESS)
@@ -824,11 +841,11 @@ gmx_bool gmx_get_tng_data_next_frame_of_block_type(tng_trajectory_t     input,
     }
     snew(*values, sizeof(real) * *nValuesPerFrame * *nAtoms);
     convert_array_to_real_array(data,
-                                    *values,
-                                    getDistanceScaleFactor(input),
-                                    *nAtoms,
-                                    *nValuesPerFrame,
-                                    datatype);
+                                *values,
+                                getDistanceScaleFactor(input),
+                                *nAtoms,
+                                *nValuesPerFrame,
+                                datatype);
 
     tng_util_frame_current_compression_get(input, blockId, &codecId, &localPrec);