summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tng_io.h20
-rw-r--r--src/lib/tng_io.c101
2 files changed, 107 insertions, 14 deletions
diff --git a/include/tng_io.h b/include/tng_io.h
index fb4efd6..27c8c7f 100644
--- a/include/tng_io.h
+++ b/include/tng_io.h
@@ -1076,6 +1076,8 @@ tng_function_status DECLSPECDLLEXPORT tng_input_file_len_get
* @param n is pointing to a value set to the number of frames.
* @pre \code tng_data != 0 \endcode The trajectory container (tng_data)
* must be initialised before using it.
+ * @pre \code tng_data->input_file != 0 \endcode An input file must be open
+ * to find the next frame set.
* @pre \code n != 0 \endcode The pointer to n must not be a NULL pointer.
* @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
* has occurred (could not find last frame set).
@@ -2102,6 +2104,24 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_first_frame_time_set
const double first_frame_time);
/**
+ * @brief Read the number of the first frame of the next frame set.
+ * @param tng_data is the trajectory containing the frame set.
+ * @param frame is set to the frame number of the first frame in the
+ * next frame set.
+ * @pre \code tng_data != 0 \endcode The trajectory container (tng_data)
+ * must be initialised before using it.
+ * @pre \code tng_data->input_file != 0 \endcode An input file must be open
+ * to find the next frame set.
+ * @pre \code frame != 0 \endcode The pointer to the frame must not be a NULL
+ * pointer.
+ * @return TNG_SUCCESS(0) if successful, TNG_FAILURE(1) if there is no next
+ * frame set or TNG_CRITICAL(2) if a major error has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get
+ (tng_trajectory_t tng_data,
+ int64_t *frame);
+
+/**
* @brief Add a non-particle dependent data block.
* @param tng_data is the trajectory data container in which to add the data
* block
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index 19e7cbd..2ecec72 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -3132,6 +3132,7 @@ static tng_function_status tng_frame_set_block_read
}
}
offset += sizeof(frame_set->next_frame_set_file_pos);
+ printf("NEXT FRAME SET FILE POS: %"PRId64"\n", frame_set->next_frame_set_file_pos);
memcpy(&frame_set->prev_frame_set_file_pos,
block->block_contents + offset,
@@ -9661,44 +9662,51 @@ tng_function_status DECLSPECDLLEXPORT tng_num_frames_get
{
tng_gen_block_t block;
tng_function_status stat;
- int64_t file_pos;
+ long file_pos;
+ int64_t last_file_pos, first_frame, n_frames;
TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
+ TNG_ASSERT(tng_data->input_file, "TNG library: An input file must be open to find the next frame set");
TNG_ASSERT(n, "TNG library: n must not be a NULL pointer");
- file_pos = tng_data->last_trajectory_frame_set_input_file_pos;
+ file_pos = ftell(tng_data->input_file);
+ last_file_pos = tng_data->last_trajectory_frame_set_input_file_pos;
- if(file_pos <= 0)
+ if(last_file_pos <= 0)
{
return(TNG_FAILURE);
}
tng_block_init(&block);
fseek(tng_data->input_file,
- (long)file_pos,
+ (long)last_file_pos,
SEEK_SET);
- tng_data->current_trajectory_frame_set_input_file_pos = (long)file_pos;
- /* Read block headers first to see what block is found. */
+ /* Read block headers first to see that a frame set block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
{
- printf("TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", file_pos,
+ printf("TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", last_file_pos,
__FILE__, __LINE__);
tng_block_destroy(&block);
return(TNG_FAILURE);
}
-
- stat = tng_block_read_next(tng_data, block,
- TNG_SKIP_HASH);
tng_block_destroy(&block);
- if(stat != TNG_SUCCESS)
+ if(fread(&first_frame, sizeof(int64_t), 1, tng_data->input_file) == 0)
{
- return(TNG_FAILURE);
+ printf("TNG library: Cannot read first frame of frame set. %s: %d\n",
+ __FILE__, __LINE__);
+ return(TNG_CRITICAL);
}
+ if(fread(&n_frames, sizeof(int64_t), 1, tng_data->input_file) == 0)
+ {
+ printf("TNG library: Cannot read n frames of frame set. %s: %d\n",
+ __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }
+ fseek(tng_data->input_file, file_pos, SEEK_SET);
- *n = tng_data->current_trajectory_frame_set.first_frame +
- tng_data->current_trajectory_frame_set.n_frames;
+ *n = first_frame + n_frames;
return(TNG_SUCCESS);
}
@@ -11191,6 +11199,8 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new
curr_pos = ftell(tng_data->output_file);
+ printf("NEW FRAME SET: %"PRId64", %"PRId64"\n", first_frame, n_frames);
+
if(curr_pos <= 10)
{
tng_file_headers_write(tng_data, TNG_USE_HASH);
@@ -11411,6 +11421,69 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_first_frame_time_set
return(TNG_SUCCESS);
}
+tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get
+ (tng_trajectory_t tng_data,
+ int64_t *frame)
+{
+ long file_pos, next_frame_set_file_pos;
+ tng_gen_block_t block;
+ tng_function_status stat;
+
+ tng_trajectory_frame_set_t frame_set;
+
+ TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
+ TNG_ASSERT(tng_data->input_file, "TNG library: An input file must be open to find the next frame set");
+ TNG_ASSERT(frame, "TNG library: frame must not be a NULL pointer");
+
+ printf("Current frame set file pos: %ld\n", tng_data->current_trajectory_frame_set_input_file_pos);
+
+ file_pos = ftell(tng_data->input_file);
+
+ if(tng_data->current_trajectory_frame_set_input_file_pos <= 0)
+ {
+ next_frame_set_file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
+ }
+ else
+ {
+ frame_set = &tng_data->current_trajectory_frame_set;
+ next_frame_set_file_pos = (long)frame_set->next_frame_set_file_pos;
+ printf("first frame %"PRId64", frames %"PRId64" \n", frame_set->first_frame, frame_set->n_frames);
+ }
+
+ printf("Next frame set file pos: %ld\n", next_frame_set_file_pos);
+
+ if(next_frame_set_file_pos <= 0)
+ {
+ return(TNG_FAILURE);
+ }
+
+ fseek(tng_data->input_file, next_frame_set_file_pos, SEEK_SET);
+ /* Read block headers first to see that a frame set block is found. */
+ tng_block_init(&block);
+ stat = tng_block_header_read(tng_data, block);
+ if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
+ {
+ printf("TNG library: Cannot read block header at pos %ld. %s: %d\n",
+ file_pos, __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }
+/* if(tng_data->current_trajectory_frame_set_input_file_pos <= 0)
+ {
+ tng_block_read_next(tng_data, block, TNG_USE_HASH);
+ }*/
+ tng_block_destroy(&block);
+
+ if(fread(frame, sizeof(int64_t), 1, tng_data->input_file) == 0)
+ {
+ printf("TNG library: Cannot read first frame of next frame set. %s: %d\n",
+ __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }
+ fseek(tng_data->input_file, file_pos, SEEK_SET);
+
+ return(TNG_SUCCESS);
+}
+
tng_function_status DECLSPECDLLEXPORT tng_data_block_add
(tng_trajectory_t tng_data,
const int64_t id,
contact: Jan Huwald // Impressum