TNG Fix for GMX_DOUBLE builds and where ZLIB is not available.
authorMagnus Lundborg <lundborg.magnus@gmail.com>
Tue, 26 Aug 2014 12:02:06 +0000 (14:02 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 2 Sep 2014 12:14:03 +0000 (14:14 +0200)
Also includes a check that the user name can be retrieved
before trying to set it.

Change-Id: I51d4ab2e590752980953d1926d4bea56fe1beffa

src/external/tng_io/src/lib/tng_io.c
src/gromacs/fileio/tngio.cpp
src/gromacs/fileio/tngio_for_tools.cpp

index 92721fab40771bd567403af5003b4e34cb610c0d..c388f789bfcbae367f3e583bde0c91098c41631f 100644 (file)
@@ -4917,7 +4917,7 @@ static tng_function_status tng_compress(tng_trajectory_t tng_data,
         if(n_frames == 1 && tng_data->frame_set_n_frames > 1)
         {
             nalgo = tng_compress_nalgo();
-            alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_pos);
+            alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_vel);
             if(type == TNG_FLOAT_DATA)
             {
                 dest = tng_compress_vel_float_find_algo((float *)temp_data_contents, (int)n_particles,
@@ -5683,6 +5683,16 @@ static tng_function_status tng_particle_data_read
 
     TNG_ASSERT(offset != 0, "TNG library: offset must not be a NULL pointer.");
 
+    /* This must be caught early to avoid creating a data block if not necessary. */
+#ifndef USE_ZLIB
+    if(codec_id == TNG_GZIP_COMPRESSION)
+    {
+        fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__,
+                __LINE__);
+        return(TNG_FAILURE);
+    }
+#endif
+
     switch(datatype)
     {
     case TNG_CHAR_DATA:
@@ -6617,6 +6627,16 @@ static tng_function_status tng_data_read(tng_trajectory_t tng_data,
 
 /*     fprintf(stderr, "TNG library: %s\n", block->name);*/
 
+    /* This must be caught early to avoid creating a data block if not necessary. */
+#ifndef USE_ZLIB
+    if(codec_id == TNG_GZIP_COMPRESSION)
+    {
+        fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__,
+                __LINE__);
+        return(TNG_FAILURE);
+    }
+#endif
+
     switch(datatype)
     {
     case TNG_CHAR_DATA:
index 1fea9473e73b1ed3947bd897315ca7d045f98af4..fb8b8f6dcb39e15966351fcfdca1e111be1a90d9 100644 (file)
@@ -149,10 +149,12 @@ void gmx_tng_open(const char       *filename,
 
 #ifdef HAVE_UNISTD_H
         char username[256];
-        getlogin_r(username, 256);
-        if (mode == 'w')
+        if (!getlogin_r(username, 256))
         {
-            tng_first_user_name_set(*tng, username);
+            if (mode == 'w')
+            {
+                tng_first_user_name_set(*tng, username);
+            }
         }
 /* TODO: This should be implemented when the above fixme is done (adding data to
  * the header). */
index 1c579a6f81744798b72b727f3771e90fc305a132..997b40942f33ed251a7bccd50f417ecf41bae413 100644 (file)
@@ -78,6 +78,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);
 
@@ -115,24 +127,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;
                 }