TNG version 1.7.5
authorMagnus Lundborg <lundborg.magnus@gmail.com>
Wed, 29 Apr 2015 18:29:27 +0000 (20:29 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 16 May 2015 14:48:45 +0000 (16:48 +0200)
Corresponds to 7482fac2a840e5f99664fbe812a3ce05e0eef335 in the
TNG repository.

Fixed bug when writing multiple chains in one molecule. Pointers
to the residues in the chain were not properly updated.

Fixed minor issues.

sizeof should not be printed as %lu but %<PRIuPTR>.

Change-Id: Ice90c72dd37df77d3d15c4d05d40df5994fed943

src/external/tng_io/BuildTNG.cmake
src/external/tng_io/include/tng/tng_io.h
src/external/tng_io/src/lib/tng_io.c

index a00d5b5e4ed2ddb5550eb9366123fd40fefafede..38a86c61c4787908513050522dd9901d2adb62ee 100644 (file)
@@ -5,7 +5,7 @@ set(TNG_ROOT_BINARY_DIR ${CMAKE_BINARY_DIR}/${TNG_ROOT_BINARY_DIR})
 function (TNG_GENERATE_VERSION_H)
     set(TNG_MAJOR_VERSION "1")
     set(TNG_MINOR_VERSION "7")
-    set(TNG_VERSION_PATCH_LEVEL "3")
+    set(TNG_VERSION_PATCH_LEVEL "5")
     set(TNG_IO_VERSION "${TNG_MAJOR_VERSION}.${TNG_MINOR_VERSION}.${TNG_VERSION_PATCH_LEVEL}")
     set(TNG_API_VERSION "7")
     configure_file(${TNG_ROOT_SOURCE_DIR}/include/tng/version.h.in
index 668acbea7b214c9968d4c0f6a9866f2075d1e1fb..d8ff0fea228500478f0a132b1e7256bf5ed49666 100644 (file)
@@ -343,6 +343,10 @@ typedef unsigned __int64 uint64_t;
 # define PRIu64         __PRI64_PREFIX "u"
 #endif
 
+#ifndef PRIuPTR
+# define PRIuPTR         __PRIPTR_PREFIX "u"
+#endif
+
 #endif
 
 #endif /* USE_STD_INTTYPES_H */
@@ -2128,9 +2132,10 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_atom_w_id_add
  * @pre \code atom != 0 \endcode The atom must not be NULL.
  * @return TNG_SUCCESS (0) if successful.
  */
-tng_function_status tng_atom_residue_get(const tng_trajectory_t tng_data,
-                                         const tng_atom_t atom,
-                                         tng_residue_t *residue);
+tng_function_status DECLSPECDLLEXPORT tng_atom_residue_get
+                (const tng_trajectory_t tng_data,
+                 const tng_atom_t atom,
+                 tng_residue_t *residue);
 
 /**
  * @brief Get the name of an atom.
index 94e74309241feb005515094e6d84a7ef54d8d017..6ac939c208e8387b1e9e10f6b3be383724feb5e7 100644 (file)
@@ -949,7 +949,7 @@ static tng_function_status tng_block_init(struct tng_gen_block **block_p)
     *block_p = malloc(sizeof(struct tng_gen_block));
     if(!*block_p)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n",
                sizeof(struct tng_gen_block), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -3080,7 +3080,7 @@ static tng_function_status tng_molecules_block_read
         if(molecule->n_residues > 0)
         {
             molecule->residues = malloc(molecule->n_residues *
-                                sizeof(struct tng_residue));
+                                        sizeof(struct tng_residue));
             if(!molecule->residues)
             {
                 fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
@@ -4203,7 +4203,7 @@ static tng_function_status tng_particle_data_block_create
                     frame_set->n_particle_data_blocks);
         if(!data)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n",
                 sizeof(struct tng_data) *
                 frame_set->n_particle_data_blocks,
                 __FILE__, __LINE__);
@@ -4221,7 +4221,7 @@ static tng_function_status tng_particle_data_block_create
                         tng_data->n_particle_data_blocks);
         if(!data)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n",
                     sizeof(struct tng_data) *
                     tng_data->n_particle_data_blocks,
                     __FILE__, __LINE__);
@@ -5097,7 +5097,7 @@ static tng_function_status tng_data_block_create
                        frame_set->n_data_blocks);
         if(!data)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n",
                 sizeof(struct tng_data) * frame_set->n_data_blocks,
                 __FILE__, __LINE__);
             free(frame_set->tr_data);
@@ -5113,7 +5113,7 @@ static tng_function_status tng_data_block_create
                         tng_data->n_data_blocks);
         if(!data)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n",
                 sizeof(struct tng_data) * tng_data->n_data_blocks,
                 __FILE__, __LINE__);
             free(tng_data->non_tr_data);
@@ -5772,7 +5772,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data,
         temp_name = realloc(block->name, len);
         if(!temp_name)
         {
-            fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", len+1,
+            fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n", len+1,
                    __FILE__, __LINE__);
             free(block->name);
             block->name = 0;
@@ -6678,9 +6678,10 @@ static tng_function_status tng_frame_set_finalize
 // }
 */
 
-tng_function_status tng_atom_residue_get(const tng_trajectory_t tng_data,
-                                         const tng_atom_t atom,
-                                         tng_residue_t *residue)
+tng_function_status DECLSPECDLLEXPORT tng_atom_residue_get
+                (const tng_trajectory_t tng_data,
+                 const tng_atom_t atom,
+                 tng_residue_t *residue)
 {
     (void) tng_data;
 
@@ -6691,10 +6692,11 @@ tng_function_status tng_atom_residue_get(const tng_trajectory_t tng_data,
     return(TNG_SUCCESS);
 }
 
-tng_function_status tng_atom_name_get(const tng_trajectory_t tng_data,
-                                      const tng_atom_t atom,
-                                      char *name,
-                                      const int max_len)
+tng_function_status DECLSPECDLLEXPORT tng_atom_name_get
+                (const tng_trajectory_t tng_data,
+                 const tng_atom_t atom,
+                 char *name,
+                 const int max_len)
 {
     (void) tng_data;
     TNG_ASSERT(atom, "TNG library: atom must not be NULL");
@@ -6710,9 +6712,10 @@ tng_function_status tng_atom_name_get(const tng_trajectory_t tng_data,
     return(TNG_SUCCESS);
 }
 
-tng_function_status tng_atom_name_set(const tng_trajectory_t tng_data,
-                                      const tng_atom_t atom,
-                                      const char *new_name)
+tng_function_status DECLSPECDLLEXPORT tng_atom_name_set
+                (const tng_trajectory_t tng_data,
+                 const tng_atom_t atom,
+                 const char *new_name)
 {
     unsigned int len;
     (void)tng_data;
@@ -6745,10 +6748,11 @@ tng_function_status tng_atom_name_set(const tng_trajectory_t tng_data,
     return(TNG_SUCCESS);
 }
 
-tng_function_status tng_atom_type_get(const tng_trajectory_t tng_data,
-                                      const tng_atom_t atom,
-                                      char *type,
-                                      const int max_len)
+tng_function_status DECLSPECDLLEXPORT tng_atom_type_get
+                (const tng_trajectory_t tng_data,
+                 const tng_atom_t atom,
+                 char *type,
+                 const int max_len)
 {
     (void) tng_data;
     TNG_ASSERT(atom, "TNG library: atom must not be NULL");
@@ -6764,9 +6768,10 @@ tng_function_status tng_atom_type_get(const tng_trajectory_t tng_data,
     return(TNG_SUCCESS);
 }
 
-tng_function_status tng_atom_type_set(const tng_trajectory_t tng_data,
-                                      const tng_atom_t atom,
-                                      const char *new_type)
+tng_function_status DECLSPECDLLEXPORT tng_atom_type_set
+                (const tng_trajectory_t tng_data,
+                 const tng_atom_t atom,
+                 const char *new_type)
 {
     unsigned int len;
     (void)tng_data;
@@ -6833,6 +6838,31 @@ static tng_function_status tng_atom_destroy(const tng_atom_t atom)
     return(TNG_SUCCESS);
 }
 
+/**
+ * @brief Update chain->residue pointers (after new memory for
+ * molecule->residues has been allocated).
+ * @param tng_data The trajectory container containing the molecule.
+ * @param mol The molecule that contains the chains that need to be
+ * updated.
+ * @returns TNG_SUCCESS (0) if successful.
+ */
+static tng_function_status tng_molecule_chains_residue_pointers_update
+                (const tng_trajectory_t tng_data,
+                 const tng_molecule_t mol)
+{
+    tng_chain_t chain;
+    int64_t i, res_cnt = 0;
+    (void)tng_data;
+
+    for(i = 0; i < mol->n_chains; i++)
+    {
+        chain = &mol->chains[i];
+        chain->residues = mol->residues + res_cnt;
+        res_cnt += chain->n_residues;
+    }
+    return(TNG_SUCCESS);
+}
+
 tng_function_status DECLSPECDLLEXPORT tng_version_major
                 (const tng_trajectory_t tng_data,
                  int *version)
@@ -7814,14 +7844,7 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_residue_w_id_add
 
     *residue = &molecule->residues[curr_index + chain->n_residues];
 
-    if(!chain->n_residues)
-    {
-        chain->residues = *residue;
-    }
-    else
-    {
-        chain->residues = &molecule->residues[curr_index];
-    }
+    tng_molecule_chains_residue_pointers_update(tng_data, molecule);
 
     (*residue)->name = 0;
     tng_residue_name_set(tng_data, *residue, name);
@@ -8023,7 +8046,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_alloc(const tng_trajectory_t
     *molecule_p = malloc(sizeof(struct tng_molecule));
     if(!*molecule_p)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n",
                sizeof(struct tng_molecule), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -8710,7 +8733,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init(tng_trajectory_t *tng_
     *tng_data_p = malloc(sizeof(struct tng_trajectory));
     if(!*tng_data_p)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n",
                sizeof(struct tng_trajectory), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -9234,7 +9257,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src
     *dest_p = malloc(sizeof(struct tng_trajectory));
     if(!*dest_p)
     {
-        fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+        fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIuPTR" bytes). %s: %d\n",
                sizeof(struct tng_trajectory), __FILE__, __LINE__);
         return(TNG_CRITICAL);
     }
@@ -10313,7 +10336,7 @@ tng_function_status DECLSPECDLLEXPORT tng_implicit_num_particles_set
     tng_function_status stat;
     int64_t diff, n_mod, n_impl;
 
-    TNG_ASSERT(n >= 0, "TNG library: The number of molecules must be >= 0");
+    TNG_ASSERT(n >= 0, "TNG library: The requested number of particles must be >= 0");
 
     diff = n - tng_data->n_particles;