diff options
-rw-r--r-- | include/tng_io.h | 78 | ||||
-rw-r--r-- | src/lib/tng_io.c | 183 |
2 files changed, 159 insertions, 102 deletions
diff --git a/include/tng_io.h b/include/tng_io.h index e536725..7d3cdb1 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -2827,6 +2827,84 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_double_write const double *box_shape); /** + * @brief High-level function for writing data of one frame to a data block. + * 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 values is a 1D array of data to add. The array should be of length + * n_particles * n_values_per_frame if writing particle related data, otherwise + * it should be n_values_per_frame. + * @param n_values_per_frame is the number of values to store per frame. If the + * data is particle dependent there will be n_values_per_frame stored per + * particle each frame. + * @param block_id is the ID of the block, of which to set the output interval. + * @param block_name is a string that will be used as name of the block. + * @param particle_dependency should be TNG_NON_PARTICLE_BLOCK_DATA (0) if the + * data is not related to specific particles (e.g. box shape) or + * TNG_PARTICLE_BLOCK_DATA (1) is it is related to specific particles (e.g. + * positions). + * @param compression is the compression routine to use when writing the data. + * @details n_values_per_frame, block_name, particle_dependency and + * compression are only used if the data block did not exist before calling + * this function, in which case it is created. + * N.b. 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_generic_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const float *values, + const int64_t n_values_per_frame, + const int64_t block_id, + const char *block_name, + const char particle_dependency, + const char compression); + +/** + * @brief High-level function for writing data of one frame to a double precision + * data block. 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 values is a 1D array of data to add. The array should be of length + * n_particles * n_values_per_frame if writing particle related data, otherwise + * it should be n_values_per_frame. + * @param n_values_per_frame is the number of values to store per frame. If the + * data is particle dependent there will be n_values_per_frame stored per + * particle each frame. + * @param block_id is the ID of the block, of which to set the output interval. + * @param block_name is a string that will be used as name of the block. + * @param particle_dependency should be TNG_NON_PARTICLE_BLOCK_DATA (0) if the + * data is not related to specific particles (e.g. box shape) or + * TNG_PARTICLE_BLOCK_DATA (1) is it is related to specific particles (e.g. + * positions). + * @param compression is the compression routine to use when writing the data. + * @details n_values_per_frame, block_name, particle_dependency and + * compression are only used if the data block did not exist before calling + * this function, in which case it is created. + * N.b. 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_generic_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *values, + const int64_t n_values_per_frame, + const int64_t block_id, + const char *block_name, + const char particle_dependency, + const char compression); + +/** * @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. diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index e0e34c3..b1ea313 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -15775,18 +15775,24 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_double_write TNG_GZIP_COMPRESSION)); } -tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_write +tng_function_status DECLSPECDLLEXPORT tng_util_generic_with_time_write (tng_trajectory_t tng_data, const int64_t frame_nr, const double time, - const float *positions) + const float *values, + const int64_t n_values_per_frame, + const int64_t block_id, + const char *block_name, + const char particle_dependency, + const char compression) { 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); + stat = tng_util_generic_write(tng_data, frame_nr, values, n_values_per_frame, + block_id, block_name, + particle_dependency, + compression); + if(stat != TNG_SUCCESS) { return(stat); @@ -15798,18 +15804,24 @@ tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_write return(stat); } -tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_double_write +tng_function_status DECLSPECDLLEXPORT tng_util_generic_with_time_double_write (tng_trajectory_t tng_data, const int64_t frame_nr, const double time, - const double *positions) + const double *values, + const int64_t n_values_per_frame, + const int64_t block_id, + const char *block_name, + const char particle_dependency, + const char compression) { tng_function_status stat; - stat = tng_util_generic_double_write(tng_data, frame_nr, positions, 3, - TNG_TRAJ_POSITIONS, "POSITIONS", - TNG_PARTICLE_BLOCK_DATA, - TNG_TNG_COMPRESSION); + stat = tng_util_generic_double_write(tng_data, frame_nr, values, n_values_per_frame, + block_id, block_name, + particle_dependency, + compression); + if(stat != TNG_SUCCESS) { return(stat); @@ -15821,27 +15833,44 @@ tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_double_write return(stat); } +tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double time, + const float *positions) +{ + return(tng_util_generic_with_time_write(tng_data, frame_nr, time, positions, + 3, TNG_TRAJ_POSITIONS, "POSITIONS", + TNG_PARTICLE_BLOCK_DATA, + TNG_TNG_COMPRESSION)); +} + +tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double time, + const double *positions) +{ + return(tng_util_generic_with_time_double_write(tng_data, frame_nr, time, + positions, 3, + TNG_TRAJ_POSITIONS, + "POSITIONS", + TNG_PARTICLE_BLOCK_DATA, + TNG_TNG_COMPRESSION)); +} + tng_function_status DECLSPECDLLEXPORT tng_util_vel_with_time_write (tng_trajectory_t tng_data, const int64_t frame_nr, const double 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); + return(tng_util_generic_with_time_write(tng_data, frame_nr, time, + velocities, 3, + TNG_TRAJ_VELOCITIES, + "VELOCITIES", + TNG_PARTICLE_BLOCK_DATA, + TNG_TNG_COMPRESSION)); } tng_function_status DECLSPECDLLEXPORT tng_util_vel_with_time_double_write @@ -15850,21 +15879,12 @@ tng_function_status DECLSPECDLLEXPORT tng_util_vel_with_time_double_write const double time, const double *velocities) { - tng_function_status stat; - - stat = tng_util_generic_double_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); + return(tng_util_generic_with_time_double_write(tng_data, frame_nr, time, + velocities, 3, + TNG_TRAJ_VELOCITIES, + "VELOCITIES", + TNG_PARTICLE_BLOCK_DATA, + TNG_TNG_COMPRESSION)); } tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_write @@ -15873,21 +15893,10 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_write const double 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); + return(tng_util_generic_with_time_write(tng_data, frame_nr, time, forces, + 3, TNG_TRAJ_FORCES, "FORCES", + TNG_PARTICLE_BLOCK_DATA, + TNG_GZIP_COMPRESSION)); } tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_double_write @@ -15896,21 +15905,11 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_double_write const double time, const double *forces) { - tng_function_status stat; - - stat = tng_util_generic_double_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); + return(tng_util_generic_with_time_double_write(tng_data, frame_nr, time, + forces, 3, + TNG_TRAJ_FORCES, "FORCES", + TNG_PARTICLE_BLOCK_DATA, + TNG_GZIP_COMPRESSION)); } tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_write @@ -15919,21 +15918,10 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_write const double 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); + return(tng_util_generic_with_time_write(tng_data, frame_nr, time, box_shape, + 9, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE", + TNG_NON_PARTICLE_BLOCK_DATA, + TNG_GZIP_COMPRESSION)); } tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_double_write @@ -15942,20 +15930,11 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_double_write const double time, const double *box_shape) { - tng_function_status stat; - - stat = tng_util_generic_double_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); + return(tng_util_generic_with_time_double_write(tng_data, frame_nr, + time, box_shape, 9, + TNG_TRAJ_BOX_SHAPE, + "BOX SHAPE", + TNG_NON_PARTICLE_BLOCK_DATA, + TNG_GZIP_COMPRESSION)); } |