* modify it under the terms of the Revised BSD License.
*/
+#define _FILE_OFFSET_BITS 64
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+#define _LARGEFILE_SOURCE
+/* Define for large files, on AIX-style hosts. */
+#define _LARGE_FILES
+
+#include "tng/tng_io.h"
+
#ifdef USE_STD_INTTYPES_H
#include <inttypes.h>
#endif
#include <zlib.h>
#endif
-#include "../../include/tng_io.h"
-#include "../../include/md5.h"
-#include "../../include/compression/tng_compress.h"
-#include "../include/version.h"
-
+#include "tng/md5.h"
+#include "compression/tng_compress.h"
+#include "tng/version.h"
+
+#if defined( _WIN32 ) || defined( _WIN64 )
+ #ifndef fseeko
+ #define fseeko _fseeki64
+ #endif
+ #ifndef ftello
+ #ifdef __MINGW32__
+ #define ftello ftello64
+ #else
+ #define ftello _ftelli64
+ #endif
+ #endif
+#endif
struct tng_bond {
/** One of the atoms of the bond */
/** A handle to the input file */
FILE *input_file;
/** The length of the input file */
- long input_file_len;
+ int64_t input_file_len;
/** The path of the output trajectory file */
char *output_file_path;
/** A handle to the output file */
/** The currently active frame set */
struct tng_trajectory_frame_set current_trajectory_frame_set;
/** The pos in the src file of the current frame set */
- long current_trajectory_frame_set_input_file_pos;
+ int64_t current_trajectory_frame_set_input_file_pos;
/** The pos in the dest file of the current frame set */
- long current_trajectory_frame_set_output_file_pos;
+ int64_t current_trajectory_frame_set_output_file_pos;
/** The number of frame sets in the trajectory N.B. Not saved in file and
* cannot be trusted to be up-to-date */
int64_t n_trajectory_frame_sets;
*block_p = malloc(sizeof(struct tng_gen_block));
if(!*block_p)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
sizeof(struct tng_gen_block), __FILE__, __LINE__);
return(TNG_CRITICAL);
}
static tng_function_status tng_block_header_read
(tng_trajectory_t tng_data, tng_gen_block_t block)
{
- int len, offset = 0;
+ int len;
+ int64_t offset = 0;
TNG_ASSERT(block != 0, "TNG library: Trying to read to uninitialized block (NULL pointer).");
}
/* If this was the size of the general info block check the endianness */
- if(ftell(tng_data->input_file) < 9)
+ if(ftello(tng_data->input_file) < 9)
{
/* File is little endian */
if ( *((const char*)&block->header_contents_size) != 0x00 &&
}
/* Move the reading position to the beginning of the header. */
- fseek(tng_data->input_file, -(long)sizeof(block->header_contents_size),
- SEEK_CUR);
+ fseeko(tng_data->input_file, -(int64_t)sizeof(block->header_contents_size),
+ SEEK_CUR);
/* If there is already memory allocated for the contents free it (we do not
* know if the size is correct). */
return(TNG_CRITICAL);
}
- fseek(tng_data->output_file, (long)contents_start_pos, SEEK_SET);
+ fseeko(tng_data->output_file, contents_start_pos, SEEK_SET);
if(fread(block->block_contents, block->block_contents_size, 1,
tng_data->output_file) == 0)
{
tng_block_md5_hash_generate(block);
- fseek(tng_data->output_file, (long)header_start_pos + 3 * sizeof(int64_t),
+ fseeko(tng_data->output_file, header_start_pos + 3 * sizeof(int64_t),
SEEK_SET);
fwrite(block->md5_hash, TNG_MD5_HASH_LEN, 1, tng_data->output_file);
tng_block_init(&block);
- output_file_pos = ftell(tng_data->output_file);
- fseek(tng_data->output_file, 0, SEEK_SET);
+ output_file_pos = ftello(tng_data->output_file);
+ fseeko(tng_data->output_file, 0, SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
{
return(TNG_CRITICAL);
}
- contents_start_pos = ftell(tng_data->output_file);
+ contents_start_pos = ftello(tng_data->output_file);
- fseek(tng_data->output_file, (long)block->block_contents_size - 5 *
+ fseeko(tng_data->output_file, block->block_contents_size - 5 *
sizeof(int64_t), SEEK_CUR);
tng_data->input_file = temp;
tng_block_destroy(&block);
- fseek(tng_data->output_file, (long)output_file_pos, SEEK_SET);
+ fseeko(tng_data->output_file, output_file_pos, SEEK_SET);
return(TNG_SUCCESS);
}
}
tng_block_init(&block);
- output_file_pos = ftell(tng_data->output_file);
+ output_file_pos = ftello(tng_data->output_file);
tng_data->input_file = tng_data->output_file;
/* Update next frame set */
if(frame_set->next_frame_set_file_pos > 0)
{
- fseek(tng_data->output_file, (long)frame_set->next_frame_set_file_pos,
+ fseeko(tng_data->output_file, frame_set->next_frame_set_file_pos,
SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
return(TNG_CRITICAL);
}
- contents_start_pos = ftell(tng_data->output_file);
+ contents_start_pos = ftello(tng_data->output_file);
- fseek(tng_data->output_file, (long)block->block_contents_size - (5 *
+ fseeko(tng_data->output_file, block->block_contents_size - (5 *
sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
if(tng_data->input_endianness_swap_func_64)
tng_md5_hash_update(tng_data, block, frame_set->next_frame_set_file_pos,
contents_start_pos);
}
- fseek(tng_data->output_file, (long)output_file_pos, SEEK_SET);
+ fseeko(tng_data->output_file, output_file_pos, SEEK_SET);
}
/* Update previous frame set */
if(frame_set->prev_frame_set_file_pos > 0)
{
- fseek(tng_data->output_file, (long)frame_set->prev_frame_set_file_pos,
+ fseeko(tng_data->output_file, frame_set->prev_frame_set_file_pos,
SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
return(TNG_CRITICAL);
}
- contents_start_pos = ftell(tng_data->output_file);
+ contents_start_pos = ftello(tng_data->output_file);
- fseek(tng_data->output_file, (long)block->block_contents_size - (6 *
+ fseeko(tng_data->output_file, block->block_contents_size - (6 *
sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
if(tng_data->input_endianness_swap_func_64)
tng_md5_hash_update(tng_data, block, frame_set->prev_frame_set_file_pos,
contents_start_pos);
}
- fseek(tng_data->output_file, (long)output_file_pos, SEEK_SET);
+ fseeko(tng_data->output_file, output_file_pos, SEEK_SET);
}
/* Update the frame set one medium stride step after */
if(frame_set->medium_stride_next_frame_set_file_pos > 0)
{
- fseek(tng_data->output_file,
- (long)frame_set->medium_stride_next_frame_set_file_pos,
- SEEK_SET);
+ fseeko(tng_data->output_file,
+ frame_set->medium_stride_next_frame_set_file_pos,
+ SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
{
return(TNG_CRITICAL);
}
- contents_start_pos = ftell(tng_data->output_file);
+ contents_start_pos = ftello(tng_data->output_file);
- fseek(tng_data->output_file, (long)block->block_contents_size - (3 *
+ fseeko(tng_data->output_file, block->block_contents_size - (3 *
sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
if(tng_data->input_endianness_swap_func_64)
/* Update the frame set one medium stride step before */
if(frame_set->medium_stride_prev_frame_set_file_pos > 0)
{
- fseek(tng_data->output_file,
- (long)frame_set->medium_stride_prev_frame_set_file_pos,
- SEEK_SET);
+ fseeko(tng_data->output_file,
+ frame_set->medium_stride_prev_frame_set_file_pos,
+ SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
{
return(TNG_CRITICAL);
}
- contents_start_pos = ftell(tng_data->output_file);
+ contents_start_pos = ftello(tng_data->output_file);
- fseek(tng_data->output_file, (long)block->block_contents_size - (4 *
+ fseeko(tng_data->output_file, block->block_contents_size - (4 *
sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
if(tng_data->input_endianness_swap_func_64)
/* Update the frame set one long stride step after */
if(frame_set->long_stride_next_frame_set_file_pos > 0)
{
- fseek(tng_data->output_file,
- (long)frame_set->long_stride_next_frame_set_file_pos,
- SEEK_SET);
+ fseeko(tng_data->output_file,
+ frame_set->long_stride_next_frame_set_file_pos,
+ SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
{
return(TNG_CRITICAL);
}
- contents_start_pos = ftell(tng_data->output_file);
+ contents_start_pos = ftello(tng_data->output_file);
- fseek(tng_data->output_file, (long)block->block_contents_size - (1 *
- sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
+ fseeko(tng_data->output_file, block->block_contents_size - (1 *
+ sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
if(tng_data->input_endianness_swap_func_64)
{
/* Update the frame set one long stride step before */
if(frame_set->long_stride_prev_frame_set_file_pos > 0)
{
- fseek(tng_data->output_file,
- (long)frame_set->long_stride_prev_frame_set_file_pos,
- SEEK_SET);
+ fseeko(tng_data->output_file,
+ frame_set->long_stride_prev_frame_set_file_pos,
+ SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
{
return(TNG_CRITICAL);
}
- contents_start_pos = ftell(tng_data->output_file);
+ contents_start_pos = ftello(tng_data->output_file);
- fseek(tng_data->output_file, (long)block->block_contents_size - (2 *
+ fseeko(tng_data->output_file, block->block_contents_size - (2 *
sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
if(tng_data->input_endianness_swap_func_64)
}
}
- fseek(tng_data->output_file, (long)output_file_pos, SEEK_SET);
+ fseeko(tng_data->output_file, output_file_pos, SEEK_SET);
tng_data->input_file = temp;
tng_block_init(&block);
- fseek(tng_data->input_file, pos, SEEK_SET);
+ fseeko(tng_data->input_file, pos, SEEK_SET);
if(pos > 0)
{
stat = tng_block_header_read(tng_data, block);
tng_trajectory_frame_set_t frame_set =
&tng_data->current_trajectory_frame_set;
- orig_pos = ftell(tng_data->input_file);
+ orig_pos = ftello(tng_data->input_file);
curr_frame_set_pos = tng_data->current_trajectory_frame_set_input_file_pos;
*pos = tng_data->first_trajectory_frame_set_input_file_pos;
return(TNG_SUCCESS);
}
- fseek(tng_data->input_file, *pos, SEEK_SET);
+ fseeko(tng_data->input_file, *pos, SEEK_SET);
tng_block_init(&block);
/* Read block headers first to see that a frame set block is found. */
/* Read all frame set blocks (not the blocks between them) */
while(frame_set->next_frame_set_file_pos > 0)
{
- fseek(tng_data->input_file, frame_set->next_frame_set_file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, frame_set->next_frame_set_file_pos, SEEK_SET);
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL)
{
/* Re-read the frame set that used to be the current one */
tng_reread_frame_set_at_file_pos(tng_data, curr_frame_set_pos);
- fseek(tng_data->input_file, orig_pos, SEEK_SET);
+ fseeko(tng_data->input_file, orig_pos, SEEK_SET);
tng_block_destroy(&block);
return(TNG_CRITICAL);
}
- fseek(tng_data->input_file, block_start_pos, SEEK_SET);
+ fseeko(tng_data->input_file, block_start_pos, SEEK_SET);
contents = malloc(block_len);
if(!contents)
free(contents);
return(TNG_CRITICAL);
}
- fseek(tng_data->output_file, new_pos, SEEK_SET);
+ fseeko(tng_data->output_file, new_pos, SEEK_SET);
if(fwrite(contents, block_len, 1, tng_data->output_file) != 1)
{
{
contents[i] = '\0';
}
- fseek(tng_data->output_file, block_start_pos, SEEK_SET);
+ fseeko(tng_data->output_file, block_start_pos, SEEK_SET);
/* FIXME: casting block_len to size_t is dangerous */
fwrite(contents, 1, block_len, tng_data->output_file);
tng_gen_block_t block;
tng_function_status stat;
- orig_pos = ftell(tng_data->input_file);
+ orig_pos = ftello(tng_data->input_file);
curr_frame_set_pos = pos = tng_data->current_trajectory_frame_set_input_file_pos;
*len = 0;
- fseek(tng_data->input_file, curr_frame_set_pos, SEEK_SET);
+ fseeko(tng_data->input_file, curr_frame_set_pos, SEEK_SET);
tng_block_init(&block);
/* Read block headers first to see that a frame set block is found. */
/* Read the headers of all blocks in the frame set (not the actual contents of them) */
while(stat == TNG_SUCCESS)
{
- fseek(tng_data->input_file, block->block_contents_size, SEEK_CUR);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
*len += block->header_contents_size + block->block_contents_size;
pos += block->header_contents_size + block->block_contents_size;
if(pos >= tng_data->input_file_len)
/* Re-read the frame set that used to be the current one */
tng_reread_frame_set_at_file_pos(tng_data, curr_frame_set_pos);
- fseek(tng_data->input_file, orig_pos, SEEK_SET);
+ fseeko(tng_data->input_file, orig_pos, SEEK_SET);
tng_block_destroy(&block);
return(TNG_SUCCESS);
}
- orig_file_pos = ftell(tng_data->input_file);
+ orig_file_pos = ftello(tng_data->input_file);
tng_block_init(&block);
while(empty_space < offset)
{
- fseek(tng_data->input_file, traj_start_pos, SEEK_SET);
+ fseeko(tng_data->input_file, traj_start_pos, SEEK_SET);
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL)
{
empty_space += frame_set_length;
}
- fseek(tng_data->input_file, orig_file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, orig_file_pos, SEEK_SET);
tng_block_destroy(&block);
return(TNG_SUCCESS);
if(tng_data->input_endianness_swap_func_64)
{
if(tng_data->input_endianness_swap_func_64(tng_data,
- &tng_data->long_stride_length)
+ &tng_data->long_stride_length)
!= TNG_SUCCESS)
{
fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n",
return(TNG_CRITICAL);
}
- fseek(tng_data->output_file, 0, SEEK_SET);
+ fseeko(tng_data->output_file, 0, SEEK_SET);
tng_block_init(&block);
sizeof(struct tng_molecule));
if(!tng_data->molecules)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
tng_data->n_molecules * sizeof(struct tng_molecule),
__FILE__, __LINE__);
return(TNG_CRITICAL);
tng_data->n_molecules);
if(!tng_data->molecule_cnt_list)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
tng_data->n_molecules * sizeof(struct tng_molecule),
__FILE__, __LINE__);
return(TNG_CRITICAL);
sizeof(struct tng_chain));
if(!molecule->chains)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
molecule->n_chains * sizeof(struct tng_chain),
__FILE__, __LINE__);
return(TNG_CRITICAL);
sizeof(struct tng_residue));
if(!molecule->residues)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
molecule->n_residues * sizeof(struct tng_residue),
__FILE__, __LINE__);
if(molecule->chains)
sizeof(struct tng_atom));
if(!molecule->atoms)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
molecule->n_atoms * sizeof(struct tng_atom),
__FILE__, __LINE__);
if(molecule->chains)
sizeof(struct tng_bond));
if(!molecule->bonds)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
molecule->n_bonds * sizeof(struct tng_bond),
__FILE__, __LINE__);
if(molecule->chains)
tng_gen_block_t block,
const char hash_mode)
{
- long file_pos;
int offset = 0;
- int64_t i, prev_n_particles;
+ int64_t file_pos, i, prev_n_particles;
tng_bool same_hash;
tng_trajectory_frame_set_t frame_set =
&tng_data->current_trajectory_frame_set;
/* FIXME: Does not check if the size of the contents matches the expected
* size or if the contents can be read. */
- file_pos = (int64_t)ftell(tng_data->input_file) -
- (long)(block->block_contents_size + block->header_contents_size);
+ file_pos = (int64_t)ftello(tng_data->input_file) -
+ (block->block_contents_size + block->header_contents_size);
if(hash_mode == TNG_USE_HASH)
{
tng_md5_hash_match_verify(block, &same_hash);
if(same_hash != TNG_TRUE)
{
- fprintf(stderr, "TNG library: Frame set block contents corrupt. File pos %ld Hashes do not match. "
+ fprintf(stderr, "TNG library: Frame set block contents corrupt. File pos %"PRId64" Hashes do not match. "
"%s: %d\n",
file_pos, __FILE__, __LINE__);
/* return(TNG_FAILURE); */
if(!frame_set->molecule_cnt_list)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * tng_data->n_molecules,
__FILE__, __LINE__);
return(TNG_CRITICAL);
temp_name = realloc(block->name, name_len + 1);
if(!temp_name)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n",
name_len+1, __FILE__, __LINE__);
free(block->name);
block->name = 0;
sizeof(int64_t));
if(!mapping->real_particle_numbers)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
mapping->n_particles * sizeof(int64_t), __FILE__, __LINE__);
return(TNG_CRITICAL);
}
temp_name = realloc(block->name, name_len + 1);
if(!temp_name)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n",
name_len+1, __FILE__, __LINE__);
free(block->name);
block->name = 0;
frame_set->n_particle_data_blocks);
if(!data)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
sizeof(struct tng_particle_data) *
frame_set->n_particle_data_blocks,
__FILE__, __LINE__);
tng_data->n_particle_data_blocks);
if(!data)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
sizeof(struct tng_particle_data) *
tng_data->n_particle_data_blocks,
__FILE__, __LINE__);
int nalgo;
int new_len;
int *alt_algo = 0;
- char *dest, *temp;
- int64_t algo_find_n_frames;
- unsigned long offset;
+ char *dest, *temp, *temp_data_contents;
+ int64_t algo_find_n_frames, compressed_len, offset;
float f_precision;
double d_precision;
f_precision = 1/(float)tng_data->compression_precision;
d_precision = 1/tng_data->compression_precision;
+ compressed_len = block->block_contents_size - (int64_t)((char *)start_pos - (char *)block->block_contents);
+ temp_data_contents = malloc(compressed_len);
+ if(!temp_data_contents)
+ {
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ compressed_len, __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }
+
+ memcpy(temp_data_contents, (char *)start_pos, compressed_len);
+
if(block->id == TNG_TRAJ_POSITIONS)
{
/* If there is only one frame in this frame set and there might be more
alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_pos);
if(type == TNG_FLOAT_DATA)
{
- dest = tng_compress_pos_float_find_algo(start_pos, (int)n_particles,
+ dest = tng_compress_pos_float_find_algo((float *)temp_data_contents, (int)n_particles,
(int)n_frames,
f_precision,
0, alt_algo,
}
else
{
- dest = tng_compress_pos_find_algo(start_pos, (int)n_particles,
+ dest = tng_compress_pos_find_algo((double *)temp_data_contents, (int)n_particles,
(int)n_frames,
d_precision,
0, alt_algo,
sizeof *tng_data->compress_algo_pos);
if(type == TNG_FLOAT_DATA)
{
- dest = tng_compress_pos_float_find_algo(start_pos, (int)n_particles,
+ dest = tng_compress_pos_float_find_algo((float *)temp_data_contents, (int)n_particles,
(int)algo_find_n_frames,
f_precision,
0, tng_data->
if(algo_find_n_frames < n_frames)
{
- dest = tng_compress_pos_float(start_pos, (int)n_particles,
+ dest = tng_compress_pos_float((float *)temp_data_contents, (int)n_particles,
(int)n_frames,
f_precision,
0, tng_data->compress_algo_pos,
}
else
{
- dest = tng_compress_pos_find_algo(start_pos, (int)n_particles,
+ dest = tng_compress_pos_find_algo((double *)temp_data_contents, (int)n_particles,
(int)algo_find_n_frames,
d_precision,
0, tng_data->
if(algo_find_n_frames < n_frames)
{
- dest = tng_compress_pos(start_pos, (int)n_particles,
+ dest = tng_compress_pos((double *)temp_data_contents, (int)n_particles,
(int)n_frames,
d_precision, 0,
tng_data->compress_algo_pos,
{
if(type == TNG_FLOAT_DATA)
{
- dest = tng_compress_pos_float(start_pos, (int)n_particles,
+ dest = tng_compress_pos_float((float *)temp_data_contents, (int)n_particles,
(int)n_frames,
f_precision, 0,
tng_data->compress_algo_pos, &new_len);
}
else
{
- dest = tng_compress_pos(start_pos, (int)n_particles,
+ dest = tng_compress_pos((double *)temp_data_contents, (int)n_particles,
(int)n_frames,
d_precision, 0,
tng_data->compress_algo_pos,
if(n_frames == 1 && tng_data->frame_set_n_frames > 1)
{
nalgo = tng_compress_nalgo();
- alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_pos);
+ alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_vel);
if(type == TNG_FLOAT_DATA)
{
- dest = tng_compress_vel_float_find_algo(start_pos, (int)n_particles,
+ dest = tng_compress_vel_float_find_algo((float *)temp_data_contents, (int)n_particles,
(int)n_frames,
f_precision,
0, alt_algo,
}
else
{
- dest = tng_compress_vel_find_algo(start_pos, (int)n_particles,
+ dest = tng_compress_vel_find_algo((double *)temp_data_contents, (int)n_particles,
(int)n_frames,
d_precision,
0, alt_algo,
if(type == TNG_FLOAT_DATA)
{
- dest = tng_compress_vel_float_find_algo(start_pos, (int)n_particles,
+ dest = tng_compress_vel_float_find_algo((float *)temp_data_contents, (int)n_particles,
(int)algo_find_n_frames,
f_precision,
0, tng_data->
&new_len);
if(algo_find_n_frames < n_frames)
{
- dest = tng_compress_vel_float(start_pos, (int)n_particles,
+ dest = tng_compress_vel_float((float *)temp_data_contents, (int)n_particles,
(int)n_frames,
f_precision,
0, tng_data->compress_algo_vel,
}
else
{
- dest = tng_compress_vel_find_algo(start_pos, (int)n_particles,
+ dest = tng_compress_vel_find_algo((double *)temp_data_contents, (int)n_particles,
(int)algo_find_n_frames,
d_precision,
0, tng_data->
&new_len);
if(algo_find_n_frames < n_frames)
{
- dest = tng_compress_vel(start_pos, (int)n_particles,
+ dest = tng_compress_vel((double *)temp_data_contents, (int)n_particles,
(int)n_frames,
d_precision,
0, tng_data->compress_algo_vel,
{
if(type == TNG_FLOAT_DATA)
{
- dest = tng_compress_vel_float(start_pos, (int)n_particles,
+ dest = tng_compress_vel_float((float *)temp_data_contents, (int)n_particles,
(int)n_frames,
f_precision,
0, tng_data->
}
else
{
- dest = tng_compress_vel(start_pos, (int)n_particles,
+ dest = tng_compress_vel((double *)temp_data_contents, (int)n_particles,
(int)n_frames,
d_precision,
0, tng_data->
else
{
fprintf(stderr, "TNG library: Can only compress positions and velocities using TNG-MF1 algorithms.\n");
+ free(temp_data_contents);
return(TNG_FAILURE);
}
block->block_contents_size = new_len + offset;
+ free(temp_data_contents);
+
temp = realloc(block->block_contents, block->block_contents_size);
if(!temp)
{
tng_gen_block_t block,
const char type,
void *start_pos,
- const unsigned long uncompressed_len)
+ const int64_t uncompressed_len)
{
- char *temp;
+ char *temp, *temp_data_contents;
+ int64_t compressed_len;
double *d_dest = 0;
float *f_dest = 0;
- unsigned long offset;
+ int64_t offset;
int result;
(void)tng_data;
return(TNG_FAILURE);
}
+ compressed_len = block->block_contents_size - (int64_t)((char *)start_pos - (char *)block->block_contents);
+ temp_data_contents = malloc(compressed_len);
+ if(!temp_data_contents)
+ {
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ uncompressed_len, __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }
+
+ memcpy(temp_data_contents, (char *)start_pos, compressed_len);
+
if(type == TNG_FLOAT_DATA)
{
f_dest = malloc(uncompressed_len);
if(!f_dest)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
uncompressed_len, __FILE__, __LINE__);
+ free(temp_data_contents);
return(TNG_CRITICAL);
}
- result = tng_compress_uncompress_float(start_pos, f_dest);
+ result = tng_compress_uncompress_float(temp_data_contents, f_dest);
}
else
{
d_dest = malloc(uncompressed_len);
if(!d_dest)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
uncompressed_len, __FILE__, __LINE__);
+ free(temp_data_contents);
return(TNG_CRITICAL);
}
- result = tng_compress_uncompress(start_pos, d_dest);
+ result = tng_compress_uncompress(temp_data_contents, d_dest);
}
if(result == 1)
{
fprintf(stderr, "TNG library: Cannot uncompress TNG compressed block.\n");
+ free(temp_data_contents);
return(TNG_FAILURE);
}
}
fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
block->block_contents_size, __FILE__, __LINE__);
+ free(temp_data_contents);
return(TNG_CRITICAL);
}
block->block_contents = temp;
+ free(temp_data_contents);
if(d_dest)
{
free(d_dest);
dest = malloc(max_len);
if(!dest)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%ld bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
max_len, __FILE__, __LINE__);
return(TNG_CRITICAL);
}
n_particles);
if(!data->strings[i])
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(union data_values *) * n_particles,
__FILE__, __LINE__);
return(TNG_CRITICAL);
n_values_per_frame);
if(!data->strings[i][j])
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(union data_values) * n_values_per_frame,
__FILE__, __LINE__);
return(TNG_CRITICAL);
{
int64_t i, j, k, tot_n_particles, n_frames_div;
int size, len;
- unsigned long data_size;
+ int64_t data_size;
char ***first_dim_values, **second_dim_values;
tng_particle_data_t data;
tng_trajectory_frame_set_t frame_set =
TNG_ASSERT(offset != 0, "TNG library: offset must not be a NULL pointer.");
+ /* This must be caught early to avoid creating a data block if not necessary. */
+#ifndef USE_ZLIB
+ if(codec_id == TNG_GZIP_COMPRESSION)
+ {
+ fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__,
+ __LINE__);
+ return(TNG_FAILURE);
+ }
+#endif
+
switch(datatype)
{
case TNG_CHAR_DATA:
temp_name = realloc(block->name, len);
if(!temp_name)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lud bytes). %s: %d\n", len,
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", len,
__FILE__, __LINE__);
free(block->name);
block->name = 0;
frame_set->n_data_blocks);
if(!data)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
sizeof(struct tng_non_particle_data) * frame_set->n_data_blocks,
__FILE__, __LINE__);
free(frame_set->tr_data);
tng_data->n_data_blocks);
if(!data)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
sizeof(struct tng_non_particle_data) * tng_data->n_data_blocks,
__FILE__, __LINE__);
free(tng_data->non_tr_data);
int64_t i, j, n_frames_div;
int size, len;
#ifdef USE_ZLIB
- unsigned long data_size;
+ int64_t data_size;
#endif
tng_non_particle_data_t data;
tng_trajectory_frame_set_t frame_set =
/* fprintf(stderr, "TNG library: %s\n", block->name);*/
+ /* This must be caught early to avoid creating a data block if not necessary. */
+#ifndef USE_ZLIB
+ if(codec_id == TNG_GZIP_COMPRESSION)
+ {
+ fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__,
+ __LINE__);
+ return(TNG_FAILURE);
+ }
+#endif
+
switch(datatype)
{
case TNG_CHAR_DATA:
temp_name = realloc(block->name, len);
if(!temp_name)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", len+1,
+ fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n", len+1,
__FILE__, __LINE__);
free(block->name);
block->name = 0;
// }
//
// tng_block_init(&block);
-// // output_file_pos = ftell(tng_data->output_file);
+// // output_file_pos = ftello(tng_data->output_file);
//
// tng_data->input_file = tng_data->output_file;
//
// pos = tng_data->current_trajectory_frame_set_output_file_pos;
//
-// fseek(tng_data->output_file, pos, SEEK_SET);
+// fseeko(tng_data->output_file, pos, SEEK_SET);
// if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
// {
// fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n",
// return(TNG_CRITICAL);
// }
//
-// contents_start_pos = ftell(tng_data->output_file);
+// contents_start_pos = ftello(tng_data->output_file);
//
-// fseek(tng_data->output_file, 0, SEEK_END);
-// output_file_len = ftell(tng_data->output_file);
+// fseeko(tng_data->output_file, 0, SEEK_END);
+// output_file_len = ftello(tng_data->output_file);
// pos = contents_start_pos + block->block_contents_size;
-// fseek(tng_data->output_file, pos,
+// fseeko(tng_data->output_file, pos,
// SEEK_SET);
//
// while(pos < output_file_len)
// return(TNG_CRITICAL);
// }
// pos += block->header_contents_size + block->block_contents_size;
-// fseek(tng_data->output_file, pos, SEEK_SET);
+// fseeko(tng_data->output_file, pos, SEEK_SET);
// }
//
// return(TNG_SUCCESS);
}
tng_block_init(&block);
-/* output_file_pos = ftell(tng_data->output_file); */
+/* output_file_pos = ftello(tng_data->output_file); */
tng_data->input_file = tng_data->output_file;
pos = tng_data->current_trajectory_frame_set_output_file_pos;
- fseek(tng_data->output_file, (long)pos, SEEK_SET);
+ fseeko(tng_data->output_file, pos, SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
{
return(TNG_CRITICAL);
}
- contents_start_pos = ftell(tng_data->output_file);
+ contents_start_pos = ftello(tng_data->output_file);
- fseek(tng_data->output_file, sizeof(frame_set->first_frame), SEEK_CUR);
+ fseeko(tng_data->output_file, sizeof(frame_set->first_frame), SEEK_CUR);
if(fwrite(&frame_set->n_written_frames, sizeof(frame_set->n_frames),
1, tng_data->output_file) != 1)
{
pos + block->header_contents_size);
}
- fseek(tng_data->output_file, 0, SEEK_END);
- output_file_len = ftell(tng_data->output_file);
+ fseeko(tng_data->output_file, 0, SEEK_END);
+ output_file_len = ftello(tng_data->output_file);
pos = contents_start_pos + block->block_contents_size;
- fseek(tng_data->output_file, (long)pos, SEEK_SET);
+ fseeko(tng_data->output_file, pos, SEEK_SET);
while(pos < output_file_len)
{
pos + block->header_contents_size);
}
pos += block->header_contents_size + block->block_contents_size;
- fseek(tng_data->output_file, (long)pos, SEEK_SET);
+ fseeko(tng_data->output_file, pos, SEEK_SET);
}
tng_data->input_file = temp;
return(TNG_SUCCESS);
}
+tng_function_status DECLSPECDLLEXPORT tng_version_major
+ (const tng_trajectory_t tng_data,
+ int *version)
+{
+ (void)tng_data;
+
+ *version = TNG_VERSION_MAJOR;
+
+ return(TNG_SUCCESS);
+}
+
+tng_function_status DECLSPECDLLEXPORT tng_version_minor
+ (const tng_trajectory_t tng_data,
+ int *version)
+{
+ (void)tng_data;
+
+ *version = TNG_VERSION_MINOR;
+
+ return(TNG_SUCCESS);
+}
+
+tng_function_status DECLSPECDLLEXPORT tng_version_patchlevel
+ (const tng_trajectory_t tng_data,
+ int *patch_level)
+{
+ (void)tng_data;
+
+ *patch_level = TNG_VERSION_PATCHLEVEL;
+
+ return(TNG_SUCCESS);
+}
+
+tng_function_status DECLSPECDLLEXPORT tng_version
+ (const tng_trajectory_t tng_data,
+ char *version,
+ const int max_len)
+{
+ (void)tng_data;
+ TNG_ASSERT(version, "TNG library: version must not be a NULL pointer");
+
+ TNG_SNPRINTF(version, max_len, "%s", TNG_VERSION);
+
+ return(TNG_SUCCESS);
+}
+
tng_function_status DECLSPECDLLEXPORT tng_molecule_add
(tng_trajectory_t tng_data,
const char *name,
if(!new_molecules)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(struct tng_molecule) * (tng_data->n_molecules + 1),
__FILE__, __LINE__);
free(tng_data->molecules);
if(!new_molecule_cnt_list)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * (tng_data->n_molecules + 1),
__FILE__, __LINE__);
free(tng_data->molecule_cnt_list);
if(!new_molecules)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(struct tng_molecule) * (tng_data->n_molecules + 1),
__FILE__, __LINE__);
free(tng_data->molecules);
if(!new_molecule_cnt_list)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * (tng_data->n_molecules + 1),
__FILE__, __LINE__);
free(tng_data->molecule_cnt_list);
sizeof(struct tng_molecule) * tng_data_src->n_molecules);
if(!molecule_temp)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(struct tng_molecule) * tng_data_src->n_molecules,
__FILE__, __LINE__);
free(tng_data_dest->molecules);
sizeof(int64_t) * tng_data_src->n_molecules);
if(!list_temp)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * tng_data_src->n_molecules,
__FILE__, __LINE__);
free(tng_data_dest->molecule_cnt_list);
}
}
molecule_temp->n_bonds = molecule->n_bonds;
- bond_temp = realloc(molecule_temp->bonds, sizeof(struct tng_bond) *
- molecule->n_bonds);
- if(!bond_temp)
- {
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
- sizeof(struct tng_bond) * molecule->n_bonds,
- __FILE__, __LINE__);
- free(molecule_temp->bonds);
- molecule_temp->n_bonds = 0;
- return(TNG_CRITICAL);
- }
- molecule_temp->bonds = bond_temp;
- for(j = 0; j < molecule->n_bonds; j++)
+ if(molecule->n_bonds > 0)
{
- molecule_temp->bonds[j] = molecule->bonds[j];
+ bond_temp = realloc(molecule_temp->bonds, sizeof(struct tng_bond) *
+ molecule->n_bonds);
+ if(!bond_temp)
+ {
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
+ sizeof(struct tng_bond) * molecule->n_bonds,
+ __FILE__, __LINE__);
+ free(molecule_temp->bonds);
+ molecule_temp->n_bonds = 0;
+ return(TNG_CRITICAL);
+ }
+ molecule_temp->bonds = bond_temp;
+ for(j = 0; j < molecule->n_bonds; j++)
+ {
+ molecule_temp->bonds[j] = molecule->bonds[j];
+ }
}
stat = tng_molecule_cnt_set(tng_data_dest, molecule_temp,
tng_data_src->molecule_cnt_list[i]);
if(!new_chains)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(struct tng_chain) * (molecule->n_chains + 1),
__FILE__, __LINE__);
free(molecule->chains);
if(!new_bonds)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(struct tng_bond) * (molecule->n_bonds + 1),
__FILE__, __LINE__);
*bond = 0;
if(!new_residues)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(struct tng_residue) * (molecule->n_residues + 1),
__FILE__, __LINE__);
free(molecule->residues);
if(!new_atoms)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(struct tng_atom) * (molecule->n_atoms + 1),
__FILE__, __LINE__);
free(molecule->atoms);
*molecule_p = malloc(sizeof(struct tng_molecule));
if(!*molecule_p)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
sizeof(struct tng_molecule), __FILE__, __LINE__);
return(TNG_CRITICAL);
}
*from_atoms = malloc(sizeof(int64_t) * (*n_bonds));
if(!*from_atoms)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * (*n_bonds), __FILE__, __LINE__);
return(TNG_CRITICAL);
}
*to_atoms = malloc(sizeof(int64_t) * (*n_bonds));
if(!*to_atoms)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * (*n_bonds), __FILE__, __LINE__);
free(*from_atoms);
*from_atoms = 0;
if(!mapping)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(struct tng_particle_mapping)*frame_set->n_mapping_blocks,
__FILE__, __LINE__);
free(frame_set->mappings);
frame_set->mappings[frame_set->n_mapping_blocks - 1].real_particle_numbers = malloc(sizeof(int64_t) * n_particles);
if(!frame_set->mappings[frame_set->n_mapping_blocks - 1].real_particle_numbers)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * n_particles, __FILE__, __LINE__);
return(TNG_CRITICAL);
}
*tng_data_p = malloc(sizeof(struct tng_trajectory));
if(!*tng_data_p)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
sizeof(struct tng_trajectory), __FILE__, __LINE__);
return(TNG_CRITICAL);
}
*dest_p = malloc(sizeof(struct tng_trajectory));
if(!*dest_p)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n",
sizeof(struct tng_trajectory), __FILE__, __LINE__);
return(TNG_CRITICAL);
}
/* Tne endianness cannot be changed if the data has already been written
* to the output file. */
- if(ftell(tng_data->output_file) > 0)
+ if(ftello(tng_data->output_file) > 0)
{
return(TNG_FAILURE);
}
{
tng_gen_block_t block;
tng_function_status stat;
- long file_pos;
- int64_t last_file_pos, first_frame, n_frames;
+ int64_t file_pos, 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 = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
last_file_pos = tng_data->last_trajectory_frame_set_input_file_pos;
if(last_file_pos <= 0)
}
tng_block_init(&block);
- fseek(tng_data->input_file,
- (long)last_file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ last_file_pos,
+ SEEK_SET);
/* 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)
__FILE__, __LINE__);
return(TNG_CRITICAL);
}
- fseek(tng_data->input_file, file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
*n = first_frame + n_frames;
int64_t *n)
{
int64_t long_stride_length, medium_stride_length;
- long file_pos, orig_frame_set_file_pos;
+ int64_t file_pos, orig_frame_set_file_pos;
tng_trajectory_frame_set_t frame_set;
- struct tng_trajectory_frame_set orig_frame_set;
+ struct tng_trajectory_frame_set orig_frame_set;
tng_gen_block_t block;
tng_function_status stat;
int64_t cnt = 0;
frame_set = &tng_data->current_trajectory_frame_set;
orig_frame_set_file_pos = tng_data->current_trajectory_frame_set_input_file_pos;
- file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+ file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
+
+ if(file_pos < 0)
+ {
+ *n = tng_data->n_trajectory_frame_sets = cnt;
+ return(TNG_SUCCESS);
+ }
tng_block_init(&block);
- fseek(tng_data->input_file,
+ fseeko(tng_data->input_file,
file_pos,
SEEK_SET);
tng_data->current_trajectory_frame_set_input_file_pos = file_pos;
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 %ld. %s: %d\n", file_pos,
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", file_pos,
__FILE__, __LINE__);
tng_block_destroy(&block);
return(TNG_CRITICAL);
/* Take long steps forward until a long step forward would be too long or
* the last frame set is found */
- file_pos = (long)frame_set->long_stride_next_frame_set_file_pos;
+ file_pos = frame_set->long_stride_next_frame_set_file_pos;
while(file_pos > 0)
{
if(file_pos > 0)
{
cnt += long_stride_length;
- fseek(tng_data->input_file, file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
/* Read block headers first to see what block is found. */
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 %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
tng_block_destroy(&block);
return(TNG_CRITICAL);
return(TNG_CRITICAL);
}
}
- file_pos = (long)frame_set->long_stride_next_frame_set_file_pos;
+ file_pos = frame_set->long_stride_next_frame_set_file_pos;
}
/* Take medium steps forward until a medium step forward would be too long
* or the last frame set is found */
- file_pos = (long)frame_set->medium_stride_next_frame_set_file_pos;
+ file_pos = frame_set->medium_stride_next_frame_set_file_pos;
while(file_pos > 0)
{
if(file_pos > 0)
{
cnt += medium_stride_length;
- fseek(tng_data->input_file,
+ fseeko(tng_data->input_file,
file_pos,
SEEK_SET);
/* Read block headers first to see what block is found. */
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 %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
tng_block_destroy(&block);
return(TNG_CRITICAL);
return(TNG_CRITICAL);
}
}
- file_pos = (long)frame_set->medium_stride_next_frame_set_file_pos;
+ file_pos = frame_set->medium_stride_next_frame_set_file_pos;
}
/* Take one step forward until the last frame set is found */
- file_pos = (long)frame_set->next_frame_set_file_pos;
+ file_pos = frame_set->next_frame_set_file_pos;
while(file_pos > 0)
{
if(file_pos > 0)
{
++cnt;
- fseek(tng_data->input_file,
+ fseeko(tng_data->input_file,
file_pos,
SEEK_SET);
/* Read block headers first to see what block is found. */
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 %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
tng_block_destroy(&block);
return(TNG_CRITICAL);
return(TNG_CRITICAL);
}
}
- file_pos = (long)frame_set->next_frame_set_file_pos;
+ file_pos = frame_set->next_frame_set_file_pos;
}
tng_block_destroy(&block);
*n = tng_data->n_trajectory_frame_sets = cnt;
*frame_set = orig_frame_set;
+ /* The mapping block in the original frame set has been freed when reading
+ * other frame sets. */
+ frame_set->mappings = 0;
+ frame_set->n_mapping_blocks = 0;
- fseek(tng_data->input_file,
- (long)tng_data->first_trajectory_frame_set_input_file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ tng_data->first_trajectory_frame_set_input_file_pos,
+ SEEK_SET);
tng_data->current_trajectory_frame_set_input_file_pos = orig_frame_set_file_pos;
}
tng_block_init(&block);
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
- tng_data->current_trajectory_frame_set_input_file_pos = (long)file_pos;
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
+ tng_data->current_trajectory_frame_set_input_file_pos = file_pos;
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(file_pos > 0)
{
curr_nr += long_stride_length;
- fseek(tng_data->input_file, (long)file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(file_pos > 0)
{
curr_nr += medium_stride_length;
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(file_pos > 0)
{
++curr_nr;
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(file_pos > 0)
{
curr_nr -= long_stride_length;
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(file_pos > 0)
{
curr_nr -= medium_stride_length;
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(file_pos > 0)
{
--curr_nr;
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(file_pos > 0)
{
++curr_nr;
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(tng_data->current_trajectory_frame_set_input_file_pos < 0)
{
file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
- tng_data->current_trajectory_frame_set_input_file_pos = (long)file_pos;
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
+ tng_data->current_trajectory_frame_set_input_file_pos = file_pos;
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
if(file_pos > 0)
{
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
- tng_data->current_trajectory_frame_set_input_file_pos = (long)file_pos;
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
+ tng_data->current_trajectory_frame_set_input_file_pos = file_pos;
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
file_pos = frame_set->long_stride_next_frame_set_file_pos;
if(file_pos > 0)
{
- fseek(tng_data->input_file, (long)file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
file_pos = frame_set->medium_stride_next_frame_set_file_pos;
if(file_pos > 0)
{
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
file_pos = frame_set->next_frame_set_file_pos;
if(file_pos > 0)
{
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
file_pos = frame_set->long_stride_prev_frame_set_file_pos;
if(file_pos > 0)
{
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
file_pos = frame_set->medium_stride_prev_frame_set_file_pos;
if(file_pos > 0)
{
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
file_pos = frame_set->prev_frame_set_file_pos;
if(file_pos > 0)
{
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
file_pos = frame_set->next_frame_set_file_pos;
if(file_pos > 0)
{
- fseek(tng_data->input_file,
- (long)file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ file_pos,
+ SEEK_SET);
/* Read block headers first to see what block is found. */
stat = tng_block_header_read(tng_data, block);
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET)
*len = 0;
- orig_pos = ftell(tng_data->input_file);
+ orig_pos = ftello(tng_data->input_file);
if(!tng_data->input_file_len)
{
- fseek(tng_data->input_file, 0, SEEK_END);
- tng_data->input_file_len = ftell(tng_data->input_file);
+ fseeko(tng_data->input_file, 0, SEEK_END);
+ tng_data->input_file_len = ftello(tng_data->input_file);
}
- fseek(tng_data->input_file, 0, SEEK_SET);
+ fseeko(tng_data->input_file, 0, SEEK_SET);
tng_block_init(&block);
/* Read through the headers of non-trajectory blocks (they come before the
block->id != TNG_TRAJECTORY_FRAME_SET)
{
*len += block->header_contents_size + block->block_contents_size;
- fseek(tng_data->input_file, block->block_contents_size, SEEK_CUR);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
}
- fseek(tng_data->input_file, orig_pos, SEEK_SET);
+ fseeko(tng_data->input_file, orig_pos, SEEK_SET);
tng_block_destroy(&block);
if(!tng_data->input_file_len)
{
- fseek(tng_data->input_file, 0, SEEK_END);
- tng_data->input_file_len = ftell(tng_data->input_file);
+ fseeko(tng_data->input_file, 0, SEEK_END);
+ tng_data->input_file_len = ftello(tng_data->input_file);
}
- fseek(tng_data->input_file, 0, SEEK_SET);
+ fseeko(tng_data->input_file, 0, SEEK_SET);
tng_block_init(&block);
/* Non trajectory blocks (they come before the trajectory
block->id != TNG_TRAJECTORY_FRAME_SET)
{
tng_block_read_next(tng_data, block, hash_mode);
- prev_pos = ftell(tng_data->input_file);
+ prev_pos = ftello(tng_data->input_file);
}
/* Go back if a trajectory block was encountered */
if(block->id == TNG_TRAJECTORY_FRAME_SET)
{
- fseek(tng_data->input_file, prev_pos, SEEK_SET);
+ fseeko(tng_data->input_file, prev_pos, SEEK_SET);
}
tng_block_destroy(&block);
else
{
/* Skip to the next block */
- fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
return(TNG_FAILURE);
}
}
(tng_trajectory_t tng_data,
const char hash_mode)
{
- long file_pos;
+ int64_t file_pos;
tng_gen_block_t block;
tng_function_status stat;
return(TNG_CRITICAL);
}
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
tng_block_init(&block);
if(!tng_data->input_file_len)
{
- fseek(tng_data->input_file, 0, SEEK_END);
- tng_data->input_file_len = ftell(tng_data->input_file);
- fseek(tng_data->input_file, file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, 0, SEEK_END);
+ tng_data->input_file_len = ftello(tng_data->input_file);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
}
/* Read block headers first to see what block is found. */
if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET ||
block->id == -1)
{
- fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
tng_block_destroy(&block);
return(TNG_CRITICAL);
hash_mode) == TNG_SUCCESS)
{
tng_data->n_trajectory_frame_sets++;
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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 &&
hash_mode);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
}
if(stat == TNG_CRITICAL)
{
- fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
tng_block_destroy(&block);
return(stat);
if(block->id == TNG_TRAJECTORY_FRAME_SET)
{
- fseek(tng_data->input_file, file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
}
}
const char hash_mode,
const int64_t block_id)
{
- long file_pos;
+ int64_t file_pos;
tng_gen_block_t block;
tng_function_status stat;
int found_flag = 1;
return(TNG_CRITICAL);
}
- file_pos = (long)tng_data->current_trajectory_frame_set_input_file_pos;
+ file_pos = tng_data->current_trajectory_frame_set_input_file_pos;
if(file_pos < 0)
{
/* No current frame set. This means that the first frame set must be
* read */
found_flag = 0;
- file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+ file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
}
if(file_pos > 0)
{
- fseek(tng_data->input_file,
+ fseeko(tng_data->input_file,
file_pos,
SEEK_SET);
}
if(!tng_data->input_file_len)
{
- fseek(tng_data->input_file, 0, SEEK_END);
- tng_data->input_file_len = ftell(tng_data->input_file);
- fseek(tng_data->input_file, file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, 0, SEEK_END);
+ tng_data->input_file_len = ftello(tng_data->input_file);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
}
/* Read block headers first to see what block is found. */
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 %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
tng_block_destroy(&block);
return(TNG_CRITICAL);
/* If the current frame set had already been read skip its block contents */
if(found_flag)
{
- fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
}
/* Otherwiese read the frame set block */
else
return(stat);
}
}
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
found_flag = 0;
hash_mode);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
found_flag = 1;
if(file_pos < tng_data->input_file_len)
{
}
else
{
- file_pos += (long)(block->block_contents_size + block->header_contents_size);
- fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+ file_pos += (block->block_contents_size + block->header_contents_size);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
}
if(stat == TNG_CRITICAL)
{
- fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
tng_block_destroy(&block);
return(stat);
if(block->id == TNG_TRAJECTORY_FRAME_SET)
{
- fseek(tng_data->input_file, file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
}
tng_block_destroy(&block);
(tng_trajectory_t tng_data,
const char hash_mode)
{
- long file_pos;
+ int64_t file_pos;
TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
return(TNG_CRITICAL);
}
- file_pos = (long)tng_data->current_trajectory_frame_set.next_frame_set_file_pos;
+ file_pos = tng_data->current_trajectory_frame_set.next_frame_set_file_pos;
if(file_pos < 0 && tng_data->current_trajectory_frame_set_input_file_pos <= 0)
{
- file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+ file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
}
if(file_pos > 0)
{
- fseek(tng_data->input_file,
+ fseeko(tng_data->input_file,
file_pos,
SEEK_SET);
}
const char hash_mode,
const int64_t block_id)
{
- long file_pos;
+ int64_t file_pos;
tng_gen_block_t block;
tng_function_status stat;
return(TNG_CRITICAL);
}
- file_pos = (long)tng_data->current_trajectory_frame_set.next_frame_set_file_pos;
+ file_pos = tng_data->current_trajectory_frame_set.next_frame_set_file_pos;
if(file_pos < 0 && tng_data->current_trajectory_frame_set_input_file_pos <= 0)
{
- file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+ file_pos = tng_data->first_trajectory_frame_set_input_file_pos;
}
if(file_pos > 0)
{
- fseek(tng_data->input_file,
+ fseeko(tng_data->input_file,
file_pos,
SEEK_SET);
}
if(!tng_data->input_file_len)
{
- fseek(tng_data->input_file, 0, SEEK_END);
- tng_data->input_file_len = ftell(tng_data->input_file);
- fseek(tng_data->input_file, file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, 0, SEEK_END);
+ tng_data->input_file_len = ftello(tng_data->input_file);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
}
/* Read block headers first to see what block is found. */
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 %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
tng_block_destroy(&block);
return(TNG_CRITICAL);
}
tng_data->current_trajectory_frame_set_output_file_pos =
- ftell(tng_data->output_file);
+ ftello(tng_data->output_file);
tng_data->last_trajectory_frame_set_output_file_pos =
tng_data->current_trajectory_frame_set_output_file_pos;
frame_set = &tng_data->current_trajectory_frame_set;
- curr_pos = ftell(tng_data->output_file);
+ curr_pos = ftello(tng_data->output_file);
if(curr_pos <= 10)
{
}
tng_data->current_trajectory_frame_set_output_file_pos =
- ftell(tng_data->output_file);
+ ftello(tng_data->output_file);
tng_data->n_trajectory_frame_sets++;
tng_block_init(&block);
tng_data->input_file = tng_data->output_file;
- curr_pos = ftell(tng_data->output_file);
- fseek(tng_data->output_file,
- (long)frame_set->medium_stride_prev_frame_set_file_pos,
- SEEK_SET);
+ curr_pos = ftello(tng_data->output_file);
+ fseeko(tng_data->output_file,
+ frame_set->medium_stride_prev_frame_set_file_pos,
+ SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
{
/* Read the next frame set from the previous frame set and one
* medium stride step back */
- fseek(tng_data->output_file, (long)block->block_contents_size - (6 *
+ fseeko(tng_data->output_file, block->block_contents_size - (6 *
sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
if(fread(&frame_set->medium_stride_prev_frame_set_file_pos,
sizeof(frame_set->medium_stride_prev_frame_set_file_pos),
tng_block_init(&block);
tng_data->input_file = tng_data->output_file;
- fseek(tng_data->output_file,
- (long)frame_set->long_stride_prev_frame_set_file_pos,
- SEEK_SET);
+ fseeko(tng_data->output_file,
+ frame_set->long_stride_prev_frame_set_file_pos,
+ SEEK_SET);
if(tng_block_header_read(tng_data, block) != TNG_SUCCESS)
{
/* Read the next frame set from the previous frame set and one
* long stride step back */
- fseek(tng_data->output_file, (long)block->block_contents_size - (6 *
+ fseeko(tng_data->output_file, block->block_contents_size - (6 *
sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR);
tng_block_destroy(&block);
}
tng_data->input_file = temp;
- fseek(tng_data->output_file, (long)curr_pos, SEEK_SET);
+ fseeko(tng_data->output_file, curr_pos, SEEK_SET);
}
}
(const tng_trajectory_t tng_data,
int64_t *frame)
{
- long file_pos, next_frame_set_file_pos;
+ int64_t file_pos, next_frame_set_file_pos;
tng_gen_block_t block;
tng_function_status stat;
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");
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(tng_data->current_trajectory_frame_set_input_file_pos <= 0)
{
- next_frame_set_file_pos = (long)tng_data->first_trajectory_frame_set_input_file_pos;
+ 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;
+ next_frame_set_file_pos = frame_set->next_frame_set_file_pos;
}
if(next_frame_set_file_pos <= 0)
return(TNG_FAILURE);
}
- fseek(tng_data->input_file, (long)next_frame_set_file_pos, SEEK_SET);
+ fseeko(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)
{
- fprintf(stderr, "TNG library: Cannot read block header at pos %ld. %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
return(TNG_CRITICAL);
}
__FILE__, __LINE__);
return(TNG_CRITICAL);
}
- fseek(tng_data->input_file, file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, file_pos, SEEK_SET);
return(TNG_SUCCESS);
}
int64_t header_pos, file_pos;
int64_t output_file_len, n_values_per_frame, size, contents_size;
int64_t header_size, temp_first, temp_last;
- int64_t i, last_frame;
- long temp_current;
+ int64_t i, last_frame, temp_current;
tng_gen_block_t block;
tng_trajectory_frame_set_t frame_set;
FILE *temp = tng_data->input_file;
tng_frame_set_new(tng_data,
last_frame+1,
tng_data->frame_set_n_frames);
- file_pos = ftell(tng_data->output_file);
- fseek(tng_data->output_file, 0, SEEK_END);
- output_file_len = ftell(tng_data->output_file);
- fseek(tng_data->output_file, (long)file_pos, SEEK_SET);
+ file_pos = ftello(tng_data->output_file);
+ fseeko(tng_data->output_file, 0, SEEK_END);
+ output_file_len = ftello(tng_data->output_file);
+ fseeko(tng_data->output_file, file_pos, SEEK_SET);
/* Read mapping blocks from the last frame set */
tng_block_init(&block);
}
else
{
- fseek(tng_data->output_file, (long)block->block_contents_size,
- SEEK_CUR);
+ fseeko(tng_data->output_file, block->block_contents_size,
+ SEEK_CUR);
}
- file_pos = ftell(tng_data->output_file);
+ file_pos = ftello(tng_data->output_file);
if(file_pos < output_file_len)
{
stat = tng_block_header_read(tng_data, block);
file_pos = tng_data->current_trajectory_frame_set_output_file_pos;
- fseek(tng_data->output_file, 0, SEEK_END);
- output_file_len = ftell(tng_data->output_file);
- fseek(tng_data->output_file, (long)file_pos, SEEK_SET);
+ fseeko(tng_data->output_file, 0, SEEK_END);
+ output_file_len = ftello(tng_data->output_file);
+ fseeko(tng_data->output_file, file_pos, SEEK_SET);
/* Read past the frame set block first */
stat = tng_block_header_read(tng_data, block);
tng_data->current_trajectory_frame_set_input_file_pos = temp_current;
return(stat);
}
- fseek(tng_data->output_file, (long)block->block_contents_size,
- SEEK_CUR);
+ fseeko(tng_data->output_file, block->block_contents_size,
+ SEEK_CUR);
/* Read all block headers until next frame set block or
* until the wanted block id is found */
block->id != TNG_TRAJECTORY_FRAME_SET &&
block->id != -1)
{
- fseek(tng_data->output_file, (long)block->block_contents_size, SEEK_CUR);
- file_pos = ftell(tng_data->output_file);
+ fseeko(tng_data->output_file, block->block_contents_size, SEEK_CUR);
+ file_pos = ftello(tng_data->output_file);
if(file_pos < output_file_len)
{
stat = tng_block_header_read(tng_data, block);
contents_size = block->block_contents_size;
header_size = block->header_contents_size;
- header_pos = ftell(tng_data->output_file) - header_size;
+ header_pos = ftello(tng_data->output_file) - header_size;
frame_set = &tng_data->current_trajectory_frame_set;
if(fread(&datatype, sizeof(datatype), 1, tng_data->input_file) == 0)
return(TNG_FAILURE);
}
- fseek(tng_data->output_file, (long)file_pos, SEEK_CUR);
+ fseeko(tng_data->output_file, file_pos, SEEK_CUR);
/* If the endianness is not big endian the data needs to be swapped */
if((data.datatype == TNG_INT_DATA ||
int64_t output_file_len, n_values_per_frame, size, contents_size;
int64_t header_size, temp_first, temp_last;
int64_t mapping_block_end_pos, num_first_particle, block_n_particles;
- int64_t i, last_frame;
- long temp_current;
+ int64_t i, last_frame, temp_current;
tng_gen_block_t block;
tng_trajectory_frame_set_t frame_set;
FILE *temp = tng_data->input_file;
last_frame+1,
tng_data->frame_set_n_frames);
- file_pos = ftell(tng_data->output_file);
- fseek(tng_data->output_file, 0, SEEK_END);
- output_file_len = ftell(tng_data->output_file);
- fseek(tng_data->output_file, (long)file_pos, SEEK_SET);
+ file_pos = ftello(tng_data->output_file);
+ fseeko(tng_data->output_file, 0, SEEK_END);
+ output_file_len = ftello(tng_data->output_file);
+ fseeko(tng_data->output_file, file_pos, SEEK_SET);
/* Read mapping blocks from the last frame set */
tng_block_init(&block);
}
else
{
- fseek(tng_data->output_file, (long)block->block_contents_size,
+ fseeko(tng_data->output_file, block->block_contents_size,
SEEK_CUR);
}
- file_pos = ftell(tng_data->output_file);
+ file_pos = ftello(tng_data->output_file);
if(file_pos < output_file_len)
{
stat = tng_block_header_read(tng_data, block);
file_pos = tng_data->current_trajectory_frame_set_output_file_pos;
- fseek(tng_data->output_file, 0, SEEK_END);
- output_file_len = ftell(tng_data->output_file);
- fseek(tng_data->output_file, (long)file_pos, SEEK_SET);
+ fseeko(tng_data->output_file, 0, SEEK_END);
+ output_file_len = ftello(tng_data->output_file);
+ fseeko(tng_data->output_file, file_pos, SEEK_SET);
/* Read past the frame set block first */
stat = tng_block_header_read(tng_data, block);
tng_data->current_trajectory_frame_set_input_file_pos = temp_current;
return(stat);
}
- fseek(tng_data->output_file, (long)block->block_contents_size,
+ fseeko(tng_data->output_file, block->block_contents_size,
SEEK_CUR);
if(tng_data->var_num_atoms_flag)
}
else
{
- fseek(tng_data->output_file, (long)block->block_contents_size,
+ fseeko(tng_data->output_file, block->block_contents_size,
SEEK_CUR);
}
- file_pos = ftell(tng_data->output_file);
+ file_pos = ftello(tng_data->output_file);
if(block->id == TNG_PARTICLE_MAPPING)
{
mapping = &frame_set->mappings[frame_set->n_mapping_blocks - 1];
tng_data->current_trajectory_frame_set_input_file_pos = temp_current;
return(TNG_FAILURE);
}
- fseek(tng_data->output_file, (long)mapping_block_end_pos, SEEK_SET);
+ fseeko(tng_data->output_file, mapping_block_end_pos, SEEK_SET);
}
/* Read all block headers until next frame set block or
block->id != TNG_TRAJECTORY_FRAME_SET &&
block->id != -1)
{
- fseek(tng_data->output_file, (long)block->block_contents_size, SEEK_CUR);
- file_pos = ftell(tng_data->output_file);
+ fseeko(tng_data->output_file, block->block_contents_size, SEEK_CUR);
+ file_pos = ftello(tng_data->output_file);
if(file_pos < output_file_len)
{
stat = tng_block_header_read(tng_data, block);
contents_size = block->block_contents_size;
header_size = block->header_contents_size;
- header_pos = ftell(tng_data->output_file) - header_size;
+ header_pos = ftello(tng_data->output_file) - header_size;
frame_set = &tng_data->current_trajectory_frame_set;
if(fread(&datatype, sizeof(datatype), 1, tng_data->input_file) == 0)
return(TNG_FAILURE);
}
- fseek(tng_data->output_file, (long)file_pos, SEEK_CUR);
+ fseeko(tng_data->output_file, file_pos, SEEK_CUR);
/* If the endianness is not big endian the data needs to be swapped */
if((data.datatype == TNG_INT_DATA ||
*values = malloc(sizeof(union data_values *) * n_frames);
if(!*values)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(union data_values **) * n_frames,
__FILE__, __LINE__);
return(TNG_CRITICAL);
n_values_per_frame);
if(!(*values)[i])
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(union data_values) * n_values_per_frame,
__FILE__, __LINE__);
free(values);
*values = malloc(sizeof(union data_values **) * n_frames);
if(!*values)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(union data_values **) * n_frames,
__FILE__, __LINE__);
return(TNG_CRITICAL);
n_particles);
if(!(*values)[i])
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(union data_values *) * n_particles,
__FILE__, __LINE__);
free(*values);
n_values_per_frame);
if(!(*values)[i][j])
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(union data_values *) * n_particles,
__FILE__, __LINE__);
tng_particle_data_values_free(tng_data, *values, n_frames,
if(tng_data_find(tng_data, block_id, &data) != TNG_SUCCESS)
{
tng_block_init(&block);
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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 &&
TNG_USE_HASH);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
if(tng_data_find(tng_data, block_id, &data) != TNG_SUCCESS)
{
tng_block_init(&block);
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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 &&
TNG_USE_HASH);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
frame_set->n_data_blocks <= 0)
{
tng_block_init(&block);
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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 &&
hash_mode);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
tng_block_init(&block);
if(stat != TNG_SUCCESS)
{
- fseek(tng_data->input_file,
- (long)tng_data->current_trajectory_frame_set_input_file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ tng_data->current_trajectory_frame_set_input_file_pos,
+ SEEK_SET);
stat = tng_block_header_read(tng_data, block);
if(stat != TNG_SUCCESS)
{
return(stat);
}
- fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
}
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
/* Read until next frame set block */
stat = tng_block_header_read(tng_data, block);
while(file_pos < tng_data->input_file_len &&
hash_mode);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
else
{
file_pos += block->block_contents_size + block->header_contents_size;
- fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
}
tng_block_init(&block);
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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 &&
TNG_USE_HASH);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
if(tng_particle_data_find(tng_data, block_id, &data) != TNG_SUCCESS)
{
tng_block_init(&block);
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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 &&
TNG_USE_HASH);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
frame_set->n_particle_data_blocks <= 0)
{
tng_block_init(&block);
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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 &&
hash_mode);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
tng_block_init(&block);
if(stat != TNG_SUCCESS)
{
- fseek(tng_data->input_file,
- (long)tng_data->current_trajectory_frame_set_input_file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ tng_data->current_trajectory_frame_set_input_file_pos,
+ SEEK_SET);
stat = tng_block_header_read(tng_data, block);
if(stat != TNG_SUCCESS)
{
return(stat);
}
- fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
}
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
/* Read until next frame set block */
stat = tng_block_header_read(tng_data, block);
while(file_pos < tng_data->input_file_len &&
hash_mode);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
else
{
file_pos += block->block_contents_size + block->header_contents_size;
- fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
if(file_pos < tng_data->input_file_len)
{
stat = tng_block_header_read(tng_data, block);
tng_function_status stat;
tng_non_particle_data_t np_data;
tng_particle_data_t p_data;
- long orig_file_pos, file_pos;
+ int64_t orig_file_pos, file_pos;
int is_particle_data;
if(tng_data->current_trajectory_frame_set_input_file_pos <= 0)
/* If no specific frame was required read until this data block is found */
if(frame < 0)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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);
+ file_pos = ftello(tng_data->input_file);
}
}
if(stat != TNG_SUCCESS)
/* Read the file headers */
tng_file_headers_read(*tng_data_p, TNG_USE_HASH);
- tng_num_frame_sets_get(*tng_data_p, &(*tng_data_p)->n_trajectory_frame_sets);
+ stat = tng_num_frame_sets_get(*tng_data_p, &(*tng_data_p)->n_trajectory_frame_sets);
+
+ if(stat != TNG_SUCCESS)
+ {
+ return(stat);
+ }
}
if(mode == 'w')
fclose((*tng_data_p)->output_file);
}
(*tng_data_p)->output_file = (*tng_data_p)->input_file;
- fseek((*tng_data_p)->input_file,
- (long)(*tng_data_p)->last_trajectory_frame_set_input_file_pos,
- SEEK_SET);
+ fseeko((*tng_data_p)->input_file,
+ (*tng_data_p)->last_trajectory_frame_set_input_file_pos,
+ SEEK_SET);
stat = tng_frame_set_read(*tng_data_p, TNG_USE_HASH);
if(stat != TNG_SUCCESS)
}
tng_output_append_file_set(*tng_data_p, filename);
- fseek((*tng_data_p)->output_file, 0, SEEK_END);
+ fseeko((*tng_data_p)->output_file, 0, SEEK_END);
}
return(TNG_SUCCESS);
tng_particle_data_t data = 0;
tng_function_status stat;
int size;
- int64_t i, data_size, n_particles;
+ int64_t i, data_size, n_particles, file_pos;
void *temp;
- long file_pos;
TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
TNG_ASSERT(values, "TNG library: The pointer to the values array must not be a NULL pointer");
if(stat != TNG_SUCCESS)
{
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);
+ file_pos = ftello(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);
+ file_pos = ftello(tng_data->input_file);
}
if(stat != TNG_SUCCESS)
{
}
if(data->last_retrieved_frame < 0)
{
- fseek(tng_data->input_file,
- (long)tng_data->first_trajectory_frame_set_input_file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ tng_data->first_trajectory_frame_set_input_file_pos,
+ SEEK_SET);
stat = tng_frame_set_read(tng_data, TNG_USE_HASH);
if(stat != TNG_SUCCESS)
{
{
return(stat);
}
+ if(frame_set->first_frame + frame_set->n_frames - 1 < i)
+ {
+ return(TNG_FAILURE);
+ }
i = frame_set->first_frame;
}
}
tng_non_particle_data_t data = 0;
tng_function_status stat;
int size;
- int64_t i, data_size;
+ int64_t i, data_size, file_pos;
void *temp;
- long file_pos;
TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
TNG_ASSERT(values, "TNG library: The pointer to the values array must not be a NULL pointer");
if(stat != TNG_SUCCESS)
{
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);
+ file_pos = ftello(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);
+ file_pos = ftello(tng_data->input_file);
}
if(stat != TNG_SUCCESS)
{
}
if(data->last_retrieved_frame < 0)
{
- fseek(tng_data->input_file,
- (long)tng_data->first_trajectory_frame_set_input_file_pos,
- SEEK_SET);
+ fseeko(tng_data->input_file,
+ tng_data->first_trajectory_frame_set_input_file_pos,
+ SEEK_SET);
stat = tng_frame_set_read(tng_data, TNG_USE_HASH);
if(stat != TNG_SUCCESS)
{
{
return(stat);
}
+ if(frame_set->first_frame + frame_set->n_frames - 1 < i)
+ {
+ return(TNG_FAILURE);
+ }
i = frame_set->first_frame;
}
}
(tng_trajectory_t tng_data,
const int64_t block_id,
int64_t *codec_id,
- float *factor)
+ double *factor)
{
tng_trajectory_frame_set_t frame_set;
tng_particle_data_t p_data = 0;
if(block_type == TNG_PARTICLE_BLOCK_DATA)
{
*codec_id = p_data->codec_id;
- *factor = (float)p_data->compression_multiplier;
+ *factor = p_data->compression_multiplier;
}
else if(block_type == TNG_NON_PARTICLE_BLOCK_DATA)
{
*codec_id = np_data->codec_id;
- *factor = (float)np_data->compression_multiplier;
+ *factor = np_data->compression_multiplier;
}
return(TNG_SUCCESS);
}
tng_gen_block_t block;
int64_t i, j, block_id, *temp;
int64_t data_frame, frame_diff, min_diff;
- int64_t size, frame_set_file_pos;
+ int64_t size, frame_set_file_pos, file_pos;
int found, read_all = 0;
- long file_pos;
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.");
temp = realloc(*data_block_ids_in_next_frame, size);
if(!temp)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * (*n_data_blocks_in_next_frame),
__FILE__, __LINE__);
free(*data_block_ids_in_next_frame);
/* Check for data blocks only if they have not already been found. */
if(frame_set->n_particle_data_blocks <= 0 && frame_set->n_data_blocks <= 0)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(tng_data->input_file);
if(file_pos < tng_data->input_file_len)
{
tng_block_init(&block);
TNG_USE_HASH);
if(stat != TNG_CRITICAL)
{
- file_pos = ftell(tng_data->input_file);
+ file_pos = ftello(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",
+ fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n",
file_pos, __FILE__, __LINE__);
return(stat);
}
temp = realloc(*data_block_ids_in_next_frame, size);
if(!temp)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * (*n_data_blocks_in_next_frame),
__FILE__, __LINE__);
free(*data_block_ids_in_next_frame);
temp = realloc(*data_block_ids_in_next_frame, size);
if(!temp)
{
- fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",
sizeof(int64_t) * (*n_data_blocks_in_next_frame),
__FILE__, __LINE__);
free(*data_block_ids_in_next_frame);
char **compressions)
{
tng_gen_block_t block;
- long orig_file_pos, file_pos;
+ int64_t orig_file_pos, file_pos;
TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
TNG_ASSERT(n_data_blocks, "TNG library: The pointer to n_data_blocks must not be NULL.");
TNG_ASSERT(data_block_names, "TNG library: The pointer to the list of data block names must not be NULL.");
TNG_ASSERT(stride_lengths, "TNG library: The pointer to the list of stride lengths must not be NULL.");
- orig_file_pos = ftell(tng_data->input_file);
+ orig_file_pos = ftello(tng_data->input_file);
if(!tng_data->input_file_len)
{
- fseek(tng_data->input_file, 0, SEEK_END);
- tng_data->input_file_len = ftell(tng_data->input_file);
+ fseeko(tng_data->input_file, 0, SEEK_END);
+ tng_data->input_file_len = ftello(tng_data->input_file);
}
- fseek(tng_data->input_file, 0, SEEK_SET);
+ fseeko(tng_data->input_file, 0, SEEK_SET);
file_pos = 0;
*n_data_blocks = 0;
{
}
- file_pos += (long)(block->block_contents_size + block->header_contents_size);
- fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
+ file_pos += (block->block_contents_size + block->header_contents_size);
+ fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR);
}
- fseek(tng_data->input_file, orig_file_pos, SEEK_SET);
+ fseeko(tng_data->input_file, orig_file_pos, SEEK_SET);
return(TNG_SUCCESS);
}