From dc08c1e4cb0bb26e02219f49bb3f6eb9801fe764 Mon Sep 17 00:00:00 2001 From: Magnus Lundborg Date: Wed, 30 Oct 2013 11:05:22 +0100 Subject: Added utility function to get time of frame. diff --git a/include/tng_io.h b/include/tng_io.h index c31d8a2..e26089d 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -2142,6 +2142,19 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_open */ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_close (tng_trajectory_t *tng_data_p); + +/** + * @brief High-level function for getting the time (in seconds) of a frame. + * @param tng_data is the trajectory containing the frame. + * @param frame_nr is the frame number of which to get the time. + * @param time is set to the time (in seconds) of the specified frame. + * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (1) if a + * minor error has occured. + */ +tng_function_status DECLSPECDLLEXPORT tng_util_time_of_frame_get + (tng_trajectory_t tng_data, + const int64_t frame_nr, + double *time); /* // tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_molecules_get // (tng_trajectory_t tng_data, diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 69dbadd..dccbf03 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -14652,6 +14652,32 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_close return(tng_trajectory_destroy(tng_data_p)); } +tng_function_status DECLSPECDLLEXPORT tng_util_time_of_frame_get + (tng_trajectory_t tng_data, + const int64_t frame_nr, + double *time) +{ + int64_t first_frame; + + tng_trajectory_frame_set_t frame_set; + tng_function_status stat; + + stat = tng_frame_set_of_frame_find(tng_data, frame_nr); + if(stat != TNG_SUCCESS) + { + printf("Cannot find frame nr %"PRId64". %s: %d\n", + frame_nr, __FILE__, __LINE__); + return(stat); + } + + frame_set = &tng_data->current_trajectory_frame_set; + first_frame = frame_set->first_frame; + + *time = frame_set->first_frame_time + (tng_data->time_per_frame * frame_nr - first_frame); + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_molecules_get (tng_trajectory_t tng_data, int64_t *n_mols, -- cgit v0.10.1