// return(TNG_SUCCESS);
// }
*/
+
+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);
+}
+
/** Write the header of a data block, regardless of its type
* @param tng_data is a trajectory data container.
* @param block is a general block container.
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)
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)
{
}
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);
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
{
*stride_length = np_data->stride_length;
}
+ tng_reread_frame_set_at_file_pos(tng_data, orig_file_pos);
+
return(TNG_SUCCESS);
}
}
else
{
- i = data->last_retrieved_frame + data->stride_length;
+ if(data->n_frames == 1)
+ {
+ i = data->last_retrieved_frame + 1;
+ }
+ else
+ {
+ i = data->last_retrieved_frame + data->stride_length;
+ }
if(i < frame_set->first_frame || i >= frame_set->first_frame + frame_set->n_frames)
{
stat = tng_frame_set_of_frame_find(tng_data, i);
}
else
{
- i = data->last_retrieved_frame + data->stride_length;
+ if(data->n_frames == 1)
+ {
+ i = data->last_retrieved_frame + 1;
+ }
+ else
+ {
+ i = data->last_retrieved_frame + data->stride_length;
+ }
if(i < frame_set->first_frame || i >= frame_set->first_frame + frame_set->n_frames)
{
stat = tng_frame_set_of_frame_find(tng_data, i);
}
}
- if(frame_set->n_particle_data_blocks <= 0 || frame_set->n_data_blocks <= 0)
+ /* If no data blocks have been found in the frame set check what data blocks
+ * are present. If they have already been found do not read them again. */
+ if(frame_set->n_particle_data_blocks <= 0 && frame_set->n_data_blocks <= 0)
{
- tng_block_init(&block);
file_pos = ftell(tng_data->input_file);
/* Read all blocks until next frame set block */
- stat = tng_block_header_read(tng_data, block);
- while(file_pos < tng_data->input_file_len &&
- stat != TNG_CRITICAL &&
- block->id != TNG_TRAJECTORY_FRAME_SET)
+ if(file_pos < tng_data->input_file_len)
{
- stat = tng_block_read_next(tng_data, block,
- TNG_USE_HASH);
- if(stat != TNG_CRITICAL)
+ tng_block_init(&block);
+ stat = tng_block_header_read(tng_data, block);
+ while(file_pos < tng_data->input_file_len &&
+ stat != TNG_CRITICAL &&
+ block->id != TNG_TRAJECTORY_FRAME_SET)
{
- file_pos = ftell(tng_data->input_file);
- if(file_pos < tng_data->input_file_len)
+ stat = tng_block_read_next(tng_data, block,
+ TNG_USE_HASH);
+ if(stat != TNG_CRITICAL)
{
- stat = tng_block_header_read(tng_data, block);
+ file_pos = ftell(tng_data->input_file);
+ if(file_pos < tng_data->input_file_len)
+ {
+ stat = tng_block_header_read(tng_data, block);
+ }
}
}
- }
- tng_block_destroy(&block);
- if(stat == TNG_CRITICAL)
- {
- fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
- file_pos, __FILE__, __LINE__);
- return(stat);
+ tng_block_destroy(&block);
+ if(stat == TNG_CRITICAL)
+ {
+ fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+ file_pos, __FILE__, __LINE__);
+ return(stat);
+ }
}
read_all = 1;
}