diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-10-28 15:27:51 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-10-28 15:27:51 (GMT) |
commit | 5e2aa20f61229654d06111e6086ce8d417a7664b (patch) | |
tree | b464a29f72fd1f4b5432eac87b70f48f2925dfb8 | |
parent | e2131c7ee45d9b0aefc3f9304fd7851978cc4b51 (diff) |
Added utility functions for writing double precision data.
-rw-r--r-- | include/tng_io.h | 306 | ||||
-rw-r--r-- | src/lib/tng_io.c | 504 |
2 files changed, 796 insertions, 14 deletions
diff --git a/include/tng_io.h b/include/tng_io.h index 3bec8a9..2ab3e04 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -2316,6 +2316,38 @@ tng_function_status DECLSPECDLLEXPORT tng_util_generic_write_interval_set const char compression); /** + * @brief High-level function for setting the writing interval of data blocks + * containing double precision data. + * @param tng_data is the trajectory to use. + * @param i is the output interval, i.e. i == 10 means data written every 10th + * 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. + * @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_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i, + 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 setting the writing interval of data blocks. * Obsolete! Use tng_util_generic_write_interval_set() * @param tng_data is the trajectory to use. @@ -2367,6 +2399,22 @@ tng_function_status DECLSPECDLLEXPORT tng_util_pos_write_interval_set /** * @brief High-level function for setting the writing interval of position + * data blocks containing double precision data. + * @param tng_data is the trajectory to use. + * @param i is the output interval, i.e. i == 10 means data written every 10th + * frame. + * @details This function uses tng_util_generic_write_interval_set() and will + * create a positions data block if none exists. + * @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_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i); + +/** + * @brief High-level function for setting the writing interval of position * data blocks. Obsolete! Use tng_util_pos_write_interval_set() * @param tng_data is the trajectory to use. * @param i is the output interval, i.e. i == 10 means data written every 10th @@ -2401,6 +2449,22 @@ tng_function_status DECLSPECDLLEXPORT tng_util_vel_write_interval_set /** * @brief High-level function for setting the writing interval of velocity + * data blocks containing double precision data. + * @param tng_data is the trajectory to use. + * @param i is the output interval, i.e. i == 10 means data written every 10th + * frame. + * @details This function uses tng_util_generic_write_interval_set() and will + * create a velocities data block if none exists. + * @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_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i); + +/** + * @brief High-level function for setting the writing interval of velocity * data blocks. Obsolete! Use tng_util_vel_write_interval_set() * @param tng_data is the trajectory to use. * @param i is the output interval, i.e. i == 10 means data written every 10th @@ -2435,6 +2499,22 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_write_interval_set /** * @brief High-level function for setting the writing interval of force + * data blocks containing double precision data. + * @param tng_data is the trajectory to use. + * @param i is the output interval, i.e. i == 10 means data written every 10th + * frame. + * @details This function uses tng_util_generic_write_interval_set() and will + * create a forces data block if none exists. + * @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_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i); + +/** + * @brief High-level function for setting the writing interval of force * data blocks. Obsolete! Use tng_util_force_write_interval_set() * @param tng_data is the trajectory to use. * @param i is the output interval, i.e. i == 10 means data written every 10th @@ -2468,6 +2548,22 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write_interval_set const int64_t i); /** + * @brief High-level function for setting the writing interval of box shape + * data blocks containing double precision data. + * @param tng_data is the trajectory to use. + * @param i is the output interval, i.e. i == 10 means data written every 10th + * frame. + * @details This function uses tng_util_generic_write_interval_set() and will + * create a box shape data block if none exists. + * @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_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i); + +/** * @brief High-level function for setting the writing interval of velocity * data blocks. Obsolete! Use tng_util_box_shape_write_interval_set() * @param tng_data is the trajectory to use. @@ -2523,6 +2619,44 @@ tng_function_status DECLSPECDLLEXPORT tng_util_generic_write const char compression); /** + * @brief High-level function for writing data of one frame to a double precision + * data block. + * @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. * @param tng_data is the trajectory to use. * @param frame_nr is the frame number of the data. @@ -2544,6 +2678,28 @@ tng_function_status DECLSPECDLLEXPORT tng_util_pos_write const float *positions); /** + * @brief High-level function for adding data to positions data blocks at double + * precision. + * @param tng_data is the trajectory to use. + * @param frame_nr is the frame number of the data. + * @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_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *positions); + +/** * @brief High-level function for adding data to velocities data blocks. * @param tng_data is the trajectory to use. * @param frame_nr is the frame number of the data. @@ -2565,6 +2721,28 @@ tng_function_status DECLSPECDLLEXPORT tng_util_vel_write const float *velocities); /** + * @brief High-level function for adding data to velocities data blocks at double + * precision. + * @param tng_data is the trajectory to use. + * @param frame_nr is the frame number of the data. + * @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_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *velocities); + +/** * @brief High-level function for adding data to forces data blocks. * @param tng_data is the trajectory to use. * @param frame_nr is the frame number of the data. @@ -2586,6 +2764,28 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_write const float *forces); /** + * @brief High-level function for adding data to forces data blocks at double + * precision. + * @param tng_data is the trajectory to use. + * @param frame_nr is the frame number of the data. + * @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_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *forces); + +/** * @brief High-level function for adding data to box shape data blocks. * @param tng_data is the trajectory to use. * @param frame_nr is the frame number of the data. @@ -2606,6 +2806,27 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write const float *box_shape); /** + * @brief High-level function for adding data to box shape data blocks at double + * precision. + * @param tng_data is the trajectory to use. + * @param frame_nr is the frame number of the data. + * @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_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *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. @@ -2631,6 +2852,31 @@ tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_write const float *positions); /** + * @brief High-level function for adding data to positions data blocks at double + * precision. 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 seconds). + * @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_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double time, + const double *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. @@ -2656,6 +2902,31 @@ tng_function_status DECLSPECDLLEXPORT tng_util_vel_with_time_write const float *velocities); /** + * @brief High-level function for adding data to velocities data blocks at + * double precision. 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 seconds). + * @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_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double time, + const double *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. @@ -2681,9 +2952,34 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_write 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. + * @brief High-level function for adding data to forces data blocks at + * double precision. 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 seconds). + * @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_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double time, + const double *forces); + +/** + * @brief High-level function for adding data to box shape data blocks at + * double precision. 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 seconds). @@ -2698,11 +2994,11 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_write * 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_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_double_write (tng_trajectory_t tng_data, const int64_t frame_nr, const double time, - const float *box_shape); + const double *box_shape); /** @} */ /* end of group2 */ diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 8bb8f43..e0e34c3 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -15053,6 +15053,124 @@ tng_function_status DECLSPECDLLEXPORT tng_util_generic_write_interval_set return(TNG_SUCCESS); } +tng_function_status DECLSPECDLLEXPORT tng_util_generic_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i, + const int64_t n_values_per_frame, + const int64_t block_id, + const char *block_name, + const char particle_dependency, + const char compression) +{ + tng_trajectory_frame_set_t frame_set; + tng_particle_data_t p_data; + tng_non_particle_data_t np_data; + int64_t n_particles, n_frames = 100*i; + tng_function_status stat; + + stat = tng_check_trajectory_container(tng_data); + if(stat != TNG_SUCCESS) + { + printf("Trajectory container not properly setup. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + + if(i <= 0) + { + printf("Cannot set writing frequency to %"PRId64". %s: %d\n", + i, __FILE__, __LINE__); + return(TNG_FAILURE); + } + + frame_set = &tng_data->current_trajectory_frame_set; + + if(!frame_set || tng_data->n_trajectory_frame_sets <= 0) + { + stat = tng_frame_set_new(tng_data, 0, n_frames); + if(stat != TNG_SUCCESS) + { + printf("Cannot create frame set. %s: %d\n", __FILE__, + __LINE__); + return(stat); + } + } + else + { + n_frames = frame_set->n_frames; + } + + if(particle_dependency == TNG_PARTICLE_BLOCK_DATA) + { + tng_num_particles_get(tng_data, &n_particles); + + if(tng_particle_data_find(tng_data, block_id, &p_data) + != TNG_SUCCESS) + { + stat = tng_particle_data_block_add(tng_data, block_id, + block_name, + TNG_DOUBLE_DATA, + TNG_TRAJECTORY_BLOCK, + n_frames, n_values_per_frame, i, + 0, n_particles, + compression, 0); + if(stat != TNG_SUCCESS) + { + printf("Error %s adding data block. %s: %d\n", block_name, + __FILE__, __LINE__); + return(stat); + } + p_data = &frame_set->tr_particle_data[frame_set-> + n_particle_data_blocks - 1]; + stat = tng_allocate_particle_data_mem(tng_data, p_data, n_frames, + i, n_particles, + n_values_per_frame); + if(stat != TNG_SUCCESS) + { + printf("Error allocating particle data memory. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + } + else + { + p_data->stride_length = i; + } + } + else + { + if(tng_data_find(tng_data, block_id, &np_data) != TNG_SUCCESS) + { + stat = tng_data_block_add(tng_data, block_id, block_name, + TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK, + n_frames, n_values_per_frame, + i, compression, 0); + if(stat != TNG_SUCCESS) + { + printf("Error %s adding data block. %s: %d\n", block_name, + __FILE__, __LINE__); + return(stat); + } + np_data = &frame_set->tr_data[frame_set-> + n_data_blocks - 1]; + stat = tng_allocate_data_mem(tng_data, np_data, n_frames, + i, n_values_per_frame); + if(stat != TNG_SUCCESS) + { + printf("Error allocating particle data memory. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + } + else + { + np_data->stride_length = i; + } + } + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_util_generic_write_frequency_set (tng_trajectory_t tng_data, const int64_t i, @@ -15062,7 +15180,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_generic_write_frequency_set const char particle_dependency, const char compression) { - printf("Using obsolete function tng_util_generic_write_frequency_set()." + printf("Using obsolete function tng_util_generic_write_frequency_set(). " "See documentation. %s: %d", __FILE__, __LINE__); return(tng_util_generic_write_interval_set(tng_data, i, n_values_per_frame, block_id, block_name, @@ -15080,11 +15198,22 @@ tng_function_status DECLSPECDLLEXPORT tng_util_pos_write_interval_set TNG_TNG_COMPRESSION)); } +tng_function_status DECLSPECDLLEXPORT tng_util_pos_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i) +{ + return(tng_util_generic_write_interval_double_set(tng_data, i, 3, + TNG_TRAJ_POSITIONS, + "POSITIONS", + TNG_PARTICLE_BLOCK_DATA, + TNG_TNG_COMPRESSION)); +} + tng_function_status DECLSPECDLLEXPORT tng_util_pos_write_frequency_set (tng_trajectory_t tng_data, const int64_t i) { - printf("Using obsolete function tng_util_pos_write_frequency_set()." + printf("Using obsolete function tng_util_pos_write_frequency_set(). " "See documentation. %s: %d", __FILE__, __LINE__); return(tng_util_pos_write_interval_set(tng_data, i)); } @@ -15100,11 +15229,22 @@ tng_function_status DECLSPECDLLEXPORT tng_util_vel_write_interval_set TNG_TNG_COMPRESSION)); } +tng_function_status DECLSPECDLLEXPORT tng_util_vel_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i) +{ + return(tng_util_generic_write_interval_double_set(tng_data, i, 3, + TNG_TRAJ_VELOCITIES, + "VELOCITIES", + TNG_PARTICLE_BLOCK_DATA, + TNG_TNG_COMPRESSION)); +} + tng_function_status DECLSPECDLLEXPORT tng_util_vel_write_frequency_set (tng_trajectory_t tng_data, const int64_t i) { - printf("Using obsolete function tng_util_vel_write_frequency_set()." + printf("Using obsolete function tng_util_vel_write_frequency_set(). " "See documentation. %s: %d", __FILE__, __LINE__); return(tng_util_vel_write_interval_set(tng_data, i)); } @@ -15120,11 +15260,22 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_write_interval_set TNG_GZIP_COMPRESSION)); } +tng_function_status DECLSPECDLLEXPORT tng_util_force_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i) +{ + return(tng_util_generic_write_interval_double_set(tng_data, i, 3, + TNG_TRAJ_FORCES, + "FORCES", + TNG_PARTICLE_BLOCK_DATA, + TNG_GZIP_COMPRESSION)); +} + tng_function_status DECLSPECDLLEXPORT tng_util_force_write_frequency_set (tng_trajectory_t tng_data, const int64_t i) { - printf("Using obsolete function tng_util_force_write_frequency_set()." + printf("Using obsolete function tng_util_force_write_frequency_set(). " "See documentation. %s: %d", __FILE__, __LINE__); return(tng_util_force_write_interval_set(tng_data, i)); } @@ -15134,17 +15285,28 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write_interval_set const int64_t i) { return(tng_util_generic_write_interval_set(tng_data, i, 9, - TNG_TRAJ_BOX_SHAPE, - "BOX SHAPE", - TNG_NON_PARTICLE_BLOCK_DATA, - TNG_GZIP_COMPRESSION)); + TNG_TRAJ_BOX_SHAPE, + "BOX SHAPE", + TNG_NON_PARTICLE_BLOCK_DATA, + TNG_GZIP_COMPRESSION)); +} + +tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write_interval_double_set + (tng_trajectory_t tng_data, + const int64_t i) +{ + return(tng_util_generic_write_interval_double_set(tng_data, i, 9, + TNG_TRAJ_BOX_SHAPE, + "BOX SHAPE", + TNG_NON_PARTICLE_BLOCK_DATA, + TNG_GZIP_COMPRESSION)); } tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write_frequency_set (tng_trajectory_t tng_data, const int64_t i) { - printf("Using obsolete function tng_util_box_shape_write_frequency_set()." + printf("Using obsolete function tng_util_box_shape_write_frequency_set(). " "See documentation. %s: %d", __FILE__, __LINE__); return(tng_util_box_shape_write_interval_set(tng_data, i)); } @@ -15337,6 +15499,194 @@ tng_function_status DECLSPECDLLEXPORT tng_util_generic_write return(TNG_SUCCESS); } +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) +{ + tng_trajectory_frame_set_t frame_set; + tng_particle_data_t p_data; + tng_non_particle_data_t np_data; + int64_t n_particles, n_frames = 10000, stride_length = 100, frame_pos; + char block_type_flag; + tng_function_status stat; + + stat = tng_check_trajectory_container(tng_data); + if(stat != TNG_SUCCESS) + { + printf("Trajectory container not properly setup. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + + if(values == 0) + { + return(TNG_FAILURE); + } + + frame_set = &tng_data->current_trajectory_frame_set; + + if(frame_nr < 0) + { + block_type_flag = TNG_NON_TRAJECTORY_BLOCK; + n_frames = stride_length = 1; + } + else + { + block_type_flag = TNG_TRAJECTORY_BLOCK; + + if(!frame_set || tng_data->n_trajectory_frame_sets <= 0) + { + stat = tng_frame_set_new(tng_data, 0, n_frames); + if(stat != TNG_SUCCESS) + { + printf("Cannot create frame set. %s: %d\n", __FILE__, + __LINE__); + return(stat); + } + } + else + { + n_frames = frame_set->n_frames; + } + if(frame_nr >= frame_set->first_frame + n_frames) + { + stat = tng_frame_set_write(tng_data, TNG_USE_HASH); + if(stat != TNG_SUCCESS) + { + printf("Cannot write frame set. %s: %d\n", __FILE__, + __LINE__); + return(stat); + } + stat = tng_frame_set_new(tng_data, frame_set->first_frame + + frame_set->n_frames, n_frames); + if(stat != TNG_SUCCESS) + { + printf("Cannot create frame set. %s: %d\n", __FILE__, + __LINE__); + return(stat); + } + } + frame_set->n_unwritten_frames = frame_nr - + frame_set->first_frame + 1; + } + + if(particle_dependency == TNG_PARTICLE_BLOCK_DATA) + { + tng_num_particles_get(tng_data, &n_particles); + + if(tng_particle_data_find(tng_data, block_id, &p_data) + != TNG_SUCCESS) + { + stat = tng_particle_data_block_add(tng_data, block_id, + block_name, + TNG_DOUBLE_DATA, + block_type_flag, + n_frames, n_values_per_frame, + stride_length, + 0, n_particles, + compression, 0); + if(stat != TNG_SUCCESS) + { + printf("Error %s adding data block. %s: %d\n", block_name, + __FILE__, __LINE__); + return(stat); + } + if(block_type_flag == TNG_TRAJECTORY_BLOCK) + { + p_data = &frame_set->tr_particle_data[frame_set-> + n_particle_data_blocks - 1]; + } + else + { + p_data = &tng_data->non_tr_particle_data[tng_data-> + n_particle_data_blocks - 1]; + } + stat = tng_allocate_particle_data_mem(tng_data, p_data, n_frames, + stride_length, n_particles, + n_values_per_frame); + if(stat != TNG_SUCCESS) + { + printf("Error allocating particle data memory. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + } + + if(block_type_flag == TNG_TRAJECTORY_BLOCK) + { + stride_length = p_data->stride_length; + + frame_pos = (frame_nr - frame_set->first_frame) / stride_length; + + memcpy((char *)p_data->values + sizeof(float) * frame_pos * n_particles * + n_values_per_frame, values, sizeof(float) * + n_particles * n_values_per_frame); + } + else + { + memcpy(p_data->values, values, sizeof(float) * n_particles * + n_values_per_frame); + } + } + else + { + if(tng_data_find(tng_data, block_id, &np_data) != TNG_SUCCESS) + { + stat = tng_data_block_add(tng_data, block_id, block_name, + TNG_DOUBLE_DATA, block_type_flag, + n_frames, n_values_per_frame, + stride_length, compression, 0); + if(stat != TNG_SUCCESS) + { + printf("Error %s adding data block. %s: %d\n", block_name, + __FILE__, __LINE__); + return(stat); + } + if(block_type_flag == TNG_TRAJECTORY_BLOCK) + { + np_data = &frame_set->tr_data[frame_set-> + n_data_blocks - 1]; + } + else + { + np_data = &tng_data->non_tr_data[tng_data-> + n_data_blocks - 1]; + } + stat = tng_allocate_data_mem(tng_data, np_data, n_frames, + stride_length, n_values_per_frame); + if(stat != TNG_SUCCESS) + { + printf("Error allocating particle data memory. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + } + + if(block_type_flag == TNG_TRAJECTORY_BLOCK) + { + stride_length = np_data->stride_length; + + frame_pos = (frame_nr - frame_set->first_frame) / stride_length; + + memcpy((char *)np_data->values + sizeof(float) * frame_pos * + n_values_per_frame, values, sizeof(float) * + n_values_per_frame); + } + else + { + memcpy(np_data->values, values, sizeof(float) * n_values_per_frame); + } + } + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_util_pos_write (tng_trajectory_t tng_data, const int64_t frame_nr, @@ -15348,6 +15698,17 @@ tng_function_status DECLSPECDLLEXPORT tng_util_pos_write TNG_TNG_COMPRESSION)); } +tng_function_status DECLSPECDLLEXPORT tng_util_pos_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *positions) +{ + return(tng_util_generic_double_write(tng_data, frame_nr, positions, 3, + TNG_TRAJ_POSITIONS, "POSITIONS", + TNG_PARTICLE_BLOCK_DATA, + TNG_TNG_COMPRESSION)); +} + tng_function_status DECLSPECDLLEXPORT tng_util_vel_write (tng_trajectory_t tng_data, const int64_t frame_nr, @@ -15359,6 +15720,17 @@ tng_function_status DECLSPECDLLEXPORT tng_util_vel_write TNG_TNG_COMPRESSION)); } +tng_function_status DECLSPECDLLEXPORT tng_util_vel_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *velocities) +{ + return(tng_util_generic_double_write(tng_data, frame_nr, velocities, 3, + TNG_TRAJ_VELOCITIES, "VELOCITIES", + TNG_PARTICLE_BLOCK_DATA, + TNG_TNG_COMPRESSION)); +} + tng_function_status DECLSPECDLLEXPORT tng_util_force_write (tng_trajectory_t tng_data, const int64_t frame_nr, @@ -15370,6 +15742,17 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_write TNG_GZIP_COMPRESSION)); } +tng_function_status DECLSPECDLLEXPORT tng_util_force_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *forces) +{ + return(tng_util_generic_double_write(tng_data, frame_nr, forces, 3, + TNG_TRAJ_FORCES, "FORCES", + TNG_PARTICLE_BLOCK_DATA, + TNG_GZIP_COMPRESSION)); +} + tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write (tng_trajectory_t tng_data, const int64_t frame_nr, @@ -15381,6 +15764,17 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_write TNG_GZIP_COMPRESSION)); } +tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + const double *box_shape) +{ + return(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)); +} + tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_write (tng_trajectory_t tng_data, const int64_t frame_nr, @@ -15404,6 +15798,29 @@ tng_function_status DECLSPECDLLEXPORT tng_util_pos_with_time_write return(stat); } +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) +{ + 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); + 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, @@ -15427,6 +15844,29 @@ tng_function_status DECLSPECDLLEXPORT tng_util_vel_with_time_write return(stat); } +tng_function_status DECLSPECDLLEXPORT tng_util_vel_with_time_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + 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); +} + tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_write (tng_trajectory_t tng_data, const int64_t frame_nr, @@ -15450,6 +15890,29 @@ tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_write return(stat); } +tng_function_status DECLSPECDLLEXPORT tng_util_force_with_time_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + 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); +} + tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_write (tng_trajectory_t tng_data, const int64_t frame_nr, @@ -15473,3 +15936,26 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_write return(stat); } +tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_double_write + (tng_trajectory_t tng_data, + const int64_t frame_nr, + 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); +} + |