summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tng_io.h15
-rw-r--r--src/lib/tng_io.c73
-rw-r--r--src/tests/tng_io_testing.c2
3 files changed, 52 insertions, 38 deletions
diff --git a/include/tng_io.h b/include/tng_io.h
index b6d0890..3b19a32 100644
--- a/include/tng_io.h
+++ b/include/tng_io.h
@@ -2323,6 +2323,19 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_mapping_add
const int64_t *mapping_table);
/**
+ * @brief Remove all particle mappings (in memory) from the current frame set.
+ * @details Clears the currently setup particle mappings of the current frame
+ * set.
+ * @param tng_data is the trajectory, with the frame set of which to clear
+ * all particle mappings.
+ * @pre \code tng_data != 0 \endcode The trajectory container (tng_data)
+ * must be initialised before using it.
+ * @return TNG_SUCCESS (0) if successful.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_frame_set_particle_mapping_free
+ (tng_trajectory_t tng_data);
+
+/**
* @brief Read the header blocks from the input_file of tng_data.
* @details The trajectory blocks must be read separately and iteratively in chunks
* to fit in memory.
@@ -2504,6 +2517,8 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_premature_write
/**
* @brief Create and initialise a frame set.
+ * @details Particle mappings are retained from previous frame set (if any).
+ * To explicitly clear particle mappings use tng_frame_set_particle_mapping_free().
* @param tng_data is the trajectory data container in which to add the frame
* set.
* @param first_frame is the first frame of the frame set.
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index 4611037..e4774dd 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -722,35 +722,6 @@ static tng_function_status tng_output_file_init(tng_trajectory_t tng_data)
return(TNG_SUCCESS);
}
-static tng_function_status DECLSPECDLLEXPORT tng_frame_set_particle_mapping_free(tng_trajectory_t tng_data)
-{
- tng_trajectory_frame_set_t frame_set;
- tng_particle_mapping_t mapping;
- int64_t i;
-
- TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
-
- frame_set = &tng_data->current_trajectory_frame_set;
-
- if(frame_set->n_mapping_blocks && frame_set->mappings)
- {
- for(i = frame_set->n_mapping_blocks; i--;)
- {
- mapping = &frame_set->mappings[i];
- if(mapping->real_particle_numbers)
- {
- free(mapping->real_particle_numbers);
- mapping->real_particle_numbers = 0;
- }
- }
- free(frame_set->mappings);
- frame_set->mappings = 0;
- frame_set->n_mapping_blocks = 0;
- }
-
- return(TNG_SUCCESS);
-}
-
/** Setup a file block container.
* @param block_p a pointer to memory to initialise as a file block container.
* @details Memory is allocated during initialisation.
@@ -7446,7 +7417,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_cnt_set
{
old_cnt = tng_data->current_trajectory_frame_set.molecule_cnt_list[index];
tng_data->current_trajectory_frame_set.molecule_cnt_list[index] = cnt;
-
+
tng_data->current_trajectory_frame_set.n_particles += (cnt-old_cnt) *
tng_data->molecules[index].n_atoms;
}
@@ -8443,7 +8414,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_name_of_particle_nr_get
TNG_ASSERT(name, "TNG library: name must not be a NULL pointer.");
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
-
+
if(!molecule_cnt_list)
{
return(TNG_FAILURE);
@@ -8550,7 +8521,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molsystem_bonds_get
{
return(TNG_SUCCESS);
}
-
+
*from_atoms = malloc(sizeof(int64_t) * (*n_bonds));
if(!*from_atoms)
{
@@ -8971,6 +8942,35 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_mapping_add
return(TNG_SUCCESS);
}
+tng_function_status DECLSPECDLLEXPORT tng_frame_set_particle_mapping_free(tng_trajectory_t tng_data)
+{
+ tng_trajectory_frame_set_t frame_set;
+ tng_particle_mapping_t mapping;
+ int64_t i;
+
+ TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
+
+ frame_set = &tng_data->current_trajectory_frame_set;
+
+ if(frame_set->n_mapping_blocks && frame_set->mappings)
+ {
+ for(i = frame_set->n_mapping_blocks; i--;)
+ {
+ mapping = &frame_set->mappings[i];
+ if(mapping->real_particle_numbers)
+ {
+ free(mapping->real_particle_numbers);
+ mapping->real_particle_numbers = 0;
+ }
+ }
+ free(frame_set->mappings);
+ frame_set->mappings = 0;
+ frame_set->n_mapping_blocks = 0;
+ }
+
+ return(TNG_SUCCESS);
+}
+
tng_function_status DECLSPECDLLEXPORT tng_trajectory_init(tng_trajectory_t *tng_data_p)
{
time_t seconds;
@@ -10561,7 +10561,7 @@ tng_function_status DECLSPECDLLEXPORT tng_implicit_num_particles_set
tng_molecule_cnt_get(tng_data, mol, &n_impl);
diff -= n_impl * mol->n_atoms;
}
-
+
if(diff == 0)
{
if(stat == TNG_SUCCESS)
@@ -12354,9 +12354,6 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
tng_data->current_trajectory_frame_set_output_file_pos =
ftell(tng_data->output_file);
- /* Clear mappings if they remain. */
- tng_frame_set_particle_mapping_free(tng_data);
-
tng_data->n_trajectory_frame_sets++;
/* Set the medium range pointers */
@@ -14849,7 +14846,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_vector_interval_get
__FILE__, __LINE__);
return(stat);
}
-
+
fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
}
file_pos = ftell(tng_data->input_file);
@@ -15693,7 +15690,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_vector_interval_get
__FILE__, __LINE__);
return(stat);
}
-
+
fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
}
file_pos = ftell(tng_data->input_file);
diff --git a/src/tests/tng_io_testing.c b/src/tests/tng_io_testing.c
index ff41024..3899b15 100644
--- a/src/tests/tng_io_testing.c
+++ b/src/tests/tng_io_testing.c
@@ -286,6 +286,8 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t *traj)
return(TNG_CRITICAL);
}
+ tng_frame_set_particle_mapping_free(*traj);
+
/* Setup particle mapping. Use 4 different mapping blocks with arbitrary
* mappings. */
for(k=0; k<150; k++)
contact: Jan Huwald // Impressum