From b4783da8473431eb91bc82861f49bcb402c6f163 Mon Sep 17 00:00:00 2001 From: Magnus Lundborg Date: Tue, 3 Dec 2013 13:51:23 +0100 Subject: Added function tng_data_block_num_values_per_frame_get() diff --git a/include/tng_io.h b/include/tng_io.h index eddfb5c..bca3978 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -2692,7 +2692,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_block_name_get /** @brief Get the dependency of a data block of a specific ID. * @param tng_data is the trajectory data container. * @param block_id is the ID of the data block of which to get the name. - * @param block_dependency is a pointer to the depency of the data block. + * @param block_dependency is a pointer to the dependency of the data block. * If the block is frame dependent it will be set to TNG_FRAME_DEPENDENT, * if it is particle dependent it will be set to TNG_PARTICLE_DEPENDENT and * if it is both it will be set to TNG_FRAME_DEPENDENT & TNG_PARTICLE_DEPENDENT. @@ -2709,6 +2709,23 @@ tng_function_status DECLSPECDLLEXPORT tng_data_block_dependency_get int64_t block_id, int *block_dependency); +/** @brief Get the number of values per frame of a data block of a specific ID. + * @param tng_data is the trajectory data container. + * @param block_id is the ID of the data block of which to get the name. + * @param n_values_per_frame is a pointer set to the number of values per frame. + * @pre \code tng_data != 0 \endcode The trajectory container (tng_data) + * must be initialised before using it. + * @pre \code n_values_per_frame != 0 \endcode The pointer to the number of values + * per frame must not be a NULL pointer. + * @return TNG_SUCCESS (0) if the data block is found, TNG_FAILURE (1) + * if a minor error has occured or the data block is not found or + * TNG_CRITICAL (2) if a major error has occured. + */ +tng_function_status DECLSPECDLLEXPORT tng_data_block_num_values_per_frame_get + (tng_trajectory_t tng_data, + int64_t block_id, + int *n_values_per_frame); + /** * @brief Write data of one trajectory frame to the output_file of tng_data. * @param tng_data is a trajectory data container. tng_data->output_file_path diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 5abce04..fa6d94a 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -12924,6 +12924,80 @@ tng_function_status DECLSPECDLLEXPORT tng_data_block_dependency_get return(TNG_FAILURE); } +tng_function_status DECLSPECDLLEXPORT tng_data_block_num_values_per_frame_get + (tng_trajectory_t tng_data, + int64_t block_id, + int *n_values_per_frame) +{ + int64_t i; + tng_function_status stat; + tng_particle_data_t p_data; + tng_non_particle_data_t np_data; + + TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); + TNG_ASSERT(n_values_per_frame, "TNG library: n_values_per_frame must not be a NULL pointer."); + + for(i = 0; i < tng_data->n_particle_data_blocks; i++) + { + p_data = &tng_data->non_tr_particle_data[i]; + if(p_data->block_id == block_id) + { + *n_values_per_frame = p_data->n_values_per_frame; + return(TNG_SUCCESS); + } + } + for(i = 0; i < tng_data->n_data_blocks; i++) + { + np_data = &tng_data->non_tr_data[i]; + if(np_data->block_id == block_id) + { + *n_values_per_frame = np_data->n_values_per_frame; + return(TNG_SUCCESS); + } + } + + stat = tng_particle_data_find(tng_data, block_id, &p_data); + if(stat == TNG_SUCCESS) + { + *n_values_per_frame = p_data->n_values_per_frame; + return(TNG_SUCCESS); + } + else + { + stat = tng_data_find(tng_data, block_id, &np_data); + if(stat == TNG_SUCCESS) + { + *n_values_per_frame = np_data->n_values_per_frame; + return(TNG_SUCCESS); + } + else + { + stat = tng_frame_set_read_current_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id); + if(stat != TNG_SUCCESS) + { + return(stat); + } + stat = tng_particle_data_find(tng_data, block_id, &p_data); + if(stat == TNG_SUCCESS) + { + *n_values_per_frame = p_data->n_values_per_frame; + return(TNG_SUCCESS); + } + else + { + stat = tng_data_find(tng_data, block_id, &np_data); + if(stat == TNG_SUCCESS) + { + *n_values_per_frame = np_data->n_values_per_frame; + return(TNG_SUCCESS); + } + } + } + } + + return(TNG_FAILURE); +} + tng_function_status DECLSPECDLLEXPORT tng_frame_data_write (tng_trajectory_t tng_data, const int64_t frame_nr, -- cgit v0.10.1