diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2014-05-27 10:55:32 (GMT) |
---|---|---|
committer | Magnus Lundborg <magnus.lundborg@scilifelab.se> | 2014-05-28 10:29:30 (GMT) |
commit | fab772c39bffd88692fdbdfe513733e91c277caa (patch) | |
tree | da5ce34b3b1713cacd297187be9fb3f5ff91c9e5 | |
parent | 58756626184437613b7fee705afc8e69077ea6fc (diff) |
Reread frame set after getting stride length.
After determining the stride length reread the current frame
set so that no data is skipped when reading a file.
Change-Id: I99c36b0cefe918ea39f22a559553d65b9a72a48f
-rw-r--r-- | src/lib/tng_io.c | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 92d728a..73431df 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -1028,6 +1028,40 @@ static tng_function_status tng_block_header_read // } */ +static tng_function_status tng_reread_frame_set_at_file_pos + (tng_trajectory_t tng_data, + const int64_t pos) +{ + tng_gen_block_t block; + tng_function_status stat; + + tng_block_init(&block); + + fseek(tng_data->input_file, pos, SEEK_SET); + if(pos > 0) + { + stat = tng_block_header_read(tng_data, block); + if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET) + { + fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", pos, + __FILE__, __LINE__); + tng_block_destroy(&block); + return(TNG_FAILURE); + } + + if(tng_block_read_next(tng_data, block, + TNG_SKIP_HASH) != TNG_SUCCESS) + { + tng_block_destroy(&block); + return(TNG_CRITICAL); + } + } + + tng_block_destroy(&block); + + return(TNG_SUCCESS); +} + static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get (tng_trajectory_t tng_data, int64_t *pos) @@ -1100,30 +1134,12 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get } /* Re-read the frame set that used to be the current one */ - fseek(tng_data->input_file, curr_frame_set_pos, SEEK_SET); - if(curr_frame_set_pos > 0) - { - stat = tng_block_header_read(tng_data, block); - if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET) - { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", *pos, - __FILE__, __LINE__); - tng_block_destroy(&block); - return(TNG_FAILURE); - } + tng_reread_frame_set_at_file_pos(tng_data, curr_frame_set_pos); - if(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) - { - tng_block_destroy(&block); - return(TNG_CRITICAL); - } - } + fseek(tng_data->input_file, orig_pos, SEEK_SET); tng_block_destroy(&block); - fseek(tng_data->input_file, orig_pos, SEEK_SET); - return(TNG_SUCCESS); } @@ -1223,30 +1239,12 @@ static tng_function_status tng_length_of_current_frame_set_contents_get } /* Re-read the frame set that used to be the current one */ - fseek(tng_data->input_file, curr_frame_set_pos, SEEK_SET); - if(curr_frame_set_pos > 0) - { - stat = tng_block_header_read(tng_data, block); - if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET) - { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - curr_frame_set_pos, __FILE__, __LINE__); - tng_block_destroy(&block); - return(TNG_FAILURE); - } + tng_reread_frame_set_at_file_pos(tng_data, curr_frame_set_pos); - if(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) - { - tng_block_destroy(&block); - return(TNG_CRITICAL); - } - } + fseek(tng_data->input_file, orig_pos, SEEK_SET); tng_block_destroy(&block); - fseek(tng_data->input_file, orig_pos, SEEK_SET); - return(TNG_SUCCESS); } @@ -16492,7 +16490,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get_stride_length tng_function_status stat; tng_non_particle_data_t np_data; tng_particle_data_t p_data; - long file_pos; + long orig_file_pos, file_pos; int is_particle_data; if(tng_data->current_trajectory_frame_set_input_file_pos <= 0) @@ -16508,6 +16506,7 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get_stride_length return(stat); } } + orig_file_pos = tng_data->current_trajectory_frame_set_input_file_pos; stat = tng_data_find(tng_data, block_id, &np_data); if(stat != TNG_SUCCESS) { @@ -16527,6 +16526,8 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get_stride_length } if(stat != TNG_SUCCESS) { + tng_reread_frame_set_at_file_pos(tng_data, orig_file_pos); + return(stat); } stat = tng_data_find(tng_data, block_id, &np_data); @@ -16535,6 +16536,8 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get_stride_length stat = tng_particle_data_find(tng_data, block_id, &p_data); if(stat != TNG_SUCCESS) { + tng_reread_frame_set_at_file_pos(tng_data, orig_file_pos); + return(stat); } else @@ -16564,6 +16567,8 @@ tng_function_status DECLSPECDLLEXPORT tng_data_get_stride_length { *stride_length = np_data->stride_length; } + tng_reread_frame_set_at_file_pos(tng_data, orig_file_pos); + return(TNG_SUCCESS); } |