diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-11-29 12:53:08 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-11-29 12:53:08 (GMT) |
commit | 5721dc29c3c2e0df5651303fe27f7a05fedda56e (patch) | |
tree | 87a8c253018ba2ec280b4589563755168d9a37b2 | |
parent | 88707939328087c5b439c072ae3c2bb0e4e1073c (diff) |
Added tng_util_next_frame_present_data_blocks_find()
Changed from tng_util_compression_next_frame_get() to
tng_util_compression_current_frame_get().
-rw-r--r-- | include/tng_io.h | 48 | ||||
-rw-r--r-- | src/lib/tng_io.c | 213 |
2 files changed, 240 insertions, 21 deletions
diff --git a/include/tng_io.h b/include/tng_io.h index e46cd60..3480007 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -4295,7 +4295,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_double_write /** * @brief High-level function for getting the compression method and - * multiplication factor of the next frame of a specific data block. + * multiplication factor of the last read frame of a specific data block. * @param tng_data is the trajectory to use. * @param block_id is the ID number of the block containing the data of * interest. @@ -4310,18 +4310,54 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_double_write * must not be a NULL pointer. * @pre \code factor != 0 \endcode The pointer to the returned multiplication * factor must not be a NULL pointer. - * @details This function reads ahead until a data block of the requested ID - * is found. * @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_compression_next_frame_get + */ +tng_function_status DECLSPECDLLEXPORT tng_util_compression_current_frame_get (tng_trajectory_t tng_data, const int64_t block_id, char *codec_id, float *factor); - + +/** @brief High-level function for determining the next frame with data and what + * data blocks have data for that frame. The search can be limited to certain + * data blocks. + * @param tng_data is the trajectory to use. + * @param current_frame is the frame that was last read, from where to start + * looking for data. + * @param n_requested_data_block_ids is the number of data blocks listed in + * requested_data_block_ids. If this is 0 all data blocks will be taken into + * account. + * @param requested_data_block_ids is an array of data blocks to look for. + * @param next_frame will be set to the next frame with data. + * @param n_data_blocks_in_next_frame is set to the number of data blocks with + * data for next_frame. + * @param data_block_ids_in_next_frame is an array (of length + * n_data_blocks_in_next_frame) that lists the data block IDs with data for + * next_frame. + * @pre \code tng_data != 0 \endcode The trajectory container (tng_data) + * must be initialised before using it. + * @pre \code next_frame != 0 \endcode The pointer to the next frame must not + * be NULL. + * @pre \code data_block_ids_in_next_frame != 0 \endcode The pointer to the + * list of data block IDs must not be NULL. + * @pre \code n_requested_data_block_ids == 0 || requested_data_block_ids != 0 \endcode + * If the number of requested data blocks != 0 then the array of data block IDs must not be NULL. + * @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_next_frame_present_data_blocks_find + (tng_trajectory_t tng_data, + int64_t current_frame, + const int64_t n_requested_data_block_ids, + const int64_t *requested_data_block_ids, + int64_t *next_frame, + int64_t *n_data_blocks_in_next_frame, + int64_t **data_block_ids_in_next_frame); + + /** @} */ /* end of group2 */ diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 0eb6d20..317c78e 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -17244,7 +17244,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_box_shape_with_time_double_write TNG_GZIP_COMPRESSION)); } -tng_function_status DECLSPECDLLEXPORT tng_util_compression_next_frame_get +tng_function_status DECLSPECDLLEXPORT tng_util_compression_current_frame_get (tng_trajectory_t tng_data, const int64_t block_id, char *codec_id, @@ -17255,7 +17255,6 @@ tng_function_status DECLSPECDLLEXPORT tng_util_compression_next_frame_get tng_non_particle_data_t np_data; tng_function_status stat; int64_t i; - long file_pos; int block_type = -1; TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); @@ -17279,16 +17278,6 @@ tng_function_status DECLSPECDLLEXPORT tng_util_compression_next_frame_get else { stat = tng_frame_set_read_current_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id); - file_pos = ftell(tng_data->input_file); - while(stat != TNG_SUCCESS && file_pos < tng_data->input_file_len) - { - stat = tng_frame_set_read_next_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id); - file_pos = ftell(tng_data->input_file); - } - if(stat != TNG_SUCCESS) - { - return(stat); - } stat = tng_particle_data_find(tng_data, block_id, &p_data); if(stat == TNG_SUCCESS) { @@ -17316,7 +17305,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_compression_next_frame_get } else { - i = p_data->last_retrieved_frame + p_data->stride_length; + i = p_data->last_retrieved_frame; } } else if(block_type == TNG_NON_PARTICLE_BLOCK_DATA) @@ -17327,7 +17316,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_compression_next_frame_get } else { - i = np_data->last_retrieved_frame + np_data->stride_length; + i = np_data->last_retrieved_frame; } } else @@ -17344,7 +17333,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_compression_next_frame_get stat = tng_frame_set_read_current_only_data_from_block_id(tng_data, TNG_USE_HASH, block_id); if(stat != TNG_SUCCESS) { - printf("Cannot read data blocks of frame set. %s: %d\n", + printf("Cannot read data block of frame set. %s: %d\n", __FILE__, __LINE__); return(stat); } @@ -17361,3 +17350,197 @@ tng_function_status DECLSPECDLLEXPORT tng_util_compression_next_frame_get } return(TNG_SUCCESS); } + +tng_function_status DECLSPECDLLEXPORT tng_util_next_frame_present_data_blocks_find + (tng_trajectory_t tng_data, + int64_t current_frame, + const int64_t n_requested_data_block_ids, + const int64_t *requested_data_block_ids, + int64_t *next_frame, + int64_t *n_data_blocks_in_next_frame, + int64_t **data_block_ids_in_next_frame) +{ + tng_trajectory_frame_set_t frame_set; + tng_function_status stat; + tng_particle_data_t p_data; + tng_non_particle_data_t np_data; + int64_t i, j, block_id, *temp; + int64_t data_first_frame, frame_diff, min_diff; + int found; + + TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); + TNG_ASSERT(next_frame, "TNG library: The pointer to the next frame must not be NULL."); + TNG_ASSERT(data_block_ids_in_next_frame, "TNG library: The pointer to the list of data block IDs must not be NULL."); + if(n_requested_data_block_ids) + { + TNG_ASSERT(requested_data_block_ids, "TNG library: If the number of requested data blocks is > 0 then the array of data block IDs must not be NULL."); + } + + frame_set = &tng_data->current_trajectory_frame_set; + + current_frame += 1; + + if(current_frame < frame_set->first_frame || + current_frame >= frame_set->first_frame + frame_set->n_frames) + { + stat = tng_frame_set_of_frame_find(tng_data, current_frame); + if(stat != TNG_SUCCESS) + { + return(stat); + } + } + + min_diff = -1; + + n_data_blocks_in_next_frame = 0; + + for(i = 0; i < frame_set->n_particle_data_blocks; i++) + { + p_data = &frame_set->tr_particle_data[i]; + block_id = p_data->block_id; + + if(n_requested_data_block_ids > 0) + { + found = 0; + for(j = 0; j < n_requested_data_block_ids; j++) + { + if(block_id == requested_data_block_ids[j]) + { + found = 1; + break; + } + } + if(!found) + { + continue; + } + } + + if(p_data->last_retrieved_frame < frame_set->first_frame || + p_data->last_retrieved_frame >= + frame_set->first_frame + frame_set->n_frames) + { + stat = tng_frame_set_read_current_only_data_from_block_id(tng_data, + TNG_USE_HASH, block_id); + if(stat != TNG_SUCCESS) + { + printf("Cannot read data block of frame set. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + } + data_first_frame = tng_max_i64(p_data->last_retrieved_frame, + p_data->first_frame_with_data); + frame_diff = current_frame - data_first_frame; + if(frame_diff < 0) + { + continue; + } + frame_diff = frame_diff % p_data->stride_length; + if(min_diff == -1 || frame_diff <= min_diff) + { + if(frame_diff < min_diff) + { + *n_data_blocks_in_next_frame = 1; + } + else + { + *n_data_blocks_in_next_frame += 1; + } + temp = realloc(*data_block_ids_in_next_frame, sizeof(int64_t) * + (*n_data_blocks_in_next_frame)); + if(!temp) + { + printf("TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", + sizeof(int64_t) * (*n_data_blocks_in_next_frame), + __FILE__, __LINE__); + free(*data_block_ids_in_next_frame); + *data_block_ids_in_next_frame = 0; + return(TNG_CRITICAL); + } + *data_block_ids_in_next_frame = temp; + + *data_block_ids_in_next_frame[*n_data_blocks_in_next_frame-1] = block_id; + + min_diff = frame_diff; + } + } + for(i = 0; i < frame_set->n_data_blocks; i++) + { + np_data = &frame_set->tr_data[i]; + block_id = np_data->block_id; + + if(n_requested_data_block_ids > 0) + { + found = 0; + for(j = 0; j < n_requested_data_block_ids; j++) + { + if(block_id == requested_data_block_ids[j]) + { + found = 1; + break; + } + } + if(!found) + { + continue; + } + } + + if(np_data->last_retrieved_frame < frame_set->first_frame || + np_data->last_retrieved_frame >= + frame_set->first_frame + frame_set->n_frames) + { + stat = tng_frame_set_read_current_only_data_from_block_id(tng_data, + TNG_USE_HASH, block_id); + if(stat != TNG_SUCCESS) + { + printf("Cannot read data block of frame set. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + } + data_first_frame = tng_max_i64(np_data->last_retrieved_frame, + np_data->first_frame_with_data); + frame_diff = current_frame - data_first_frame; + if(frame_diff < 0) + { + continue; + } + frame_diff = frame_diff % np_data->stride_length; + if(min_diff == -1 || frame_diff <= min_diff) + { + if(frame_diff < min_diff) + { + *n_data_blocks_in_next_frame = 1; + } + else + { + *n_data_blocks_in_next_frame += 1; + } + temp = realloc(*data_block_ids_in_next_frame, sizeof(int64_t) * + (*n_data_blocks_in_next_frame)); + if(!temp) + { + printf("TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", + sizeof(int64_t) * (*n_data_blocks_in_next_frame), + __FILE__, __LINE__); + free(*data_block_ids_in_next_frame); + *data_block_ids_in_next_frame = 0; + return(TNG_CRITICAL); + } + *data_block_ids_in_next_frame = temp; + + *data_block_ids_in_next_frame[*n_data_blocks_in_next_frame-1] = block_id; + + min_diff = frame_diff; + } + } + if(min_diff < 0) + { + return(TNG_FAILURE); + } + *next_frame = current_frame + min_diff; + + return(TNG_SUCCESS); +} |