summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Lundborg <lundborg.magnus@gmail.com>2013-06-19 13:47:27 (GMT)
committerMagnus Lundborg <lundborg.magnus@gmail.com>2013-06-19 13:47:27 (GMT)
commit8881ecdfcb13739b5c2fa46725ae426204075e5f (patch)
tree7d1fd1c144a6f13010d44f66b8256d67f136b78a
parent9d4d18e0826ba12cdcf9aa55722f659ce7c1030f (diff)
Added time stamp to frame set.
Time of first frame in a frame set can be set.
-rw-r--r--include/tng_io.h131
-rw-r--r--src/lib/tng_io.c185
2 files changed, 309 insertions, 7 deletions
diff --git a/include/tng_io.h b/include/tng_io.h
index df99d52..eb67dd8 100644
--- a/include/tng_io.h
+++ b/include/tng_io.h
@@ -343,7 +343,7 @@ typedef unsigned long long int uint64_t;
/** The version of this TNG build */
-#define TNG_VERSION 2
+#define TNG_VERSION 3
/** Flag to indicate frame dependent data. */
#define TNG_FRAME_DEPENDENT 1
@@ -1515,7 +1515,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_write
/**
* @brief Create and initialise a frame set.
* @param tng_data is the trajectory data container in which to add the frame
- * set
+ * set.
* @param first_frame is the first frame of the frame set.
* @param n_frames is the number of frames in the frame set.
* @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
@@ -1527,6 +1527,34 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
const int64_t n_frames);
/**
+ * @brief Create and initialise a frame set with the time of the first frame
+ * specified.
+ * @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.
+ * @param n_frames is the number of frames in the frame set.
+ * @param first_frame_time is the time stamp of the first frame (in fs).
+ * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
+ * has occurred or TNG_CRITICAL (2) if a major error has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_frame_set_with_time_new
+ (tng_trajectory_t tng_data,
+ const int64_t first_frame,
+ const int64_t n_frames,
+ const int64_t first_frame_time);
+
+/**
+ * @brief Set the time stamp of the first frame of the current frame set.
+ * @param tng_data is the trajectory containing the frame set.
+ * @param first_frame_time is the time stamp of the first frame in the
+ * frame set.
+ * @return TNG_SUCCESS (0) if successful.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_frame_set_first_frame_time_set
+ (tng_trajectory_t tng_data,
+ const int64_t first_frame_time);
+
+/**
* @brief Add a non-particle dependent data block.
* @param tng_data is the trajectory data container in which to add the data
* block
@@ -2414,6 +2442,105 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write
const int64_t frame_nr,
const float *box_shape);
+/**
+ * @brief High-level function for adding data to positions data blocks. If the
+ * frame is at the beginning of a frame set the time stamp of the frame set
+ * is set.
+ * @param tng_data is the trajectory to use.
+ * @param frame_nr is the frame number of the data.
+ * @param time is the time stamp of the frame (in fs).
+ * @param positions is a 1D array of data to add. The array should be of length
+ * n_particles * 3.
+ * @details This function uses tng_util_generic_write() and will
+ * create a positions data block if none exists. Positions are stored as three
+ * values per frame and compressed using TNG compression.
+ * N.b. Since compressed data is written a whole block at a time the data is not
+ * actually written to disk until the frame set is finished or the TNG
+ * trajectory is closed.
+ * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
+ * has occured (such as invalid mode) or TNG_CRITICAL (2) if a major error
+ * has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_write
+ (tng_trajectory_t tng_data,
+ const int64_t frame_nr,
+ const int64_t time,
+ const float *positions);
+
+/**
+ * @brief High-level function for adding data to velocities data blocks. If the
+ * frame is at the beginning of a frame set the time stamp of the frame set
+ * is set.
+ * @param tng_data is the trajectory to use.
+ * @param frame_nr is the frame number of the data.
+ * @param time is the time stamp of the frame (in fs).
+ * @param velocities is a 1D array of data to add. The array should be of length
+ * n_particles * 3.
+ * @details This function uses tng_util_generic_write() and will
+ * create a velocities data block if none exists. Velocities are stored as three
+ * values per frame and compressed using TNG compression.
+ * N.b. Since compressed data is written a whole block at a time the data is not
+ * actually written to disk until the frame set is finished or the TNG
+ * trajectory is closed.
+ * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
+ * has occured (such as invalid mode) or TNG_CRITICAL (2) if a major error
+ * has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_util_vel_with_time_write
+ (tng_trajectory_t tng_data,
+ const int64_t frame_nr,
+ const int64_t time,
+ const float *velocities);
+
+/**
+ * @brief High-level function for adding data to forces data blocks. If the
+ * frame is at the beginning of a frame set the time stamp of the frame set
+ * is set.
+ * @param tng_data is the trajectory to use.
+ * @param frame_nr is the frame number of the data.
+ * @param time is the time stamp of the frame (in fs).
+ * @param forces is a 1D array of data to add. The array should be of length
+ * n_particles * 3.
+ * @details This function uses tng_util_generic_write() and will
+ * create a forces data block if none exists. Forces are stored as three
+ * values per frame and compressed using gzip compression.
+ * N.b. Since compressed data is written a whole block at a time the data is not
+ * actually written to disk until the frame set is finished or the TNG
+ * trajectory is closed.
+ * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
+ * has occured (such as invalid mode) or TNG_CRITICAL (2) if a major error
+ * has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_write
+ (tng_trajectory_t tng_data,
+ const int64_t frame_nr,
+ const int64_t time,
+ const float *forces);
+
+/**
+ * @brief High-level function for adding data to box shape data blocks. If the
+ * frame is at the beginning of a frame set the time stamp of the frame set
+ * is set.
+ * @param tng_data is the trajectory to use.
+ * @param frame_nr is the frame number of the data.
+ * @param time is the time stamp of the frame (in fs).
+ * @param box_shape is a 1D array of data to add. The array should be of length 9.
+ * @details This function uses tng_util_generic_write() and will
+ * create a box shape data block if none exists. Box shapes are stored as 9
+ * values per frame and compressed using TNG compression.
+ * N.b. Since compressed data is written a whole block at a time the data is not
+ * actually written to disk until the frame set is finished or the TNG
+ * trajectory is closed.
+ * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
+ * has occured (such as invalid mode) or TNG_CRITICAL (2) if a major error
+ * has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_write
+ (tng_trajectory_t tng_data,
+ const int64_t frame_nr,
+ const int64_t time,
+ const float *box_shape);
+
/** @} */ // end of group2
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index 5b27c87..d477bab 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -171,6 +171,8 @@ struct tng_trajectory_frame_set {
int64_t long_stride_next_frame_set_file_pos;
/** The file position of the frame set one long stride step behind */
int64_t long_stride_prev_frame_set_file_pos;
+ /** Time stamp in fs of first frame in frame set (since TNG_VERSION 3) */
+ int64_t first_frame_time;
/* The data blocks in a frame set are trajectory data blocks */
/** The number of trajectory data blocks of particle dependent data */
@@ -3102,6 +3104,28 @@ static tng_function_status tng_frame_set_block_read
}
}
offset += sizeof(frame_set->long_stride_prev_frame_set_file_pos);
+
+ if(block->block_version >= 3)
+ {
+ memcpy(&frame_set->first_frame_time,
+ block->block_contents + offset,
+ sizeof(frame_set->first_frame_time));
+ if(tng_data->input_endianness_swap_func_64)
+ {
+ if(tng_data->input_endianness_swap_func_64(tng_data,
+ &frame_set->first_frame_time)
+ != TNG_SUCCESS)
+ {
+ printf("Cannot swap byte order. %s: %d\n",
+ __FILE__, __LINE__);
+ }
+ }
+ offset += sizeof(frame_set->first_frame_time);
+ }
+ else
+ {
+ frame_set->first_frame_time = -1;
+ }
return(TNG_SUCCESS);
}
@@ -3147,7 +3171,7 @@ static tng_function_status tng_frame_set_block_write
strcpy(block->name, "TRAJECTORY FRAME SET");
block->id = TNG_TRAJECTORY_FRAME_SET;
- block->block_contents_size = sizeof(int64_t) * 8;
+ block->block_contents_size = sizeof(int64_t) * 9;
if(tng_data->var_num_atoms_flag)
{
block->block_contents_size += sizeof(int64_t) * tng_data->n_molecules;
@@ -3303,6 +3327,21 @@ static tng_function_status tng_frame_set_block_write
}
offset += sizeof(frame_set->long_stride_prev_frame_set_file_pos);
+ memcpy(block->block_contents+offset,
+ &frame_set->first_frame_time,
+ sizeof(frame_set->first_frame_time));
+ if(tng_data->output_endianness_swap_func_64)
+ {
+ if(tng_data->output_endianness_swap_func_64(tng_data,
+ (int64_t *)block->header_contents+offset)
+ != TNG_SUCCESS)
+ {
+ printf("Cannot swap byte order. %s: %d\n",
+ __FILE__, __LINE__);
+ }
+ }
+ offset += sizeof(frame_set->first_frame_time);
+
if(tng_block_header_write(tng_data, block, hash_mode) != TNG_SUCCESS)
{
printf("Cannot write header of file %s. %s: %d\n",
@@ -6205,7 +6244,7 @@ static tng_function_status tng_frame_set_pointers_update
contents_start_pos = ftell(tng_data->output_file);
- fseek(tng_data->output_file, block->block_contents_size - 6 *
+ fseek(tng_data->output_file, block->block_contents_size - 7 *
sizeof(int64_t), SEEK_CUR);
pos = tng_data->current_trajectory_frame_set_output_file_pos;
@@ -6256,7 +6295,7 @@ static tng_function_status tng_frame_set_pointers_update
contents_start_pos = ftell(tng_data->output_file);
- fseek(tng_data->output_file, block->block_contents_size - 4 *
+ fseek(tng_data->output_file, block->block_contents_size - 5 *
sizeof(int64_t), SEEK_CUR);
pos = tng_data->current_trajectory_frame_set_output_file_pos;
@@ -6306,7 +6345,7 @@ static tng_function_status tng_frame_set_pointers_update
contents_start_pos = ftell(tng_data->output_file);
- fseek(tng_data->output_file, block->block_contents_size - 2 *
+ fseek(tng_data->output_file, block->block_contents_size - 3 *
sizeof(int64_t), SEEK_CUR);
pos = tng_data->current_trajectory_frame_set_output_file_pos;
@@ -7682,6 +7721,8 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init(tng_trajectory_t *tng_
frame_set->medium_stride_prev_frame_set_file_pos = -1;
frame_set->long_stride_next_frame_set_file_pos = -1;
frame_set->long_stride_prev_frame_set_file_pos = -1;
+
+ frame_set->first_frame_time = -1;
tng_data->n_molecules = 0;
tng_data->molecules = 0;
@@ -8198,7 +8239,6 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src(tng_trajector
dest->compress_algo_pos = 0;
dest->compress_algo_vel = 0;
- frame_set->first_frame = -1;
frame_set->n_mapping_blocks = 0;
frame_set->mappings = 0;
frame_set->molecule_cnt_list = 0;
@@ -8215,6 +8255,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src(tng_trajector
frame_set->medium_stride_prev_frame_set_file_pos = -1;
frame_set->long_stride_next_frame_set_file_pos = -1;
frame_set->long_stride_prev_frame_set_file_pos = -1;
+ frame_set->first_frame = -1;
dest->n_molecules = 0;
dest->molecules = 0;
@@ -10412,6 +10453,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
frame_set->n_frames = n_frames;
frame_set->n_written_frames = 0;
frame_set->n_unwritten_frames = 0;
+ frame_set->first_frame_time = -1;
if(tng_data->first_trajectory_frame_set_output_file_pos == -1 ||
tng_data->first_trajectory_frame_set_output_file_pos == 0)
@@ -10433,7 +10475,32 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
return(TNG_SUCCESS);
}
+tng_function_status DECLSPECDLLEXPORT tng_frame_set_with_time_new
+ (tng_trajectory_t tng_data,
+ const int64_t first_frame,
+ const int64_t n_frames,
+ const int64_t first_frame_time)
+{
+ tng_function_status stat;
+
+ stat = tng_frame_set_new(tng_data, first_frame, n_frames);
+ if(stat != TNG_SUCCESS)
+ {
+ return(stat);
+ }
+ stat = tng_frame_set_first_frame_time_set(tng_data, first_frame_time);
+
+ return(stat);
+}
+tng_function_status DECLSPECDLLEXPORT tng_frame_set_first_frame_time_set
+ (tng_trajectory_t tng_data,
+ const int64_t first_frame_time)
+{
+ tng_data->current_trajectory_frame_set.first_frame_time = first_frame_time;
+
+ return(TNG_SUCCESS);
+}
tng_function_status DECLSPECDLLEXPORT tng_data_block_add
(tng_trajectory_t tng_data,
@@ -13842,6 +13909,97 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write
TNG_GZIP_COMPRESSION));
}
+tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_write
+ (tng_trajectory_t tng_data,
+ const int64_t frame_nr,
+ const int64_t time,
+ const float *positions)
+{
+ tng_function_status stat;
+
+ stat = tng_util_generic_write(tng_data, frame_nr, positions, 3,
+ TNG_TRAJ_POSITIONS, "POSITIONS",
+ TNG_PARTICLE_BLOCK_DATA,
+ TNG_TNG_COMPRESSION);
+ if(stat != TNG_SUCCESS)
+ {
+ return(stat);
+ }
+ if(tng_data->current_trajectory_frame_set.first_frame == frame_nr)
+ {
+ stat = tng_frame_set_first_frame_time_set(tng_data, time);
+ }
+ return(stat);
+}
+
+tng_function_status DECLSPECDLLEXPORT tng_util_vel_with_time_write
+ (tng_trajectory_t tng_data,
+ const int64_t frame_nr,
+ const int64_t time,
+ const float *velocities)
+{
+ tng_function_status stat;
+
+ stat = tng_util_generic_write(tng_data, frame_nr, velocities, 3,
+ TNG_TRAJ_VELOCITIES, "VELOCITIES",
+ TNG_PARTICLE_BLOCK_DATA,
+ TNG_TNG_COMPRESSION);
+ if(stat != TNG_SUCCESS)
+ {
+ return(stat);
+ }
+ if(tng_data->current_trajectory_frame_set.first_frame == frame_nr)
+ {
+ stat = tng_frame_set_first_frame_time_set(tng_data, time);
+ }
+ return(stat);
+}
+
+tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_write
+ (tng_trajectory_t tng_data,
+ const int64_t frame_nr,
+ const int64_t time,
+ const float *forces)
+{
+ tng_function_status stat;
+
+ stat = tng_util_generic_write(tng_data, frame_nr, forces, 3,
+ TNG_TRAJ_FORCES, "FORCES",
+ TNG_PARTICLE_BLOCK_DATA,
+ TNG_GZIP_COMPRESSION);
+ if(stat != TNG_SUCCESS)
+ {
+ return(stat);
+ }
+ if(tng_data->current_trajectory_frame_set.first_frame == frame_nr)
+ {
+ stat = tng_frame_set_first_frame_time_set(tng_data, time);
+ }
+ return(stat);
+}
+
+tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_write
+ (tng_trajectory_t tng_data,
+ const int64_t frame_nr,
+ const int64_t time,
+ const float *box_shape)
+{
+ tng_function_status stat;
+
+ stat = tng_util_generic_write(tng_data, frame_nr, box_shape, 9,
+ TNG_TRAJ_BOX_SHAPE, "BOX SHAPE",
+ TNG_NON_PARTICLE_BLOCK_DATA,
+ TNG_GZIP_COMPRESSION);
+ if(stat != TNG_SUCCESS)
+ {
+ return(stat);
+ }
+ if(tng_data->current_trajectory_frame_set.first_frame == frame_nr)
+ {
+ stat = tng_frame_set_first_frame_time_set(tng_data, time);
+ }
+ return(stat);
+}
#ifdef BUILD_FORTRAN
/* The following is for calling the library from fortran */
@@ -14504,6 +14662,23 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new_(tng_trajectory_t tng_da
return(tng_frame_set_new(tng_data, *first_frame, *n_frames));
}
+tng_function_status DECLSPECDLLEXPORT tng_frame_set_with_time_new_
+ (tng_trajectory_t tng_data,
+ const int64_t *first_frame,
+ const int64_t *n_frames,
+ const int64_t *first_frame_time)
+{
+ return(tng_frame_set_new(tng_data, *first_frame, *n_frames,
+ *first_frame_time));
+}
+
+tng_function_status DECLSPECDLLEXPORT tng_frame_set_first_frame_time_set_
+ (tng_trajectory_t tng_data,
+ const int64_t *first_frame_time)
+{
+ return(tng_frame_set_first_frame_time_set(tng_data, *first_frame_time);
+}
+
tng_function_status DECLSPECDLLEXPORT tng_data_block_add_
(tng_trajectory_t tng_data,
const int64_t *id,
contact: Jan Huwald // Impressum