diff options
author | Jan Huwald <jh@sotun.de> | 2014-01-27 13:57:37 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2016-01-11 12:02:26 (GMT) |
commit | b7bd44ee623b64af25aa8f629ae7e22b00a2142c (patch) | |
tree | 7ca9b1eb7d75323f384e4d3641113f4140c9a3ca | |
parent | 8e239a6b59d8ff11979ca8557be9b79e2c15f83a (diff) |
Almost all of this code has been created by Stephan Richter
<s.richter@keawe.de>. Only minor changes and this squashed commit have
been prepared by Jan Huwald <jh@sotun.de>.
-rw-r--r-- | CMakeLists.txt | 37 | ||||
-rw-r--r-- | include/tng/tng_io.h | 6 | ||||
-rw-r--r-- | include/tng/tng_io.hpp | 2 | ||||
-rw-r--r-- | src/lib/tng_io.c | 1895 | ||||
-rw-r--r-- | src/tests/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/tests/md_openmp.c | 75 | ||||
-rw-r--r-- | src/tests/sr_test.c | 1249 | ||||
-rw-r--r-- | src/tests/tng_io_testing.c | 11 |
8 files changed, 1880 insertions, 1400 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 87c10be..308c897 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,39 @@ tng_get_source_list(TNG_SOURCES TNG_COMPILE_DEFS) tng_set_source_properties(WITH_ZLIB ${ZLIB_FOUND}) -add_library(tng_io ${TNG_SOURCES}) - +SET( hrtc_object_files + src/compression/hrtc/hrtc_wrapper.o + src/compression/hrtc/integer_encoding_library/src/compress/VSE-R.o + src/compression/hrtc/integer_encoding_library/src/compress/VSEncodingBlocksHybrind.o + src/compression/hrtc/integer_encoding_library/src/compress/VSEncodingSimple.o + src/compression/hrtc/integer_encoding_library/src/compress/Simple16.o + src/compression/hrtc/integer_encoding_library/src/compress/VSEncodingRest.o + src/compression/hrtc/integer_encoding_library/src/compress/PForDelta.o + src/compression/hrtc/integer_encoding_library/src/compress/VSEncodingBlocks.o + src/compression/hrtc/integer_encoding_library/src/compress/VariableByte.o + src/compression/hrtc/integer_encoding_library/src/compress/table/decGamma.o + src/compression/hrtc/integer_encoding_library/src/compress/table/decUnary.o + src/compression/hrtc/integer_encoding_library/src/compress/table/decDelta.o + src/compression/hrtc/integer_encoding_library/src/compress/VSEncodingNaive.o + src/compression/hrtc/integer_encoding_library/src/compress/VSEncodingDP.o + src/compression/hrtc/integer_encoding_library/src/compress/Simple9.o + src/compression/hrtc/integer_encoding_library/src/compress/OPTPForDelta.o + src/compression/hrtc/integer_encoding_library/src/interger_encoding.o + src/compression/hrtc/integer_encoding_library/src/io/BitsWriter.o + src/compression/hrtc/integer_encoding_library/src/io/BitsReader.o +) + +SET_SOURCE_FILES_PROPERTIES( + ${hrtc_object_files} + PROPERTIES + EXTERNAL_OBJECT true + # to say that "this is actually an object file, so it should not be compiled, only linked" + # GENERATED true + # to say that "it is OK that the obj-files do not exist before build time" +) + +add_library(tng_io ${TNG_SOURCES} ${hrtc_object_files}) + if (ZLIB_FOUND) list(APPEND EXTRA_LIBRARIES ${ZLIB_LIBRARIES}) include_directories(${ZLIB_INCLUDE_DIRS}) @@ -41,6 +72,8 @@ endif() if (UNIX) list(APPEND EXTRA_LIBRARIES m) endif() + +list(APPEND EXTRA_LIBRARIES stdc++) target_link_libraries(tng_io ${EXTRA_LIBRARIES}) diff --git a/include/tng/tng_io.h b/include/tng/tng_io.h index 668acbe..cb43891 100644 --- a/include/tng/tng_io.h +++ b/include/tng/tng_io.h @@ -399,7 +399,8 @@ typedef enum {TNG_BIG_ENDIAN_64, typedef enum {TNG_UNCOMPRESSED, TNG_XTC_COMPRESSION, TNG_TNG_COMPRESSION, - TNG_GZIP_COMPRESSION} tng_compression; + TNG_GZIP_COMPRESSION, + TNG_HRTC_COMPRESSION} tng_compression; /** Hash types */ typedef enum {TNG_NO_HASH, @@ -407,7 +408,8 @@ typedef enum {TNG_NO_HASH, TNG_SHA256} tng_hash_type; /** Non trajectory blocks come before the first frame set block */ -typedef enum {TNG_NON_TRAJECTORY_BLOCK, TNG_TRAJECTORY_BLOCK} tng_block_type; +typedef enum {TNG_NON_TRAJECTORY_BLOCK, + TNG_TRAJECTORY_BLOCK} tng_block_type; /** @defgroup def1 Standard non-trajectory blocks * Block IDs of standard non-trajectory blocks. diff --git a/include/tng/tng_io.hpp b/include/tng/tng_io.hpp index 12172e5..0983570 100644 --- a/include/tng/tng_io.hpp +++ b/include/tng/tng_io.hpp @@ -53,7 +53,7 @@ public: Trajectory(Trajectory * src) { status = tng_trajectory_init_from_src(traj,&src->traj); } - //! Detructor + //! Destructor ~Trajectory() { status = tng_trajectory_destroy(&traj); } diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index f83f984..c8b8c4d 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -622,8 +622,7 @@ static tng_function_status tng_freadstr(const tng_trajectory_t tng_data, temp_alloc = realloc(*str, count); if(!temp_alloc) { - fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", count, - __FILE__, line_nr); + fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", count, __FILE__, line_nr); free(*str); *str = 0; return TNG_FAILURE; @@ -707,19 +706,15 @@ static TNG_INLINE tng_function_status tng_file_input_numerical switch(len) { case 8: - if(tng_data->input_endianness_swap_func_64 && - tng_data->input_endianness_swap_func_64(tng_data, dest) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64 && tng_data->input_endianness_swap_func_64(tng_data, dest) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, line_nr); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, line_nr); } break; case 4: - if(tng_data->input_endianness_swap_func_32 && - tng_data->input_endianness_swap_func_32(tng_data, dest) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_32 && tng_data->input_endianness_swap_func_32(tng_data, dest) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, line_nr); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, line_nr); } break; default: @@ -760,8 +755,7 @@ static TNG_INLINE tng_function_status tng_file_output_numerical if(tng_data->output_endianness_swap_func_64 && tng_data->output_endianness_swap_func_64(tng_data, &temp_i64) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, line_nr); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, line_nr); } if(fwrite(&temp_i64, len, 1, tng_data->output_file) != 1) { @@ -775,11 +769,9 @@ static TNG_INLINE tng_function_status tng_file_output_numerical break; case 4: temp_i32 = *((int32_t *)src); - if(tng_data->output_endianness_swap_func_32 && - tng_data->output_endianness_swap_func_32(tng_data, &temp_i32) != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_32 && tng_data->output_endianness_swap_func_32(tng_data, &temp_i32) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, line_nr); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, line_nr); } if(fwrite(&temp_i32, len, 1, tng_data->output_file) != 1) { @@ -818,8 +810,7 @@ static tng_function_status tng_block_md5_hash_generate(const tng_gen_block_t blo md5_state_t md5_state; md5_init(&md5_state); - md5_append(&md5_state, (md5_byte_t *)block->block_contents, - (int)block->block_contents_size); + md5_append(&md5_state, (md5_byte_t *)block->block_contents, (int)block->block_contents_size); md5_finish(&md5_state, (md5_byte_t *)block->md5_hash); return(TNG_SUCCESS); @@ -849,19 +840,16 @@ static tng_function_status tng_md5_remaining_append(const tng_trajectory_t tng_d temp_data = malloc(start_pos + block->block_contents_size - curr_file_pos); if(!temp_data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", - start_pos + block->block_contents_size - curr_file_pos, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", start_pos + block->block_contents_size - curr_file_pos, __FILE__, __LINE__); return(TNG_CRITICAL); } - if(fread(temp_data, start_pos + block->block_contents_size - curr_file_pos, - 1, tng_data->input_file) == 0) + if(fread(temp_data, start_pos + block->block_contents_size - curr_file_pos, 1, tng_data->input_file) == 0) { fprintf(stderr, "TNG library: Cannot read remaining part of block to generate MD5 sum. %s: %d\n", __FILE__, __LINE__); free(temp_data); return(TNG_CRITICAL); } - md5_append(md5_state, (md5_byte_t *)temp_data, - start_pos + block->block_contents_size - curr_file_pos); + md5_append(md5_state, (md5_byte_t *)temp_data, start_pos + block->block_contents_size - curr_file_pos); free(temp_data); } @@ -1016,8 +1004,7 @@ static tng_function_status tng_block_destroy(struct tng_gen_block **block_p) * error has occured (not able to read the header size, thus skipping * the block) or TNG_CRITICAL (2) if a major error has occured. */ -static tng_function_status tng_block_header_read - (const tng_trajectory_t tng_data, const tng_gen_block_t block) +static tng_function_status tng_block_header_read(const tng_trajectory_t tng_data, const tng_gen_block_t block) { int64_t start_pos; @@ -1031,11 +1018,9 @@ static tng_function_status tng_block_header_read start_pos = ftello(tng_data->input_file); /* First read the header size to be able to read the whole header. */ - if(fread(&block->header_contents_size, sizeof(block->header_contents_size), - 1, tng_data->input_file) == 0) + if(fread(&block->header_contents_size, sizeof(block->header_contents_size), 1, tng_data->input_file) == 0) { - fprintf(stderr, "TNG library: Cannot read header size. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read header size. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -1061,8 +1046,7 @@ static tng_function_status tng_block_header_read } else { - tng_data->input_endianness_swap_func_32 = - &tng_swap_byte_order_little_endian_32; + tng_data->input_endianness_swap_func_32 = &tng_swap_byte_order_little_endian_32; } if(tng_data->endianness_64 == TNG_LITTLE_ENDIAN_64) { @@ -1070,8 +1054,7 @@ static tng_function_status tng_block_header_read } else { - tng_data->input_endianness_swap_func_64 = - &tng_swap_byte_order_little_endian_64; + tng_data->input_endianness_swap_func_64 = &tng_swap_byte_order_little_endian_64; } } /* File is big endian */ @@ -1086,8 +1069,7 @@ static tng_function_status tng_block_header_read } else { - tng_data->input_endianness_swap_func_32 = - &tng_swap_byte_order_big_endian_32; + tng_data->input_endianness_swap_func_32 = &tng_swap_byte_order_big_endian_32; } if(tng_data->endianness_64 == TNG_BIG_ENDIAN_64) { @@ -1095,29 +1077,22 @@ static tng_function_status tng_block_header_read } else { - tng_data->input_endianness_swap_func_64 = - &tng_swap_byte_order_big_endian_64; + tng_data->input_endianness_swap_func_64 = &tng_swap_byte_order_big_endian_64; } } } - if(tng_data->input_endianness_swap_func_64 && - tng_data->input_endianness_swap_func_64(tng_data, &block->header_contents_size) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64 && tng_data->input_endianness_swap_func_64(tng_data, &block->header_contents_size) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } - if(tng_file_input_numerical(tng_data, &block->block_contents_size, - sizeof(block->block_contents_size), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &block->block_contents_size, sizeof(block->block_contents_size), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &block->id, - sizeof(block->id), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &block->id, sizeof(block->id), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -1207,14 +1182,12 @@ static tng_function_status tng_md5_hash_update(const tng_trajectory_t tng_data, block->block_contents = malloc(block->block_contents_size); if(!block->block_contents) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", - block->block_contents_size, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", block->block_contents_size, __FILE__, __LINE__); return(TNG_CRITICAL); } 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) + if(fread(block->block_contents, block->block_contents_size, 1, tng_data->output_file) == 0) { fprintf(stderr, "TNG library: Cannot read block. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); @@ -1222,8 +1195,7 @@ static tng_function_status tng_md5_hash_update(const tng_trajectory_t tng_data, tng_block_md5_hash_generate(block); - fseeko(tng_data->output_file, header_start_pos + 3 * sizeof(int64_t), - SEEK_SET); + 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); return(TNG_SUCCESS); @@ -1247,8 +1219,7 @@ static tng_function_status tng_header_pointers_update if(tng_output_file_init(tng_data) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot initialise destination file. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot initialise destination file. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -1261,8 +1232,7 @@ static tng_function_status tng_header_pointers_update if(tng_block_header_read(tng_data, block) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot read general info header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read general info header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1270,8 +1240,7 @@ static tng_function_status tng_header_pointers_update contents_start_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, block->block_contents_size - 5 * - sizeof(int64_t), SEEK_CUR); + fseeko(tng_data->output_file, block->block_contents_size - 5 * sizeof(int64_t), SEEK_CUR); tng_data->input_file = temp; @@ -1279,12 +1248,9 @@ static tng_function_status tng_header_pointers_update if(tng_data->input_endianness_swap_func_64) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -1298,12 +1264,9 @@ static tng_function_status tng_header_pointers_update if(tng_data->input_endianness_swap_func_64) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -1336,8 +1299,7 @@ static tng_function_status tng_header_pointers_update * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major * error has occured. */ -static tng_function_status tng_frame_set_pointers_update - (const tng_trajectory_t tng_data, const char hash_mode) +static tng_function_status tng_frame_set_pointers_update(const tng_trajectory_t tng_data, const char hash_mode) { tng_gen_block_t block; tng_trajectory_frame_set_t frame_set; @@ -1346,8 +1308,7 @@ static tng_function_status tng_frame_set_pointers_update if(tng_output_file_init(tng_data) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot initialise destination file. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot initialise destination file. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -1367,8 +1328,7 @@ static tng_function_status tng_frame_set_pointers_update if(tng_block_header_read(tng_data, block) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot read frame header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read frame header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1376,17 +1336,13 @@ static tng_function_status tng_frame_set_pointers_update contents_start_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, block->block_contents_size - (5 * - sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR); + 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) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -1399,21 +1355,18 @@ static tng_function_status tng_frame_set_pointers_update if(hash_mode == TNG_USE_HASH) { - tng_md5_hash_update(tng_data, block, frame_set->next_frame_set_file_pos, - contents_start_pos); + tng_md5_hash_update(tng_data, block, frame_set->next_frame_set_file_pos, contents_start_pos); } fseeko(tng_data->output_file, output_file_pos, SEEK_SET); } /* Update previous frame set */ if(frame_set->prev_frame_set_file_pos > 0) { - fseeko(tng_data->output_file, frame_set->prev_frame_set_file_pos, - SEEK_SET); + fseeko(tng_data->output_file, frame_set->prev_frame_set_file_pos, SEEK_SET); if(tng_block_header_read(tng_data, block) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot read frame header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read frame header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1421,17 +1374,13 @@ static tng_function_status tng_frame_set_pointers_update contents_start_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, block->block_contents_size - (6 * - sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR); + 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) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -1444,8 +1393,7 @@ static tng_function_status tng_frame_set_pointers_update if(hash_mode == TNG_USE_HASH) { - tng_md5_hash_update(tng_data, block, frame_set->prev_frame_set_file_pos, - contents_start_pos); + tng_md5_hash_update(tng_data, block, frame_set->prev_frame_set_file_pos, contents_start_pos); } fseeko(tng_data->output_file, output_file_pos, SEEK_SET); } @@ -1453,14 +1401,11 @@ static tng_function_status tng_frame_set_pointers_update /* Update the frame set one medium stride step after */ if(frame_set->medium_stride_next_frame_set_file_pos > 0) { - fseeko(tng_data->output_file, - 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) { - fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1468,17 +1413,13 @@ static tng_function_status tng_frame_set_pointers_update contents_start_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, block->block_contents_size - (3 * - sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR); + 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) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -1491,22 +1432,17 @@ static tng_function_status tng_frame_set_pointers_update if(hash_mode == TNG_USE_HASH) { - tng_md5_hash_update(tng_data, block, - frame_set->medium_stride_next_frame_set_file_pos, - contents_start_pos); + tng_md5_hash_update(tng_data, block, frame_set->medium_stride_next_frame_set_file_pos, contents_start_pos); } } /* Update the frame set one medium stride step before */ if(frame_set->medium_stride_prev_frame_set_file_pos > 0) { - fseeko(tng_data->output_file, - 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) { - fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1519,12 +1455,9 @@ static tng_function_status tng_frame_set_pointers_update if(tng_data->input_endianness_swap_func_64) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -1537,23 +1470,18 @@ static tng_function_status tng_frame_set_pointers_update if(hash_mode == TNG_USE_HASH) { - tng_md5_hash_update(tng_data, block, - frame_set->medium_stride_prev_frame_set_file_pos, - contents_start_pos); + tng_md5_hash_update(tng_data, block, frame_set->medium_stride_prev_frame_set_file_pos, contents_start_pos); } } /* Update the frame set one long stride step after */ if(frame_set->long_stride_next_frame_set_file_pos > 0) { - fseeko(tng_data->output_file, - 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) { - fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1561,17 +1489,13 @@ static tng_function_status tng_frame_set_pointers_update contents_start_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, 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) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -1584,22 +1508,17 @@ static tng_function_status tng_frame_set_pointers_update if(hash_mode == TNG_USE_HASH) { - tng_md5_hash_update(tng_data, block, - frame_set->long_stride_next_frame_set_file_pos, - contents_start_pos); + tng_md5_hash_update(tng_data, block, frame_set->long_stride_next_frame_set_file_pos, contents_start_pos); } } /* Update the frame set one long stride step before */ if(frame_set->long_stride_prev_frame_set_file_pos > 0) { - fseeko(tng_data->output_file, - 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) { - fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1612,12 +1531,9 @@ static tng_function_status tng_frame_set_pointers_update if(tng_data->input_endianness_swap_func_64) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -1630,9 +1546,7 @@ static tng_function_status tng_frame_set_pointers_update if(hash_mode == TNG_USE_HASH) { - tng_md5_hash_update(tng_data, block, - frame_set->long_stride_prev_frame_set_file_pos, - contents_start_pos); + tng_md5_hash_update(tng_data, block, frame_set->long_stride_prev_frame_set_file_pos, contents_start_pos); } } @@ -1666,8 +1580,7 @@ static tng_function_status tng_reread_frame_set_at_file_pos return(TNG_FAILURE); } - if(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1686,8 +1599,7 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get int64_t orig_pos, curr_frame_set_pos; tng_gen_block_t block; tng_function_status stat; - tng_trajectory_frame_set_t frame_set = - &tng_data->current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; orig_pos = ftello(tng_data->input_file); curr_frame_set_pos = tng_data->current_trajectory_frame_set_input_file_pos; @@ -1706,14 +1618,12 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get stat = tng_block_header_read(tng_data, block); if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", *pos, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", *pos, __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_FAILURE); } - if(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block,TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -1726,8 +1636,7 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get stat = tng_block_header_read(tng_data, block); if(stat == TNG_CRITICAL) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", *pos, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", *pos, __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_CRITICAL); } @@ -1743,8 +1652,7 @@ static tng_function_status tng_file_pos_of_subsequent_trajectory_block_get return(stat); } /* Update *pos if this is the earliest frame set so far (after orig_pos) */ - if(tng_data->current_trajectory_frame_set_input_file_pos < *pos && - tng_data->current_trajectory_frame_set_input_file_pos > orig_pos) + if(tng_data->current_trajectory_frame_set_input_file_pos < *pos && tng_data->current_trajectory_frame_set_input_file_pos > orig_pos) { *pos = tng_data->current_trajectory_frame_set_input_file_pos; } @@ -1789,15 +1697,13 @@ static tng_function_status tng_frame_set_complete_migrate contents = malloc(block_len); if(!contents) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", - block_len, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", block_len, __FILE__, __LINE__); return(TNG_CRITICAL); } if(fread(contents, block_len, 1, tng_data->input_file) == 0) { - fprintf(stderr, "TNG library: Cannot read data from file when migrating data. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read data from file when migrating data. %s: %d\n", __FILE__, __LINE__); free(contents); return(TNG_CRITICAL); } @@ -1805,8 +1711,7 @@ static tng_function_status tng_frame_set_complete_migrate if(fwrite(contents, block_len, 1, tng_data->output_file) != 1) { - fprintf(stderr, "TNG library: Could not write data to file when migrating data. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Could not write data to file when migrating data. %s: %d\n", __FILE__, __LINE__); free(contents); return(TNG_CRITICAL); } @@ -1863,8 +1768,7 @@ static tng_function_status tng_length_of_current_frame_set_contents_get stat = tng_block_header_read(tng_data, block); if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - curr_frame_set_pos, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", curr_frame_set_pos, __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_FAILURE); } @@ -1952,8 +1856,7 @@ static tng_function_status tng_migrate_data_in_file stat = tng_block_header_read(tng_data, block); if(stat == TNG_CRITICAL) { - fprintf(stderr, "TNG library: Cannot read block header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read block header. %s: %d\n", __FILE__, __LINE__); tng_block_destroy(&block); tng_data->input_file = temp; return(TNG_CRITICAL); @@ -1971,9 +1874,7 @@ static tng_function_status tng_migrate_data_in_file tng_block_destroy(&block); return(stat); } - stat = tng_frame_set_complete_migrate(tng_data, traj_start_pos, - frame_set_length, tng_data->input_file_len, - hash_mode); + stat = tng_frame_set_complete_migrate(tng_data, traj_start_pos,frame_set_length, tng_data->input_file_len,hash_mode); if(stat != TNG_SUCCESS) { tng_data->input_file = temp; @@ -2004,8 +1905,7 @@ static tng_function_status tng_block_header_len_calculate block->name = malloc(1); if(!block->name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } block->name[0] = 0; @@ -2041,36 +1941,27 @@ static tng_function_status tng_block_header_write if(tng_output_file_init(tng_data) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot initialise destination file. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot initialise destination file. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } - if(tng_block_header_len_calculate(tng_data, block, &block->header_contents_size) != - TNG_SUCCESS) + if(tng_block_header_len_calculate(tng_data, block, &block->header_contents_size) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot calculate length of block header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot calculate length of block header. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &block->header_contents_size, - sizeof(block->header_contents_size), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &block->header_contents_size, sizeof(block->header_contents_size), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &block->block_contents_size, - sizeof(block->block_contents_size), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &block->block_contents_size, sizeof(block->block_contents_size), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &block->id, - sizeof(block->id), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &block->id, sizeof(block->id), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2086,9 +1977,7 @@ static tng_function_status tng_block_header_write return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &block->block_version, - sizeof(block->block_version), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &block->block_version, sizeof(block->block_version), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2096,9 +1985,7 @@ static tng_function_status tng_block_header_write return(TNG_SUCCESS); } -static tng_function_status tng_general_info_block_len_calculate - (const tng_trajectory_t tng_data, - int64_t *len) +static tng_function_status tng_general_info_block_len_calculate(const tng_trajectory_t tng_data, int64_t *len) { size_t first_program_name_len, first_user_name_len; size_t first_computer_name_len, first_pgp_signature_len; @@ -2113,8 +2000,7 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->first_program_name = malloc(1); if(!tng_data->first_program_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->first_program_name[0] = 0; @@ -2124,8 +2010,7 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->last_program_name = malloc(1); if(!tng_data->last_program_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->last_program_name[0] = 0; @@ -2135,8 +2020,7 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->first_user_name = malloc(1); if(!tng_data->first_user_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->first_user_name[0] = 0; @@ -2146,8 +2030,7 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->last_user_name = malloc(1); if(!tng_data->last_user_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->last_user_name[0] = 0; @@ -2157,8 +2040,7 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->first_computer_name = malloc(1); if(!tng_data->first_computer_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->first_computer_name[0] = 0; @@ -2168,8 +2050,7 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->last_computer_name = malloc(1); if(!tng_data->last_computer_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->last_computer_name[0] = 0; @@ -2179,8 +2060,7 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->first_pgp_signature = malloc(1); if(!tng_data->first_pgp_signature) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->first_pgp_signature[0] = 0; @@ -2190,8 +2070,7 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->last_pgp_signature = malloc(1); if(!tng_data->last_pgp_signature) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->last_pgp_signature[0] = 0; @@ -2201,31 +2080,21 @@ static tng_function_status tng_general_info_block_len_calculate tng_data->forcefield_name = malloc(1); if(!tng_data->forcefield_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } tng_data->forcefield_name[0] = 0; } - first_program_name_len = tng_min_size(strlen(tng_data->first_program_name) + 1, - TNG_MAX_STR_LEN); - last_program_name_len = tng_min_size(strlen(tng_data->last_program_name) + 1, - TNG_MAX_STR_LEN); - first_user_name_len = tng_min_size(strlen(tng_data->first_user_name) + 1, - TNG_MAX_STR_LEN); - last_user_name_len = tng_min_size(strlen(tng_data->last_user_name) + 1, - TNG_MAX_STR_LEN); - first_computer_name_len = tng_min_size(strlen(tng_data->first_computer_name) + 1, - TNG_MAX_STR_LEN); - last_computer_name_len = tng_min_size(strlen(tng_data->last_computer_name) + 1, - TNG_MAX_STR_LEN); - first_pgp_signature_len = tng_min_size(strlen(tng_data->first_pgp_signature) + 1, - TNG_MAX_STR_LEN); - last_pgp_signature_len = tng_min_size(strlen(tng_data->last_pgp_signature) + 1, - TNG_MAX_STR_LEN); - forcefield_name_len = tng_min_size(strlen(tng_data->forcefield_name) + 1, - TNG_MAX_STR_LEN); + first_program_name_len = tng_min_size(strlen(tng_data->first_program_name) + 1, TNG_MAX_STR_LEN); + last_program_name_len = tng_min_size(strlen(tng_data->last_program_name) + 1, TNG_MAX_STR_LEN); + first_user_name_len = tng_min_size(strlen(tng_data->first_user_name) + 1, TNG_MAX_STR_LEN); + last_user_name_len = tng_min_size(strlen(tng_data->last_user_name) + 1, TNG_MAX_STR_LEN); + first_computer_name_len = tng_min_size(strlen(tng_data->first_computer_name) + 1, TNG_MAX_STR_LEN); + last_computer_name_len = tng_min_size(strlen(tng_data->last_computer_name) + 1, TNG_MAX_STR_LEN); + first_pgp_signature_len = tng_min_size(strlen(tng_data->first_pgp_signature) + 1, TNG_MAX_STR_LEN); + last_pgp_signature_len = tng_min_size(strlen(tng_data->last_pgp_signature) + 1, TNG_MAX_STR_LEN); + forcefield_name_len = tng_min_size(strlen(tng_data->forcefield_name) + 1, TNG_MAX_STR_LEN); *len = sizeof(tng_data->time) + sizeof(tng_data->var_num_atoms_flag) + @@ -2300,31 +2169,23 @@ static tng_function_status tng_general_info_block_read tng_freadstr(tng_data, &tng_data->forcefield_name, hash_mode, &md5_state, __LINE__); - if(tng_file_input_numerical(tng_data, &tng_data->time, sizeof(tng_data->time), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->time, sizeof(tng_data->time), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &tng_data->var_num_atoms_flag, - sizeof(tng_data->var_num_atoms_flag), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->var_num_atoms_flag, sizeof(tng_data->var_num_atoms_flag), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &tng_data->frame_set_n_frames, - sizeof(tng_data->frame_set_n_frames), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->frame_set_n_frames, sizeof(tng_data->frame_set_n_frames), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, - &tng_data->first_trajectory_frame_set_input_file_pos, - sizeof(tng_data->first_trajectory_frame_set_input_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->first_trajectory_frame_set_input_file_pos, sizeof(tng_data->first_trajectory_frame_set_input_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2332,36 +2193,24 @@ static tng_function_status tng_general_info_block_read tng_data->current_trajectory_frame_set.next_frame_set_file_pos = tng_data->first_trajectory_frame_set_input_file_pos; - if(tng_file_input_numerical(tng_data, - &tng_data->last_trajectory_frame_set_input_file_pos, - sizeof(tng_data->last_trajectory_frame_set_input_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->last_trajectory_frame_set_input_file_pos, sizeof(tng_data->last_trajectory_frame_set_input_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, - &tng_data->medium_stride_length, - sizeof(tng_data->medium_stride_length), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->medium_stride_length, sizeof(tng_data->medium_stride_length), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, - &tng_data->long_stride_length, - sizeof(tng_data->long_stride_length), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->long_stride_length, sizeof(tng_data->long_stride_length), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } if(block->block_version >= 3) { - if(tng_file_input_numerical(tng_data, - &tng_data->distance_unit_exponential, - sizeof(tng_data->distance_unit_exponential), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->distance_unit_exponential, sizeof(tng_data->distance_unit_exponential), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2423,8 +2272,7 @@ static tng_function_status tng_general_info_block_write block->name = malloc(name_len + 1); if(!block->name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n", - (unsigned int)(name_len+1), __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n", (unsigned int)(name_len+1), __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_CRITICAL); } @@ -2432,11 +2280,9 @@ static tng_function_status tng_general_info_block_write strcpy(block->name, "GENERAL INFO"); block->id = TNG_GENERAL_INFO; - if(tng_general_info_block_len_calculate(tng_data, &block->block_contents_size) != - TNG_SUCCESS) + if(tng_general_info_block_len_calculate(tng_data, &block->block_contents_size) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot calculate length of general info block. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot calculate length of general info block. %s: %d\n", __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_CRITICAL); } @@ -2445,8 +2291,7 @@ static tng_function_status tng_general_info_block_write if(tng_block_header_write(tng_data, block) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", - tng_data->output_file_path, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", tng_data->output_file_path, __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_CRITICAL); } @@ -2456,112 +2301,88 @@ static tng_function_status tng_general_info_block_write md5_init(&md5_state); } - if(tng_fwritestr(tng_data, tng_data->first_program_name, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->first_program_name, hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, tng_data->last_program_name, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->last_program_name, hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, tng_data->first_user_name, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->first_user_name, hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, tng_data->last_user_name, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->last_user_name, hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, tng_data->first_computer_name, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->first_computer_name,hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, tng_data->last_computer_name, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->last_computer_name, hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, tng_data->first_pgp_signature, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->first_pgp_signature, hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, tng_data->last_pgp_signature, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->last_pgp_signature, hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, tng_data->forcefield_name, - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, tng_data->forcefield_name, hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->time, sizeof(tng_data->time), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->time, sizeof(tng_data->time), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->var_num_atoms_flag, - sizeof(tng_data->var_num_atoms_flag), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->var_num_atoms_flag, sizeof(tng_data->var_num_atoms_flag), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->frame_set_n_frames, - sizeof(tng_data->frame_set_n_frames), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->frame_set_n_frames, sizeof(tng_data->frame_set_n_frames), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->first_trajectory_frame_set_output_file_pos, - sizeof(tng_data->first_trajectory_frame_set_output_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->first_trajectory_frame_set_output_file_pos, sizeof(tng_data->first_trajectory_frame_set_output_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->last_trajectory_frame_set_output_file_pos, - sizeof(tng_data->last_trajectory_frame_set_output_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->last_trajectory_frame_set_output_file_pos, sizeof(tng_data->last_trajectory_frame_set_output_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->medium_stride_length, - sizeof(tng_data->medium_stride_length), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->medium_stride_length, sizeof(tng_data->medium_stride_length), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->long_stride_length, - sizeof(tng_data->long_stride_length), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->long_stride_length, sizeof(tng_data->long_stride_length), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->distance_unit_exponential, - sizeof(tng_data->distance_unit_exponential), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->distance_unit_exponential, sizeof(tng_data->distance_unit_exponential), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2569,12 +2390,10 @@ static tng_function_status tng_general_info_block_write { md5_finish(&md5_state, (md5_byte_t *)block->md5_hash); curr_file_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, header_file_pos + - 3 * sizeof(int64_t), SEEK_SET); + fseeko(tng_data->output_file, header_file_pos + 3 * sizeof(int64_t), SEEK_SET); if(fwrite(block->md5_hash, TNG_MD5_HASH_LEN, 1, tng_data->output_file) != 1) { - fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } fseeko(tng_data->output_file, curr_file_pos, SEEK_SET); @@ -2599,18 +2418,14 @@ static tng_function_status tng_chain_data_read(const tng_trajectory_t tng_data, const char hash_mode, md5_state_t *md5_state) { - if(tng_file_input_numerical(tng_data, &chain->id, - sizeof(chain->id), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &chain->id, sizeof(chain->id), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } tng_freadstr(tng_data, &chain->name, hash_mode, md5_state, __LINE__); - if(tng_file_input_numerical(tng_data, &chain->n_residues, - sizeof(chain->n_residues), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &chain->n_residues, sizeof(chain->n_residues), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2632,22 +2447,17 @@ static tng_function_status tng_chain_data_write(const tng_trajectory_t tng_data, const char hash_mode, md5_state_t *md5_state) { - if(tng_file_output_numerical(tng_data, &chain->id, - sizeof(chain->id), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &chain->id, sizeof(chain->id), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, chain->name, hash_mode, - md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, chain->name, hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &chain->n_residues, - sizeof(chain->n_residues), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &chain->n_residues, sizeof(chain->n_residues), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2669,18 +2479,14 @@ static tng_function_status tng_residue_data_read(const tng_trajectory_t tng_data const char hash_mode, md5_state_t *md5_state) { - if(tng_file_input_numerical(tng_data, &residue->id, - sizeof(residue->id), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &residue->id, sizeof(residue->id), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } tng_freadstr(tng_data, &residue->name, hash_mode, md5_state, __LINE__); - if(tng_file_input_numerical(tng_data, &residue->n_atoms, - sizeof(residue->n_atoms), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &residue->n_atoms, sizeof(residue->n_atoms), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2702,22 +2508,17 @@ static tng_function_status tng_residue_data_write(const tng_trajectory_t tng_dat const char hash_mode, md5_state_t *md5_state) { - if(tng_file_output_numerical(tng_data, &residue->id, - sizeof(residue->id), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &residue->id, sizeof(residue->id), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, residue->name, hash_mode, - md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, residue->name, hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &residue->n_atoms, - sizeof(residue->n_atoms), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &residue->n_atoms, sizeof(residue->n_atoms), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2739,9 +2540,7 @@ static tng_function_status tng_atom_data_read(const tng_trajectory_t tng_data, const char hash_mode, md5_state_t *md5_state) { - if(tng_file_input_numerical(tng_data, &atom->id, - sizeof(atom->id), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &atom->id, sizeof(atom->id), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2767,21 +2566,17 @@ static tng_function_status tng_atom_data_write(const tng_trajectory_t tng_data, const char hash_mode, md5_state_t *md5_state) { - if(tng_file_output_numerical(tng_data, &atom->id, - sizeof(atom->id), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &atom->id, sizeof(atom->id), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, atom->name, hash_mode, - md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, atom->name, hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_fwritestr(tng_data, atom->atom_type, hash_mode, - md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, atom->atom_type, hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2810,8 +2605,7 @@ static tng_function_status tng_molecules_block_len_calculate molecule->name = malloc(1); if(!molecule->name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } molecule->name[0] = 0; @@ -2828,8 +2622,7 @@ static tng_function_status tng_molecules_block_len_calculate chain->name = malloc(1); if(!chain->name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } chain->name[0] = 0; @@ -2851,8 +2644,7 @@ static tng_function_status tng_molecules_block_len_calculate residue->name = malloc(1); if(!residue->name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } residue->name[0] = 0; @@ -2873,8 +2665,7 @@ static tng_function_status tng_molecules_block_len_calculate atom->name = malloc(1); if(!atom->name) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } atom->name[0] = 0; @@ -2886,8 +2677,7 @@ static tng_function_status tng_molecules_block_len_calculate atom->atom_type = malloc(1); if(!atom->atom_type) { - fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } atom->atom_type[0] = 0; @@ -2969,9 +2759,7 @@ static tng_function_status tng_molecules_block_read md5_init(&md5_state); } - if(tng_file_input_numerical(tng_data, &tng_data->n_molecules, - sizeof(tng_data->n_molecules), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->n_molecules, sizeof(tng_data->n_molecules), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -2983,13 +2771,10 @@ static tng_function_status tng_molecules_block_read tng_data->n_particles = 0; - tng_data->molecules = malloc(tng_data->n_molecules * - sizeof(struct tng_molecule)); + tng_data->molecules = malloc(tng_data->n_molecules * sizeof(struct tng_molecule)); if(!tng_data->molecules) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - tng_data->n_molecules * sizeof(struct tng_molecule), - __FILE__, __LINE__); + 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); } @@ -2999,13 +2784,10 @@ static tng_function_status tng_molecules_block_read { free(tng_data->molecule_cnt_list); } - tng_data->molecule_cnt_list = malloc(sizeof(int64_t) * - tng_data->n_molecules); + tng_data->molecule_cnt_list = malloc(sizeof(int64_t) * tng_data->n_molecules); if(!tng_data->molecule_cnt_list) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - tng_data->n_molecules * sizeof(struct tng_molecule), - __FILE__, __LINE__); + 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); } } @@ -3017,9 +2799,7 @@ static tng_function_status tng_molecules_block_read molecule->name = 0; - if(tng_file_input_numerical(tng_data, &molecule->id, - sizeof(molecule->id), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &molecule->id, sizeof(molecule->id), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3027,56 +2807,42 @@ static tng_function_status tng_molecules_block_read /* fprintf(stderr, "TNG library: Read id: %"PRId64" offset: %d\n", molecule->id, offset);*/ tng_freadstr(tng_data, &molecule->name, hash_mode, &md5_state, __LINE__); - if(tng_file_input_numerical(tng_data, &molecule->quaternary_str, - sizeof(molecule->quaternary_str), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &molecule->quaternary_str, sizeof(molecule->quaternary_str), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } if(!tng_data->var_num_atoms_flag) { - if(tng_file_input_numerical(tng_data, &tng_data->molecule_cnt_list[i], - sizeof(int64_t), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->molecule_cnt_list[i], sizeof(int64_t), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } } - if(tng_file_input_numerical(tng_data, &molecule->n_chains, - sizeof(molecule->n_chains), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &molecule->n_chains, sizeof(molecule->n_chains), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &molecule->n_residues, - sizeof(molecule->n_residues), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &molecule->n_residues, sizeof(molecule->n_residues), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &molecule->n_atoms, - sizeof(molecule->n_atoms), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &molecule->n_atoms, sizeof(molecule->n_atoms), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - tng_data->n_particles += molecule->n_atoms * - tng_data->molecule_cnt_list[i]; + tng_data->n_particles += molecule->n_atoms * tng_data->molecule_cnt_list[i]; if(molecule->n_chains > 0) { - molecule->chains = malloc(molecule->n_chains * - sizeof(struct tng_chain)); + molecule->chains = malloc(molecule->n_chains * sizeof(struct tng_chain)); if(!molecule->chains) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - molecule->n_chains * sizeof(struct tng_chain), - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", molecule->n_chains * sizeof(struct tng_chain), __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -3089,13 +2855,10 @@ static tng_function_status tng_molecules_block_read if(molecule->n_residues > 0) { - molecule->residues = malloc(molecule->n_residues * - sizeof(struct tng_residue)); + molecule->residues = malloc(molecule->n_residues * sizeof(struct tng_residue)); if(!molecule->residues) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - molecule->n_residues * sizeof(struct tng_residue), - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", molecule->n_residues * sizeof(struct tng_residue), __FILE__, __LINE__); if(molecule->chains) { free(molecule->chains); @@ -3111,13 +2874,10 @@ static tng_function_status tng_molecules_block_read residue = 0; } - molecule->atoms = malloc(molecule->n_atoms * - sizeof(struct tng_atom)); + molecule->atoms = malloc(molecule->n_atoms * sizeof(struct tng_atom)); if(!molecule->atoms) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - molecule->n_atoms * sizeof(struct tng_atom), - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", molecule->n_atoms * sizeof(struct tng_atom), __FILE__, __LINE__); if(molecule->chains) { free(molecule->chains); @@ -3222,22 +2982,17 @@ static tng_function_status tng_molecules_block_read } } - if(tng_file_input_numerical(tng_data, &molecule->n_bonds, - sizeof(molecule->n_bonds), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &molecule->n_bonds, sizeof(molecule->n_bonds), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } if(molecule->n_bonds > 0) { - tng_data->molecules[i].bonds = malloc(molecule->n_bonds * - sizeof(struct tng_bond)); + tng_data->molecules[i].bonds = malloc(molecule->n_bonds * sizeof(struct tng_bond)); if(!molecule->bonds) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - molecule->n_bonds * sizeof(struct tng_bond), - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", molecule->n_bonds * sizeof(struct tng_bond), __FILE__, __LINE__); if(molecule->chains) { free(molecule->chains); @@ -3260,16 +3015,12 @@ static tng_function_status tng_molecules_block_read for(j=0; j<molecule->n_bonds; j++) { - if(tng_file_input_numerical(tng_data, &bond->from_atom_id, - sizeof(bond->from_atom_id), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &bond->from_atom_id, sizeof(bond->from_atom_id), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &bond->to_atom_id, - sizeof(bond->to_atom_id), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &bond->to_atom_id, sizeof(bond->to_atom_id), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3294,8 +3045,7 @@ static tng_function_status tng_molecules_block_read { if(strncmp(block->md5_hash, hash, TNG_MD5_HASH_LEN) != 0) { - fprintf(stderr, "TNG library: Molecules block contents corrupt. Hashes do not match. " - "%s: %d\n", __FILE__, __LINE__); + fprintf(stderr, "TNG library: Molecules block contents corrupt. Hashes do not match. %s: %d\n", __FILE__, __LINE__); } } } @@ -3343,8 +3093,7 @@ static tng_function_status tng_molecules_block_write block->name = malloc(name_len + 1); if(!block->name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", - name_len+1, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", name_len+1, __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_CRITICAL); } @@ -3352,11 +3101,9 @@ static tng_function_status tng_molecules_block_write strcpy(block->name, "MOLECULES"); block->id = TNG_MOLECULES; - if(tng_molecules_block_len_calculate(tng_data, &block->block_contents_size) != - TNG_SUCCESS) + if(tng_molecules_block_len_calculate(tng_data, &block->block_contents_size) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot calculate length of molecules block. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot calculate length of molecules block. %s: %d\n", __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_CRITICAL); } @@ -3365,8 +3112,7 @@ static tng_function_status tng_molecules_block_write if(tng_block_header_write(tng_data, block) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", - tng_data->output_file_path, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", tng_data->output_file_path, __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_CRITICAL); } @@ -3376,9 +3122,7 @@ static tng_function_status tng_molecules_block_write md5_init(&md5_state); } - if(tng_file_output_numerical(tng_data, &tng_data->n_molecules, - sizeof(tng_data->n_molecules), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->n_molecules, sizeof(tng_data->n_molecules), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3387,9 +3131,7 @@ static tng_function_status tng_molecules_block_write { molecule = &tng_data->molecules[i]; - if(tng_file_output_numerical(tng_data, &molecule->id, - sizeof(molecule->id), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &molecule->id, sizeof(molecule->id), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3399,40 +3141,30 @@ static tng_function_status tng_molecules_block_write return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &molecule->quaternary_str, - sizeof(molecule->quaternary_str), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &molecule->quaternary_str, sizeof(molecule->quaternary_str), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } if(!tng_data->var_num_atoms_flag) { - if(tng_file_output_numerical(tng_data, &tng_data->molecule_cnt_list[i], - sizeof(int64_t), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->molecule_cnt_list[i], sizeof(int64_t), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } } - if(tng_file_output_numerical(tng_data, &molecule->n_chains, - sizeof(molecule->n_chains), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &molecule->n_chains, sizeof(molecule->n_chains), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &molecule->n_residues, - sizeof(molecule->n_residues), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &molecule->n_residues, sizeof(molecule->n_residues), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &molecule->n_atoms, - sizeof(molecule->n_atoms), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &molecule->n_atoms, sizeof(molecule->n_atoms), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3492,9 +3224,7 @@ static tng_function_status tng_molecules_block_write } } - if(tng_file_output_numerical(tng_data, &molecule->n_bonds, - sizeof(molecule->n_bonds), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &molecule->n_bonds, sizeof(molecule->n_bonds), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3502,16 +3232,12 @@ static tng_function_status tng_molecules_block_write bond = molecule->bonds; for(j = 0; j < molecule->n_bonds; j++) { - if(tng_file_output_numerical(tng_data, &bond->from_atom_id, - sizeof(bond->from_atom_id), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &bond->from_atom_id, sizeof(bond->from_atom_id),hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &bond->to_atom_id, - sizeof(bond->to_atom_id), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &bond->to_atom_id, sizeof(bond->to_atom_id),hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3523,12 +3249,10 @@ static tng_function_status tng_molecules_block_write { md5_finish(&md5_state, (md5_byte_t *)block->md5_hash); curr_file_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, header_file_pos + - 3 * sizeof(int64_t), SEEK_SET); + fseeko(tng_data->output_file, header_file_pos + 3 * sizeof(int64_t), SEEK_SET); if(fwrite(block->md5_hash, TNG_MD5_HASH_LEN, 1, tng_data->output_file) != 1) { - fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } fseeko(tng_data->output_file, curr_file_pos, SEEK_SET); @@ -3569,8 +3293,7 @@ static tng_function_status tng_frame_set_block_read const char hash_mode) { int64_t file_pos, start_pos, i, prev_n_particles; - tng_trajectory_frame_set_t frame_set = - &tng_data->current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; char hash[TNG_MD5_HASH_LEN]; md5_state_t md5_state; @@ -3594,9 +3317,7 @@ static tng_function_status tng_frame_set_block_read { md5_init(&md5_state); } - if(tng_file_input_numerical(tng_data, &frame_set->first_frame, - sizeof(frame_set->first_frame), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->first_frame, sizeof(frame_set->first_frame), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3616,28 +3337,22 @@ static tng_function_status tng_frame_set_block_read * it is of correct size. */ if(!frame_set->molecule_cnt_list) { - frame_set->molecule_cnt_list = - malloc(sizeof(int64_t) * tng_data->n_molecules); + frame_set->molecule_cnt_list = malloc(sizeof(int64_t) * tng_data->n_molecules); if(!frame_set->molecule_cnt_list) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - sizeof(int64_t) * tng_data->n_molecules, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", sizeof(int64_t) * tng_data->n_molecules, __FILE__, __LINE__); return(TNG_CRITICAL); } } for(i = 0; i < tng_data->n_molecules; i++) { - if(tng_file_input_numerical(tng_data, &frame_set->molecule_cnt_list[i], - sizeof(int64_t), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->molecule_cnt_list[i], sizeof(int64_t), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - frame_set->n_particles += tng_data->molecules[i].n_atoms * - frame_set->molecule_cnt_list[i]; + frame_set->n_particles += tng_data->molecules[i].n_atoms * frame_set->molecule_cnt_list[i]; } if(prev_n_particles && frame_set->n_particles != prev_n_particles) { @@ -3645,60 +3360,44 @@ static tng_function_status tng_frame_set_block_read } } - if(tng_file_input_numerical(tng_data, &frame_set->next_frame_set_file_pos, - sizeof(frame_set->next_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->next_frame_set_file_pos, sizeof(frame_set->next_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &frame_set->prev_frame_set_file_pos, - sizeof(frame_set->prev_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->prev_frame_set_file_pos, sizeof(frame_set->prev_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &frame_set->medium_stride_next_frame_set_file_pos, - sizeof(frame_set->medium_stride_next_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->medium_stride_next_frame_set_file_pos, sizeof(frame_set->medium_stride_next_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &frame_set->medium_stride_prev_frame_set_file_pos, - sizeof(frame_set->medium_stride_prev_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->medium_stride_prev_frame_set_file_pos, sizeof(frame_set->medium_stride_prev_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &frame_set->long_stride_next_frame_set_file_pos, - sizeof(frame_set->long_stride_next_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->long_stride_next_frame_set_file_pos, sizeof(frame_set->long_stride_next_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &frame_set->long_stride_prev_frame_set_file_pos, - sizeof(frame_set->long_stride_prev_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->long_stride_prev_frame_set_file_pos, sizeof(frame_set->long_stride_prev_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } if(block->block_version >= 3) { - if(tng_file_input_numerical(tng_data, &frame_set->first_frame_time, - sizeof(frame_set->first_frame_time), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &frame_set->first_frame_time, sizeof(frame_set->first_frame_time), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &tng_data->time_per_frame, - sizeof(tng_data->time_per_frame), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &tng_data->time_per_frame, sizeof(tng_data->time_per_frame), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3760,8 +3459,7 @@ static tng_function_status tng_frame_set_block_write char *temp_name; int64_t i, header_file_pos, curr_file_pos; unsigned int name_len; - tng_trajectory_frame_set_t frame_set = - &tng_data->current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; md5_state_t md5_state; if(tng_output_file_init(tng_data) != TNG_SUCCESS) @@ -3776,8 +3474,7 @@ static tng_function_status tng_frame_set_block_write temp_name = realloc(block->name, name_len + 1); if(!temp_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n", - name_len+1, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n", name_len+1, __FILE__, __LINE__); free(block->name); block->name = 0; return(TNG_CRITICAL); @@ -3787,11 +3484,9 @@ static tng_function_status tng_frame_set_block_write strcpy(block->name, "TRAJECTORY FRAME SET"); block->id = TNG_TRAJECTORY_FRAME_SET; - if(tng_frame_set_block_len_calculate(tng_data, &block->block_contents_size) != - TNG_SUCCESS) + if(tng_frame_set_block_len_calculate(tng_data, &block->block_contents_size) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot calculate length of frame set block. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot calculate length of frame set block. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -3799,8 +3494,7 @@ static tng_function_status tng_frame_set_block_write if(tng_block_header_write(tng_data, block) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", - tng_data->output_file_path, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", tng_data->output_file_path, __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -3808,16 +3502,12 @@ static tng_function_status tng_frame_set_block_write { md5_init(&md5_state); } - if(tng_file_output_numerical(tng_data, &frame_set->first_frame, - sizeof(frame_set->first_frame), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->first_frame, sizeof(frame_set->first_frame), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &frame_set->n_frames, - sizeof(frame_set->n_frames), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->n_frames, sizeof(frame_set->n_frames), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3826,67 +3516,49 @@ static tng_function_status tng_frame_set_block_write { for(i = 0; i < tng_data->n_molecules; i++) { - if(tng_file_output_numerical(tng_data, &frame_set->molecule_cnt_list[i], - sizeof(int64_t), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->molecule_cnt_list[i], sizeof(int64_t), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } } } - if(tng_file_output_numerical(tng_data, &frame_set->next_frame_set_file_pos, - sizeof(frame_set->next_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->next_frame_set_file_pos, sizeof(frame_set->next_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &frame_set->prev_frame_set_file_pos, - sizeof(frame_set->prev_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->prev_frame_set_file_pos, sizeof(frame_set->prev_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &frame_set->medium_stride_next_frame_set_file_pos, - sizeof(frame_set->medium_stride_next_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->medium_stride_next_frame_set_file_pos, sizeof(frame_set->medium_stride_next_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &frame_set->medium_stride_prev_frame_set_file_pos, - sizeof(frame_set->medium_stride_prev_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->medium_stride_prev_frame_set_file_pos, sizeof(frame_set->medium_stride_prev_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &frame_set->long_stride_next_frame_set_file_pos, - sizeof(frame_set->long_stride_next_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->long_stride_next_frame_set_file_pos, sizeof(frame_set->long_stride_next_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &frame_set->long_stride_prev_frame_set_file_pos, - sizeof(frame_set->long_stride_prev_frame_set_file_pos), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->long_stride_prev_frame_set_file_pos, sizeof(frame_set->long_stride_prev_frame_set_file_pos), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &frame_set->first_frame_time, - sizeof(frame_set->first_frame_time), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &frame_set->first_frame_time, sizeof(frame_set->first_frame_time), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &tng_data->time_per_frame, - sizeof(tng_data->time_per_frame), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &tng_data->time_per_frame, sizeof(tng_data->time_per_frame), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -3894,12 +3566,10 @@ static tng_function_status tng_frame_set_block_write { md5_finish(&md5_state, (md5_byte_t *)block->md5_hash); curr_file_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, header_file_pos + - 3 * sizeof(int64_t), SEEK_SET); + fseeko(tng_data->output_file, header_file_pos + 3 * sizeof(int64_t), SEEK_SET); if(fwrite(block->md5_hash, TNG_MD5_HASH_LEN, 1, tng_data->output_file) != 1) { - fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } fseeko(tng_data->output_file, curr_file_pos, SEEK_SET); @@ -3908,10 +3578,7 @@ static tng_function_status tng_frame_set_block_write return(TNG_SUCCESS); } -static tng_function_status tng_trajectory_mapping_block_len_calculate - (const tng_trajectory_t tng_data, - const int64_t n_particles, - int64_t *len) +static tng_function_status tng_trajectory_mapping_block_len_calculate(const tng_trajectory_t tng_data, const int64_t n_particles, int64_t *len) { (void)tng_data; *len = sizeof(int64_t) * (2 + n_particles); @@ -3936,8 +3603,7 @@ static tng_function_status tng_trajectory_mapping_block_read const char hash_mode) { int64_t start_pos, i; - tng_trajectory_frame_set_t frame_set = - &tng_data->current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; tng_particle_mapping_t mapping, mappings; char hash[TNG_MD5_HASH_LEN]; md5_state_t md5_state; @@ -3953,13 +3619,10 @@ static tng_function_status tng_trajectory_mapping_block_read * size or if the contents can be read. */ frame_set->n_mapping_blocks++; - mappings = realloc(frame_set->mappings, - sizeof(struct tng_particle_mapping) * - frame_set->n_mapping_blocks); + mappings = realloc(frame_set->mappings, sizeof(struct tng_particle_mapping) * frame_set->n_mapping_blocks); if(!mappings) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", - block->block_contents_size, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", block->block_contents_size, __FILE__, __LINE__); free(frame_set->mappings); frame_set->mappings = 0; return(TNG_CRITICAL); @@ -3973,26 +3636,20 @@ static tng_function_status tng_trajectory_mapping_block_read md5_init(&md5_state); } - if(tng_file_input_numerical(tng_data, &mapping->num_first_particle, - sizeof(mapping->num_first_particle), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &mapping->num_first_particle, sizeof(mapping->num_first_particle), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &mapping->n_particles, - sizeof(mapping->n_particles), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &mapping->n_particles, sizeof(mapping->n_particles), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - mapping->real_particle_numbers = malloc(mapping->n_particles * - sizeof(int64_t)); + mapping->real_particle_numbers = malloc(mapping->n_particles * sizeof(int64_t)); if(!mapping->real_particle_numbers) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - mapping->n_particles * sizeof(int64_t), __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", mapping->n_particles * sizeof(int64_t), __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -4002,9 +3659,7 @@ static tng_function_status tng_trajectory_mapping_block_read { for(i = 0; i < mapping->n_particles; i++) { - if(tng_file_input_numerical(tng_data, &mapping->real_particle_numbers[i], - sizeof(int64_t), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &mapping->real_particle_numbers[i], sizeof(int64_t), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -4013,8 +3668,7 @@ static tng_function_status tng_trajectory_mapping_block_read /* Otherwise the data can be read all at once */ else { - if(fread(mapping->real_particle_numbers, mapping->n_particles * sizeof(int64_t), - 1, tng_data->input_file) == 0) + if(fread(mapping->real_particle_numbers, mapping->n_particles * sizeof(int64_t), 1, tng_data->input_file) == 0) { fprintf(stderr, "TNG library: Cannot read block. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); @@ -4036,8 +3690,7 @@ static tng_function_status tng_trajectory_mapping_block_read { if(strncmp(block->md5_hash, hash, TNG_MD5_HASH_LEN) != 0) { - fprintf(stderr, "TNG library: Particle mapping block contents corrupt. Hashes do not match. " - "%s: %d\n", __FILE__, __LINE__); + fprintf(stderr, "TNG library: Particle mapping block contents corrupt. Hashes do not match. %s: %d\n", __FILE__, __LINE__); } } } @@ -4060,25 +3713,18 @@ static tng_function_status tng_trajectory_mapping_block_read * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error * has occurred or TNG_CRITICAL (2) if a major error has occured. */ -static tng_function_status tng_trajectory_mapping_block_write - (const tng_trajectory_t tng_data, - const tng_gen_block_t block, - const int mapping_block_nr, - const char hash_mode) +static tng_function_status tng_trajectory_mapping_block_write(const tng_trajectory_t tng_data, const tng_gen_block_t block, const int mapping_block_nr, const char hash_mode) { int64_t header_file_pos, curr_file_pos; char *temp_name; int i; unsigned int name_len; md5_state_t md5_state; - tng_particle_mapping_t mapping = - &tng_data->current_trajectory_frame_set.mappings[mapping_block_nr]; + tng_particle_mapping_t mapping = &tng_data->current_trajectory_frame_set.mappings[mapping_block_nr]; - if(mapping_block_nr >= - tng_data->current_trajectory_frame_set.n_mapping_blocks) + if(mapping_block_nr >= tng_data->current_trajectory_frame_set.n_mapping_blocks) { - fprintf(stderr, "TNG library: Mapping block index out of bounds. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Mapping block index out of bounds. %s: %d\n", __FILE__, __LINE__); return(TNG_FAILURE); } @@ -4094,8 +3740,7 @@ static tng_function_status tng_trajectory_mapping_block_write temp_name = realloc(block->name, name_len + 1); if(!temp_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n", - name_len+1, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%u bytes). %s: %d\n", name_len+1, __FILE__, __LINE__); free(block->name); block->name = 0; return(TNG_CRITICAL); @@ -4105,13 +3750,9 @@ static tng_function_status tng_trajectory_mapping_block_write strcpy(block->name, "PARTICLE MAPPING"); block->id = TNG_PARTICLE_MAPPING; - if(tng_trajectory_mapping_block_len_calculate(tng_data, - mapping->n_particles, - &block->block_contents_size) != - TNG_SUCCESS) + if(tng_trajectory_mapping_block_len_calculate(tng_data, mapping->n_particles, &block->block_contents_size) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot calculate length of atom mapping block. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot calculate length of atom mapping block. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -4119,8 +3760,7 @@ static tng_function_status tng_trajectory_mapping_block_write if(tng_block_header_write(tng_data, block) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", - tng_data->output_file_path, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", tng_data->output_file_path, __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -4128,16 +3768,12 @@ static tng_function_status tng_trajectory_mapping_block_write { md5_init(&md5_state); } - if(tng_file_output_numerical(tng_data, &mapping->num_first_particle, - sizeof(mapping->num_first_particle), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &mapping->num_first_particle, sizeof(mapping->num_first_particle), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &mapping->n_particles, - sizeof(mapping->n_particles), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &mapping->n_particles, sizeof(mapping->n_particles), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -4146,9 +3782,7 @@ static tng_function_status tng_trajectory_mapping_block_write { for(i = 0; i < mapping->n_particles; i++) { - if(tng_file_output_numerical(tng_data, &mapping->real_particle_numbers[i], - sizeof(int64_t), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &mapping->real_particle_numbers[i], sizeof(int64_t), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -4156,17 +3790,14 @@ static tng_function_status tng_trajectory_mapping_block_write } else { - if(fwrite(mapping->real_particle_numbers, - mapping->n_particles * sizeof(int64_t), - 1, tng_data->output_file) != 1) + if(fwrite(mapping->real_particle_numbers, mapping->n_particles * sizeof(int64_t), 1, tng_data->output_file) != 1) { fprintf(stderr, "TNG library: Could not write block data. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } if(hash_mode == TNG_USE_HASH) { - md5_append(&md5_state, (md5_byte_t *)mapping->real_particle_numbers, - mapping->n_particles * sizeof(int64_t)); + md5_append(&md5_state, (md5_byte_t *)mapping->real_particle_numbers, mapping->n_particles * sizeof(int64_t)); } } @@ -4174,12 +3805,10 @@ static tng_function_status tng_trajectory_mapping_block_write { md5_finish(&md5_state, (md5_byte_t *)block->md5_hash); curr_file_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, header_file_pos + - 3 * sizeof(int64_t), SEEK_SET); + fseeko(tng_data->output_file, header_file_pos + 3 * sizeof(int64_t), SEEK_SET); if(fwrite(block->md5_hash, TNG_MD5_HASH_LEN, 1, tng_data->output_file) != 1) { - fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } fseeko(tng_data->output_file, curr_file_pos, SEEK_SET); @@ -4200,23 +3829,17 @@ static tng_function_status tng_particle_data_block_create (const tng_trajectory_t tng_data, const char block_type_flag) { - tng_trajectory_frame_set_t frame_set = - &tng_data->current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; tng_data_t data; if(block_type_flag == TNG_TRAJECTORY_BLOCK) { frame_set->n_particle_data_blocks++; - data = realloc(frame_set->tr_particle_data, - sizeof(struct tng_data) * - frame_set->n_particle_data_blocks); + data = realloc(frame_set->tr_particle_data, sizeof(struct tng_data) * frame_set->n_particle_data_blocks); if(!data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", - sizeof(struct tng_data) * - frame_set->n_particle_data_blocks, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", sizeof(struct tng_data) * frame_set->n_particle_data_blocks,__FILE__, __LINE__); free(frame_set->tr_particle_data); frame_set->tr_particle_data = 0; return(TNG_CRITICAL); @@ -4226,15 +3849,10 @@ static tng_function_status tng_particle_data_block_create else { tng_data->n_particle_data_blocks++; - data = realloc(tng_data->non_tr_particle_data, - sizeof(struct tng_data) * - tng_data->n_particle_data_blocks); + data = realloc(tng_data->non_tr_particle_data, sizeof(struct tng_data) * tng_data->n_particle_data_blocks); if(!data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", - sizeof(struct tng_data) * - tng_data->n_particle_data_blocks, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", sizeof(struct tng_data) * tng_data->n_particle_data_blocks, __FILE__, __LINE__); free(tng_data->non_tr_particle_data); tng_data->non_tr_particle_data = 0; return(TNG_CRITICAL); @@ -4809,9 +4427,7 @@ static tng_function_status tng_allocate_particle_data_mem n_particles); if(!data->strings[i]) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - sizeof(union data_values *) * n_particles, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n",sizeof(union data_values *) * n_particles,__FILE__, __LINE__); return(TNG_CRITICAL); } for(j = 0; j < n_particles; j++) @@ -4820,9 +4436,7 @@ static tng_function_status tng_allocate_particle_data_mem n_values_per_frame); if(!data->strings[i][j]) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRIu64" bytes). %s: %d\n", - sizeof(union data_values) * n_values_per_frame, - __FILE__, __LINE__); + 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); } for(k = 0; k < n_values_per_frame; k++) @@ -4847,9 +4461,7 @@ static tng_function_status tng_allocate_particle_data_mem size = sizeof(double); } - values = realloc(data->values, - size * frame_alloc * - n_particles * n_values_per_frame); + values = realloc(data->values, size * frame_alloc * n_particles * n_values_per_frame); if(!values) { fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", @@ -4865,18 +4477,14 @@ static tng_function_status tng_allocate_particle_data_mem return(TNG_SUCCESS); } -static tng_function_status tng_particle_data_find - (const tng_trajectory_t tng_data, - const int64_t id, - tng_data_t *data) +static tng_function_status tng_particle_data_find(const tng_trajectory_t tng_data,const int64_t id,tng_data_t *data) { int64_t block_index, i; tng_trajectory_frame_set_t frame_set = &tng_data-> current_trajectory_frame_set; char block_type_flag; - if(tng_data->current_trajectory_frame_set_input_file_pos > 0 || - tng_data->current_trajectory_frame_set_output_file_pos > 0) + if(tng_data->current_trajectory_frame_set_input_file_pos > 0 || tng_data->current_trajectory_frame_set_output_file_pos > 0) { block_type_flag = TNG_TRAJECTORY_BLOCK; } @@ -4923,12 +4531,10 @@ static tng_function_status tng_data_find tng_data_t *data) { int64_t block_index, i; - tng_trajectory_frame_set_t frame_set = &tng_data-> - current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; char block_type_flag; - if(tng_data->current_trajectory_frame_set_input_file_pos > 0 || - tng_data->current_trajectory_frame_set_output_file_pos > 0) + if(tng_data->current_trajectory_frame_set_input_file_pos > 0 || tng_data->current_trajectory_frame_set_output_file_pos > 0) { block_type_flag = TNG_TRAJECTORY_BLOCK; } @@ -5019,8 +4625,7 @@ static tng_function_status tng_data_block_len_calculate size = sizeof(double); } - *len = sizeof(char) * 2 + sizeof(data->n_values_per_frame) + - sizeof(data->codec_id); + *len = sizeof(char) * 2 + sizeof(data->n_values_per_frame) + sizeof(data->codec_id); if(is_particle_data) { *len += sizeof(num_first_particle) + sizeof(n_particles); @@ -5028,8 +4633,7 @@ static tng_function_status tng_data_block_len_calculate if(stride_length > 1) { - *len += sizeof(data->first_frame_with_data) + - sizeof(data->stride_length); + *len += sizeof(data->first_frame_with_data) + sizeof(data->stride_length); } if(data->codec_id != TNG_UNCOMPRESSED) @@ -5051,8 +4655,7 @@ static tng_function_status tng_data_block_len_calculate for(i = 0; i < n_frames; i++) { first_dim_values = data->strings[i]; - for(j = num_first_particle; j < num_first_particle + n_particles; - j++) + for(j = num_first_particle; j < num_first_particle + n_particles; j++) { second_dim_values = first_dim_values[j]; for(k = 0; k < data->n_values_per_frame; k++) @@ -5095,21 +4698,17 @@ static tng_function_status tng_data_block_create (const tng_trajectory_t tng_data, const char block_type_flag) { - tng_trajectory_frame_set_t frame_set = - &tng_data->current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; tng_data_t data; if(block_type_flag == TNG_TRAJECTORY_BLOCK) { frame_set->n_data_blocks++; - data = realloc(frame_set->tr_data, sizeof(struct tng_data) * - frame_set->n_data_blocks); + data = realloc(frame_set->tr_data, sizeof(struct tng_data) * frame_set->n_data_blocks); if(!data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", - sizeof(struct tng_data) * frame_set->n_data_blocks, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", sizeof(struct tng_data) * frame_set->n_data_blocks, __FILE__, __LINE__); free(frame_set->tr_data); frame_set->tr_data = 0; return(TNG_CRITICAL); @@ -5119,13 +4718,10 @@ static tng_function_status tng_data_block_create else { tng_data->n_data_blocks++; - data = realloc(tng_data->non_tr_data, sizeof(struct tng_data) * - tng_data->n_data_blocks); + data = realloc(tng_data->non_tr_data, sizeof(struct tng_data) * tng_data->n_data_blocks); if(!data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", - sizeof(struct tng_data) * tng_data->n_data_blocks, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", sizeof(struct tng_data) * tng_data->n_data_blocks, __FILE__, __LINE__); free(tng_data->non_tr_data); tng_data->non_tr_data = 0; return(TNG_CRITICAL); @@ -5198,9 +4794,7 @@ static tng_function_status tng_allocate_data_mem data->strings[0][i] = malloc(sizeof(char *) * n_values_per_frame); if(!data->strings[0][i]) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", - n_values_per_frame, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", n_values_per_frame, __FILE__, __LINE__); return(TNG_CRITICAL); } for(j = 0; j < n_values_per_frame; j++) @@ -5224,15 +4818,10 @@ static tng_function_status tng_allocate_data_mem size = sizeof(double); } - values = realloc(data->values, - size * frame_alloc * - n_values_per_frame); + values = realloc(data->values, size * frame_alloc * n_values_per_frame); if(!values) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", - size * frame_alloc * - n_values_per_frame, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", size * frame_alloc * n_values_per_frame, __FILE__, __LINE__); free(data->values); data->values = 0; return(TNG_CRITICAL); @@ -5292,8 +4881,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, int size, len; char ***first_dim_values, **second_dim_values; tng_data_t data; - tng_trajectory_frame_set_t frame_set = - &tng_data->current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; char block_type_flag, *contents; tng_bool is_particle_data; tng_function_status stat; @@ -5304,8 +4892,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, #ifndef USE_ZLIB if(codec_id == TNG_GZIP_COMPRESSION) { - fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__, __LINE__); return(TNG_FAILURE); } #endif @@ -5334,8 +4921,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, { if(codec_id == TNG_XTC_COMPRESSION || codec_id == TNG_TNG_COMPRESSION) { - fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__, __LINE__); return(TNG_FAILURE); } is_particle_data = TNG_FALSE; @@ -5373,8 +4959,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, if(stat != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot create data block. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot create data block. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -5382,13 +4967,11 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, { if(block_type_flag == TNG_TRAJECTORY_BLOCK) { - data = &frame_set->tr_particle_data[frame_set-> - n_particle_data_blocks - 1]; + data = &frame_set->tr_particle_data[frame_set-> n_particle_data_blocks - 1]; } else { - data = &tng_data->non_tr_particle_data[tng_data-> - n_particle_data_blocks - 1]; + data = &tng_data->non_tr_particle_data[tng_data-> n_particle_data_blocks - 1]; } } else @@ -5408,8 +4991,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, data->block_name = malloc(strlen(block->name) + 1); if(!data->block_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%ud bytes). %s: %d\n", - (unsigned int)strlen(block->name)+1, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%ud bytes). %s: %d\n",(unsigned int)strlen(block->name)+1, __FILE__, __LINE__); return(TNG_CRITICAL); } strcpy(data->block_name, block->name); @@ -5425,10 +5007,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, { data->dependency += TNG_PARTICLE_DEPENDENT; } - if(block_type_flag == TNG_TRAJECTORY_BLOCK && - (n_frames > 1 || - frame_set->n_frames == n_frames || - stride_length > 1)) + if(block_type_flag == TNG_TRAJECTORY_BLOCK && (n_frames > 1 || frame_set->n_frames == n_frames || stride_length > 1)) { data->dependency += TNG_FRAME_DEPENDENT; } @@ -5461,8 +5040,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, contents = malloc(block_data_len); if(!contents) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", - block_data_len, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", block_data_len, __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -5490,29 +5068,29 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, fprintf(stderr, "TNG library: XTC compression not implemented yet.\n"); break; case TNG_TNG_COMPRESSION: -/* fprintf(stderr, "TNG library: Before TNG uncompression: %"PRId64"\n", block->block_contents_size);*/ - if(tng_uncompress(tng_data, block, datatype, - &contents, full_data_len) != TNG_SUCCESS) + if(tng_uncompress(tng_data, block, datatype, &contents, full_data_len) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Could not read tng compressed block data. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Could not read tng compressed block data. %s: %d\n", __FILE__, __LINE__); free(contents); return(TNG_CRITICAL); } -/* fprintf(stderr, "TNG library: After TNG uncompression: %"PRId64"\n", block->block_contents_size);*/ break; + case TNG_HRTC_COMPRESSION: + if(hrtc_uncompress(tng_data, datatype, &contents) != TNG_SUCCESS){ + fprintf(stderr, "TNG library: Could not read hrtc compressed block data. %s: %d\n", __FILE__, __LINE__); + free(contents); + return(TNG_CRITICAL); + } + break; + #ifdef USE_ZLIB case TNG_GZIP_COMPRESSION: - /* fprintf(stderr, "TNG library: Before compression: %"PRId64"\n", block->block_contents_size); */ - if(tng_gzip_uncompress(tng_data, &contents, - block_data_len, full_data_len) != TNG_SUCCESS) + if(tng_gzip_uncompress(tng_data, &contents, block_data_len, full_data_len) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Could not read gzipped block data. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Could not read gzipped block data. %s: %d\n", __FILE__, __LINE__); free(contents); return(TNG_CRITICAL); } - /* fprintf(stderr, "TNG library: After compression: %"PRId64"\n", block->block_contents_size); */ break; #endif } @@ -5528,19 +5106,15 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, { if(is_particle_data == TNG_TRUE) { - stat = tng_allocate_particle_data_mem(tng_data, data, n_frames, - stride_length, - tot_n_particles, n_values); + stat = tng_allocate_particle_data_mem(tng_data, data, n_frames, stride_length, tot_n_particles, n_values); } else { - stat = tng_allocate_data_mem(tng_data, data, n_frames, stride_length, - n_values); + stat = tng_allocate_data_mem(tng_data, data, n_frames, stride_length, n_values); } if(stat != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot allocate memory for data. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory for data. %s: %d\n", __FILE__, __LINE__); free(contents); return(TNG_CRITICAL); } @@ -5558,14 +5132,12 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, for(i = 0; i < n_frames_div; i++) { first_dim_values = data->strings[i]; - for(j = num_first_particle; j < num_first_particle + n_particles; - j++) + for(j = num_first_particle; j < num_first_particle + n_particles; j++) { second_dim_values = first_dim_values[j]; for(k = 0; k < n_values; k++) { - len = tng_min_size(strlen(contents+offset) + 1, - TNG_MAX_STR_LEN); + len = tng_min_size(strlen(contents+offset) + 1, TNG_MAX_STR_LEN); if(second_dim_values[k]) { free(second_dim_values[k]); @@ -5573,8 +5145,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, second_dim_values[k] = malloc(len); if(!second_dim_values[k]) { - fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", - len, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); free(contents); return(TNG_CRITICAL); } @@ -5590,8 +5161,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, { for(j = 0; j < n_values; j++) { - len = tng_min_size(strlen(contents+offset) + 1, - TNG_MAX_STR_LEN); + len = tng_min_size(strlen(contents+offset) + 1, TNG_MAX_STR_LEN); if(data->strings[0][i][j]) { free(data->strings[0][i][j]); @@ -5599,8 +5169,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, data->strings[0][i][j] = malloc(len); if(!data->strings[0][i][j]) { - fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", - len, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); free(contents); return(TNG_CRITICAL); } @@ -5614,8 +5183,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, { if(is_particle_data) { - memcpy((char *)data->values + n_frames_div * size * n_values * - num_first_particle, contents, full_data_len); + memcpy((char *)data->values + n_frames_div * size * n_values * num_first_particle, contents, full_data_len); } else { @@ -5632,8 +5200,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, (int32_t *)((char *)data->values + i)) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } } @@ -5648,8 +5215,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, (int64_t *)((char *)data->values + i)) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } } @@ -5679,12 +5245,7 @@ static tng_function_status tng_data_read(const tng_trajectory_t tng_data, * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major * error has occured. */ -static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, - const tng_gen_block_t block, - const int64_t block_index, - const tng_bool is_particle_data, - const tng_particle_mapping_t mapping, - const char hash_mode) +static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, const tng_gen_block_t block, const int64_t block_index, const tng_bool is_particle_data, const tng_particle_mapping_t mapping, const char hash_mode) { int64_t n_particles, num_first_particle, n_frames, stride_length; int64_t full_data_len, block_data_len, frame_step, data_start_pos; @@ -5694,8 +5255,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, tng_function_status stat; char temp, *temp_name, ***first_dim_values, **second_dim_values, *contents; double multiplier; - tng_trajectory_frame_set_t frame_set = - &tng_data->current_trajectory_frame_set; + tng_trajectory_frame_set_t frame_set = &tng_data->current_trajectory_frame_set; tng_data_t data; char block_type_flag; md5_state_t md5_state; @@ -5782,8 +5342,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, temp_name = realloc(block->name, len); if(!temp_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", len+1, - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", len+1, __FILE__, __LINE__); free(block->name); block->name = 0; return(TNG_CRITICAL); @@ -5807,8 +5366,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, n_frames -= (data->first_frame_with_data - frame_set->first_frame); } - frame_step = (n_frames % stride_length) ? n_frames / stride_length + 1: - n_frames / stride_length; + frame_step = (n_frames % stride_length) ? n_frames / stride_length + 1: n_frames / stride_length; /* TNG compression will use compression precision to get integers from * floating point data. The compression multiplier stores that information @@ -5847,25 +5405,17 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, if(data->dependency & TNG_PARTICLE_DEPENDENT) { - if(tng_data_block_len_calculate(tng_data, data, TNG_TRUE, n_frames, - frame_step, stride_length, num_first_particle, - n_particles, &data_start_pos, - &block->block_contents_size) != TNG_SUCCESS) + if(tng_data_block_len_calculate(tng_data, data, TNG_TRUE, n_frames, frame_step, stride_length, num_first_particle, n_particles, &data_start_pos, &block->block_contents_size) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot calculate length of particle data block. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot calculate length of particle data block. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } } else { - if(tng_data_block_len_calculate(tng_data, data, TNG_FALSE, n_frames, - frame_step, stride_length, 0, - 1, &data_start_pos, - &block->block_contents_size) != TNG_SUCCESS) + if(tng_data_block_len_calculate(tng_data, data, TNG_FALSE, n_frames, frame_step, stride_length, 0, 1, &data_start_pos, &block->block_contents_size) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot calculate length of non-particle data block. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot calculate length of non-particle data block. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } } @@ -5874,8 +5424,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, if(tng_block_header_write(tng_data, block) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", - tng_data->output_file_path, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot write header of file %s. %s: %d\n", tng_data->output_file_path, __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -5884,16 +5433,12 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, md5_init(&md5_state); } - if(tng_file_output_numerical(tng_data, &data->datatype, - sizeof(data->datatype), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &data->datatype, sizeof(data->datatype), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &data->dependency, - sizeof(data->dependency), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &data->dependency, sizeof(data->dependency), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -5908,33 +5453,25 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, { temp = 0; } - if(tng_file_output_numerical(tng_data, &temp, - sizeof(temp), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &temp, sizeof(temp), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } } - if(tng_file_output_numerical(tng_data, &data->n_values_per_frame, - sizeof(data->n_values_per_frame), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &data->n_values_per_frame, sizeof(data->n_values_per_frame), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &data->codec_id, - sizeof(data->codec_id), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &data->codec_id, sizeof(data->codec_id), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } if(data->codec_id != TNG_UNCOMPRESSED) { - if(tng_file_output_numerical(tng_data, &data->compression_multiplier, - sizeof(data->compression_multiplier), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &data->compression_multiplier, sizeof(data->compression_multiplier), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -5947,16 +5484,12 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, { data->first_frame_with_data = frame_set->first_frame; } - if(tng_file_output_numerical(tng_data, &data->first_frame_with_data, - sizeof(data->first_frame_with_data), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &data->first_frame_with_data, sizeof(data->first_frame_with_data), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &stride_length, - sizeof(stride_length), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &stride_length, sizeof(stride_length), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -5964,16 +5497,12 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, if(data->dependency & TNG_PARTICLE_DEPENDENT) { - if(tng_file_output_numerical(tng_data, &num_first_particle, - sizeof(num_first_particle), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &num_first_particle, sizeof(num_first_particle), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_output_numerical(tng_data, &n_particles, - sizeof(n_particles), - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &n_particles, sizeof(n_particles), hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -5994,8 +5523,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, second_dim_values = first_dim_values[j]; for(k = 0; k < data->n_values_per_frame; k++) { - if(tng_fwritestr(tng_data, second_dim_values[k], - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, second_dim_values[k], hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -6009,8 +5537,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, { for(j = 0; j < data->n_values_per_frame; j++) { - if(tng_fwritestr(tng_data, data->strings[0][i][j], - hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) + if(tng_fwritestr(tng_data, data->strings[0][i][j], hash_mode, &md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -6032,8 +5559,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, contents = malloc(full_data_len); if(!contents) { - fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", - full_data_len, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", full_data_len, __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -6043,19 +5569,15 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, switch(data->datatype) { case TNG_FLOAT_DATA: - if(data->codec_id == TNG_UNCOMPRESSED || data-> codec_id == TNG_GZIP_COMPRESSION || - data->codec_id == TNG_TNG_COMPRESSION) + if(data->codec_id == TNG_UNCOMPRESSED || data-> codec_id == TNG_GZIP_COMPRESSION || data->codec_id == TNG_TNG_COMPRESSION) { if(tng_data->output_endianness_swap_func_32) { for(i = 0; i < full_data_len; i+=size) { - if(tng_data->output_endianness_swap_func_32(tng_data, - (int32_t *)(contents + i)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_32(tng_data, (int32_t *)(contents + i)) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } } @@ -6069,13 +5591,9 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, for(i = 0; full_data_len; i+=size) { *(float *)(contents + i) *= (float)multiplier; - if(tng_data->output_endianness_swap_func_32 && - tng_data->output_endianness_swap_func_32(tng_data, - (int32_t *)(contents + i)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_32 && tng_data->output_endianness_swap_func_32(tng_data, (int32_t *)(contents + i)) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } } @@ -6086,12 +5604,9 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, { for(i = 0; i < full_data_len; i+=size) { - if(tng_data->output_endianness_swap_func_64(tng_data, - (int64_t *)(contents + i)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64(tng_data, (int64_t *)(contents + i)) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } } @@ -6104,12 +5619,9 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, { for(i = 0; i < full_data_len; i+=size) { - if(tng_data->output_endianness_swap_func_64(tng_data, - (int64_t *)(contents + i)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64(tng_data, (int64_t *)(contents + i)) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } } @@ -6123,13 +5635,9 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, for(i = 0; i < full_data_len; i+=size) { *(double *)(contents + i) *= multiplier; - if(tng_data->output_endianness_swap_func_64 && - tng_data->output_endianness_swap_func_64(tng_data, - (int64_t *)(contents + i)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64 && tng_data->output_endianness_swap_func_64(tng_data, (int64_t *)(contents + i)) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } } @@ -6153,13 +5661,27 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, data->codec_id = TNG_UNCOMPRESSED; break; case TNG_TNG_COMPRESSION: - stat = tng_compress(tng_data, block, frame_step, - n_particles, data->datatype, - &contents, &block_data_len); + stat = tng_compress(tng_data, block, frame_step, n_particles, data->datatype, &contents, &block_data_len); if(stat != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Could not write tng compressed block data. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Could not write tng compressed block data. %s: %d\n", __FILE__, __LINE__); + if(stat == TNG_CRITICAL) + { + return(TNG_CRITICAL); + } + /* Set the data again, but with no compression (to write only + * the relevant data) */ + data->codec_id = TNG_UNCOMPRESSED; + stat = tng_data_block_write(tng_data, block, block_index, is_particle_data, mapping, hash_mode); + free(contents); + return(stat); + } + break; + case TNG_HRTC_COMPRESSION: + stat = hrtc_compress(tng_data, frame_step, n_particles, data->datatype, &contents, &block_data_len); + if(stat != TNG_SUCCESS) + { + fprintf(stderr, "HRTC library: Could not write hrtc compressed block data. %s: %d\n", __FILE__, __LINE__); if(stat == TNG_CRITICAL) { return(TNG_CRITICAL); @@ -6167,24 +5689,19 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, /* Set the data again, but with no compression (to write only * the relevant data) */ data->codec_id = TNG_UNCOMPRESSED; - stat = tng_data_block_write(tng_data, block, - block_index, is_particle_data, mapping, - hash_mode); + stat = tng_data_block_write(tng_data, block, block_index, is_particle_data, mapping, hash_mode); free(contents); return(stat); } break; + #ifdef USE_ZLIB case TNG_GZIP_COMPRESSION: /* fprintf(stderr, "TNG library: Before compression: %"PRId64"\n", block->block_contents_size); */ - stat = tng_gzip_compress(tng_data, - &contents, - full_data_len, - &block_data_len); + stat = tng_gzip_compress(tng_data, &contents, full_data_len, &block_data_len); if(stat != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Could not write gzipped block data. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Could not write gzipped block data. %s: %d\n", __FILE__, __LINE__); if(stat == TNG_CRITICAL) { return(TNG_CRITICAL); @@ -6202,9 +5719,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, curr_file_pos = ftello(tng_data->output_file); fseeko(tng_data->output_file, header_file_pos + sizeof(block->header_contents_size), SEEK_SET); - if(tng_file_output_numerical(tng_data, &block->block_contents_size, - sizeof(block->block_contents_size), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_output_numerical(tng_data, &block->block_contents_size, sizeof(block->block_contents_size), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -6212,8 +5727,7 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, } if(fwrite(contents, block_data_len, 1, tng_data->output_file) != 1) { - fprintf(stderr, "TNG library: Could not write all block data. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Could not write all block data. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } if(hash_mode == TNG_USE_HASH) @@ -6228,12 +5742,10 @@ static tng_function_status tng_data_block_write(const tng_trajectory_t tng_data, { md5_finish(&md5_state, (md5_byte_t *)block->md5_hash); curr_file_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, header_file_pos + - 3 * sizeof(int64_t), SEEK_SET); + fseeko(tng_data->output_file, header_file_pos + 3 * sizeof(int64_t), SEEK_SET); if(fwrite(block->md5_hash, TNG_MD5_HASH_LEN, 1, tng_data->output_file) != 1) { - fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Could not write MD5 hash. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } fseeko(tng_data->output_file, curr_file_pos, SEEK_SET); @@ -6282,49 +5794,37 @@ static tng_function_status tng_data_block_meta_information_read const char hash_mode, md5_state_t *md5_state) { - if(tng_file_input_numerical(tng_data, datatype, - sizeof(*datatype), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, datatype, sizeof(*datatype), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, dependency, - sizeof(*dependency), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, dependency, sizeof(*dependency), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } if(*dependency & TNG_FRAME_DEPENDENT) { - if(tng_file_input_numerical(tng_data, sparse_data, - sizeof(*sparse_data), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, sparse_data, sizeof(*sparse_data), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } } - if(tng_file_input_numerical(tng_data, n_values, - sizeof(*n_values), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, n_values, sizeof(*n_values), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, codec_id, - sizeof(*codec_id), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, codec_id, sizeof(*codec_id), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } if(*codec_id != TNG_UNCOMPRESSED) { - if(tng_file_input_numerical(tng_data, multiplier, - sizeof(*multiplier), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, multiplier, sizeof(*multiplier), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -6338,23 +5838,17 @@ static tng_function_status tng_data_block_meta_information_read { if(*sparse_data) { - if(tng_file_input_numerical(tng_data, first_frame_with_data, - sizeof(*first_frame_with_data), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, first_frame_with_data, sizeof(*first_frame_with_data), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, stride_length, - sizeof(*stride_length), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, stride_length, sizeof(*stride_length), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - *n_frames = tng_data->current_trajectory_frame_set.n_frames - - (*first_frame_with_data - - tng_data->current_trajectory_frame_set.first_frame); + *n_frames = tng_data->current_trajectory_frame_set.n_frames - (*first_frame_with_data - tng_data->current_trajectory_frame_set.first_frame); } else { @@ -6372,16 +5866,12 @@ static tng_function_status tng_data_block_meta_information_read if (*dependency & TNG_PARTICLE_DEPENDENT) { - if(tng_file_input_numerical(tng_data, num_first_particle, - sizeof(*num_first_particle), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, num_first_particle, sizeof(*num_first_particle), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, block_n_particles, - sizeof(*block_n_particles), - hash_mode, md5_state, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, block_n_particles, sizeof(*block_n_particles), hash_mode, md5_state, __LINE__) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -6434,36 +5924,15 @@ static tng_function_status tng_data_block_contents_read /* FIXME: Does not check if the size of the contents matches the expected * size or if the contents can be read. */ - if(tng_data_block_meta_information_read(tng_data, - &datatype, - &dependency, &sparse_data, - &n_values, &codec_id, - &first_frame_with_data, - &stride_length, &n_frames, - &num_first_particle, - &block_n_particles, - &multiplier, - hash_mode, - &md5_state) == TNG_CRITICAL) - { - fprintf(stderr, "TNG library: Cannot read data block (%s) meta information. %s: %d\n", - block->name, __FILE__, __LINE__); + if(tng_data_block_meta_information_read(tng_data, &datatype, &dependency, &sparse_data, &n_values, &codec_id, &first_frame_with_data, &stride_length, &n_frames, &num_first_particle, &block_n_particles, &multiplier, hash_mode, &md5_state) == TNG_CRITICAL) + { + fprintf(stderr, "TNG library: Cannot read data block (%s) meta information. %s: %d\n", block->name, __FILE__, __LINE__); return(TNG_CRITICAL); } remaining_len = block->block_contents_size - (ftello(tng_data->input_file) - start_pos); - stat = tng_data_read(tng_data, block, - remaining_len, - datatype, - num_first_particle, - block_n_particles, - first_frame_with_data, - stride_length, - n_frames, n_values, - codec_id, multiplier, - hash_mode, - &md5_state); + stat = tng_data_read(tng_data, block, remaining_len, datatype, num_first_particle, block_n_particles, first_frame_with_data, stride_length, n_frames, n_values, codec_id, multiplier, hash_mode, &md5_state); if(hash_mode == TNG_USE_HASH) { @@ -6889,10 +6358,7 @@ tng_function_status DECLSPECDLLEXPORT tng_version return(TNG_SUCCESS); } -tng_function_status DECLSPECDLLEXPORT tng_molecule_add - (const tng_trajectory_t tng_data, - const char *name, - tng_molecule_t *molecule) +tng_function_status DECLSPECDLLEXPORT tng_molecule_add(const tng_trajectory_t tng_data,const char *name,tng_molecule_t *molecule) { int64_t id; @@ -7124,10 +6590,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_cnt_get return(TNG_SUCCESS); } -tng_function_status DECLSPECDLLEXPORT tng_molecule_cnt_set - (const tng_trajectory_t tng_data, - const tng_molecule_t molecule, - const int64_t cnt) +tng_function_status DECLSPECDLLEXPORT tng_molecule_cnt_set(const tng_trajectory_t tng_data,const tng_molecule_t molecule,const int64_t cnt) { int64_t i, old_cnt, index = -1; @@ -7479,11 +6942,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_find return(TNG_FAILURE); } -tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_add - (const tng_trajectory_t tng_data, - const tng_molecule_t molecule, - const char *name, - tng_chain_t *chain) +tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_add(const tng_trajectory_t tng_data,const tng_molecule_t molecule,const char *name,tng_chain_t *chain) { int64_t id; @@ -7734,11 +7193,7 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_residue_find return(TNG_FAILURE); } -tng_function_status DECLSPECDLLEXPORT tng_chain_residue_add - (const tng_trajectory_t tng_data, - const tng_chain_t chain, - const char *name, - tng_residue_t *residue) +tng_function_status DECLSPECDLLEXPORT tng_chain_residue_add(const tng_trajectory_t tng_data,const tng_chain_t chain,const char *name,tng_residue_t *residue) { int64_t id; @@ -7947,12 +7402,7 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_atom_of_index_get return(TNG_SUCCESS); } -tng_function_status DECLSPECDLLEXPORT tng_residue_atom_add - (const tng_trajectory_t tng_data, - const tng_residue_t residue, - const char *atom_name, - const char *atom_type, - tng_atom_t *atom) +tng_function_status DECLSPECDLLEXPORT tng_residue_atom_add(const tng_trajectory_t tng_data,const tng_residue_t residue,const char *atom_name,const char *atom_type,tng_atom_t *atom) { int64_t id; @@ -8720,8 +8170,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init(tng_trajectory_t *tng_ *tng_data_p = malloc(sizeof(struct tng_trajectory)); if(!*tng_data_p) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", - sizeof(struct tng_trajectory), __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", sizeof(struct tng_trajectory), __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -9444,9 +8893,7 @@ tng_function_status tng_output_file_get return(TNG_SUCCESS); } -tng_function_status DECLSPECDLLEXPORT tng_output_file_set - (const tng_trajectory_t tng_data, - const char *file_name) +tng_function_status DECLSPECDLLEXPORT tng_output_file_set(const tng_trajectory_t tng_data, const char *file_name) { int len; char *temp; @@ -10518,9 +9965,7 @@ tng_function_status DECLSPECDLLEXPORT tng_distance_unit_exponential_set return(TNG_SUCCESS); } -tng_function_status DECLSPECDLLEXPORT tng_num_frames_per_frame_set_get - (const tng_trajectory_t tng_data, - int64_t *n) +tng_function_status DECLSPECDLLEXPORT tng_num_frames_per_frame_set_get (const tng_trajectory_t tng_data, int64_t *n) { TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); TNG_ASSERT(n, "TNG library: n must not be a NULL pointer"); @@ -11046,9 +10491,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_nr_find return(TNG_FAILURE); } -tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find - (const tng_trajectory_t tng_data, - const int64_t frame) +tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find(const tng_trajectory_t tng_data, const int64_t frame) { int64_t first_frame, last_frame, n_frames_per_frame_set; int64_t long_stride_length, medium_stride_length; @@ -11067,22 +10510,18 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find if(tng_data->current_trajectory_frame_set_input_file_pos < 0) { file_pos = tng_data->first_trajectory_frame_set_input_file_pos; - fseeko(tng_data->input_file, - file_pos, - SEEK_SET); + 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) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11102,8 +10541,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find long_stride_length = tng_data->long_stride_length; medium_stride_length = tng_data->medium_stride_length; - if(tng_first_frame_nr_of_next_frame_set_get(tng_data, &temp_frame) == - TNG_SUCCESS) + if(tng_first_frame_nr_of_next_frame_set_get(tng_data, &temp_frame) == TNG_SUCCESS) { if(temp_frame - first_frame > n_frames_per_frame_set) { @@ -11150,22 +10588,18 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find if(file_pos > 0) { - fseeko(tng_data->input_file, - file_pos, - SEEK_SET); + 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) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11197,14 +10631,12 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find stat = tng_block_header_read(tng_data, block); if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11221,27 +10653,22 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find /* Take medium steps forward until a medium step forward would be too long * or the right frame set is found */ - while(file_pos > 0 && first_frame + medium_stride_length * - n_frames_per_frame_set <= frame) + while(file_pos > 0 && first_frame + medium_stride_length * n_frames_per_frame_set <= frame) { file_pos = frame_set->medium_stride_next_frame_set_file_pos; if(file_pos > 0) { - fseeko(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 %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11262,21 +10689,17 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find file_pos = frame_set->next_frame_set_file_pos; if(file_pos > 0) { - fseeko(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 %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11293,27 +10716,22 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find /* Take long steps backward until a long step backward would be too long * or the right frame set is found */ - while(file_pos > 0 && first_frame - long_stride_length * - n_frames_per_frame_set >= frame) + while(file_pos > 0 && first_frame - long_stride_length * n_frames_per_frame_set >= frame) { file_pos = frame_set->long_stride_prev_frame_set_file_pos; if(file_pos > 0) { - fseeko(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 %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11330,27 +10748,22 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find /* Take medium steps backward until a medium step backward would be too long * or the right frame set is found */ - while(file_pos > 0 && first_frame - medium_stride_length * - n_frames_per_frame_set >= frame) + while(file_pos > 0 && first_frame - medium_stride_length * n_frames_per_frame_set >= frame) { file_pos = frame_set->medium_stride_prev_frame_set_file_pos; if(file_pos > 0) { - fseeko(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 %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11371,21 +10784,17 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find file_pos = frame_set->prev_frame_set_file_pos; if(file_pos > 0) { - fseeko(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 %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11407,21 +10816,17 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_of_frame_find file_pos = frame_set->next_frame_set_file_pos; if(file_pos > 0) { - fseeko(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 %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + 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(tng_block_read_next(tng_data, block, - TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_block_read_next(tng_data, block, TNG_SKIP_HASH) != TNG_SUCCESS) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -11585,10 +10990,7 @@ static tng_function_status tng_file_headers_len_get tng_block_init(&block); /* Read through the headers of non-trajectory blocks (they come before the * trajectory blocks in the file) */ - while (*len < tng_data->input_file_len && - tng_block_header_read(tng_data, block) != TNG_CRITICAL && - block->id != -1 && - block->id != TNG_TRAJECTORY_FRAME_SET) + while (*len < tng_data->input_file_len && tng_block_header_read(tng_data, block) != TNG_CRITICAL && block->id != -1 && block->id != TNG_TRAJECTORY_FRAME_SET) { *len += block->header_contents_size + block->block_contents_size; fseeko(tng_data->input_file, block->block_contents_size, SEEK_CUR); @@ -11642,9 +11044,7 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_read return(TNG_SUCCESS); } -tng_function_status DECLSPECDLLEXPORT tng_file_headers_write - (const tng_trajectory_t tng_data, - const char hash_mode) +tng_function_status DECLSPECDLLEXPORT tng_file_headers_write(const tng_trajectory_t tng_data, const char hash_mode) { int i; int64_t len, orig_len, tot_len = 0, data_start_pos; @@ -11653,7 +11053,7 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_write TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); - if(tng_output_file_init(tng_data) != TNG_SUCCESS) + if(tng_output_file_init(tng_data) != TNG_SUCCESS) // opens output file for appending { return(TNG_CRITICAL); } @@ -11670,8 +11070,7 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_write block->name = malloc(TNG_MAX_STR_LEN); if(!block->name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", - TNG_MAX_STR_LEN, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", TNG_MAX_STR_LEN, __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_CRITICAL); } @@ -11691,11 +11090,7 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_write strcpy(block->name, tng_data->non_tr_data[i].block_name); tng_block_header_len_calculate(tng_data, block, &len); tot_len += len; - tng_data_block_len_calculate(tng_data, - (tng_data_t)&tng_data->non_tr_data[i], - TNG_FALSE, 1, 1, 1, 0, 1, - &data_start_pos, - &len); + tng_data_block_len_calculate(tng_data, (tng_data_t)&tng_data->non_tr_data[i], TNG_FALSE, 1, 1, 1, 0, 1, &data_start_pos, &len); tot_len += len; } for(i = 0; i < tng_data->n_particle_data_blocks; i++) @@ -11703,12 +11098,7 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_write strcpy(block->name, tng_data->non_tr_particle_data[i].block_name); tng_block_header_len_calculate(tng_data, block, &len); tot_len += len; - tng_data_block_len_calculate(tng_data, - &tng_data->non_tr_particle_data[i], - TNG_TRUE, 1, 1, 1, 0, - tng_data->n_particles, - &data_start_pos, - &len); + tng_data_block_len_calculate(tng_data, &tng_data->non_tr_particle_data[i], TNG_TRUE, 1, 1, 1, 0, tng_data->n_particles, &data_start_pos, &len); tot_len += len; } tng_block_destroy(&block); @@ -11725,19 +11115,15 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_write * appending to an already existing file we might need to move frame sets to * the end of the file. */ - if(tng_general_info_block_write(tng_data, hash_mode) - != TNG_SUCCESS) + if(tng_general_info_block_write(tng_data, hash_mode) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Error writing general info block of file %s. %s: %d\n", - tng_data->input_file_path, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Error writing general info block of file %s. %s: %d\n", tng_data->input_file_path, __FILE__, __LINE__); return(TNG_CRITICAL); } - if(tng_molecules_block_write(tng_data, hash_mode) - != TNG_SUCCESS) + if(tng_molecules_block_write(tng_data, hash_mode) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Error writing atom names block of file %s. %s: %d\n", - tng_data->input_file_path, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Error writing atom names block of file %s. %s: %d\n", tng_data->input_file_path, __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -11747,15 +11133,13 @@ tng_function_status DECLSPECDLLEXPORT tng_file_headers_write for(i = 0; i < tng_data->n_data_blocks; i++) { block->id = tng_data->non_tr_data[i].block_id; - tng_data_block_write(tng_data, block, - i, TNG_FALSE, 0, hash_mode); + tng_data_block_write(tng_data, block, i, TNG_FALSE, 0, hash_mode); } for(i = 0; i < tng_data->n_particle_data_blocks; i++) { block->id = tng_data->non_tr_particle_data[i].block_id; - tng_data_block_write(tng_data, block, - i, TNG_TRUE, 0, hash_mode); + tng_data_block_write(tng_data, block, i, TNG_TRUE, 0, hash_mode); } tng_block_destroy(&block); @@ -12090,9 +11474,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_read_next_only_data_from_blo return(stat); } -tng_function_status tng_frame_set_write - (const tng_trajectory_t tng_data, - const char hash_mode) +tng_function_status tng_frame_set_write(const tng_trajectory_t tng_data, const char hash_mode) { int i, j; tng_gen_block_t block; @@ -12108,10 +11490,8 @@ tng_function_status tng_frame_set_write return(TNG_SUCCESS); } - tng_data->current_trajectory_frame_set_output_file_pos = - ftello(tng_data->output_file); - tng_data->last_trajectory_frame_set_output_file_pos = - tng_data->current_trajectory_frame_set_output_file_pos; + tng_data->current_trajectory_frame_set_output_file_pos = ftello(tng_data->output_file); + tng_data->last_trajectory_frame_set_output_file_pos = tng_data->current_trajectory_frame_set_output_file_pos; if(tng_data->current_trajectory_frame_set_output_file_pos <= 0) { @@ -12120,8 +11500,7 @@ tng_function_status tng_frame_set_write if(tng_data->first_trajectory_frame_set_output_file_pos == -1) { - tng_data->first_trajectory_frame_set_output_file_pos = - tng_data->current_trajectory_frame_set_output_file_pos; + tng_data->first_trajectory_frame_set_output_file_pos = tng_data->current_trajectory_frame_set_output_file_pos; } tng_block_init(&block); @@ -12150,9 +11529,7 @@ tng_function_status tng_frame_set_write for(j = 0; j<frame_set->n_particle_data_blocks; j++) { block->id = frame_set->tr_particle_data[j].block_id; - tng_data_block_write(tng_data, block, - j, TNG_TRUE, &frame_set->mappings[i], - hash_mode); + tng_data_block_write(tng_data, block, j, TNG_TRUE, &frame_set->mappings[i], hash_mode); } } } @@ -12162,8 +11539,7 @@ tng_function_status tng_frame_set_write for(i = 0; i<frame_set->n_particle_data_blocks; i++) { block->id = frame_set->tr_particle_data[i].block_id; - tng_data_block_write(tng_data, block, - i, TNG_TRUE, 0, hash_mode); + tng_data_block_write(tng_data, block, i, TNG_TRUE, 0, hash_mode); } } @@ -12204,10 +11580,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_premature_write return(tng_frame_set_write(tng_data, hash_mode)); } -tng_function_status DECLSPECDLLEXPORT tng_frame_set_new - (const tng_trajectory_t tng_data, - const int64_t first_frame, - const int64_t n_frames) +tng_function_status DECLSPECDLLEXPORT tng_frame_set_new(const tng_trajectory_t tng_data, const int64_t first_frame, const int64_t n_frames) { tng_gen_block_t block; tng_trajectory_frame_set_t frame_set; @@ -12233,40 +11606,33 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new * it will be wrong. */ if(tng_data->n_trajectory_frame_sets) { - frame_set->prev_frame_set_file_pos = - tng_data->current_trajectory_frame_set_output_file_pos; + frame_set->prev_frame_set_file_pos = tng_data->current_trajectory_frame_set_output_file_pos; } - tng_data->current_trajectory_frame_set_output_file_pos = - ftello(tng_data->output_file); + tng_data->current_trajectory_frame_set_output_file_pos = ftello(tng_data->output_file); tng_data->n_trajectory_frame_sets++; /* Set the medium range pointers */ if(tng_data->n_trajectory_frame_sets == tng_data->medium_stride_length + 1) { - frame_set->medium_stride_prev_frame_set_file_pos = - tng_data->first_trajectory_frame_set_output_file_pos; + frame_set->medium_stride_prev_frame_set_file_pos = tng_data->first_trajectory_frame_set_output_file_pos; } else if(tng_data->n_trajectory_frame_sets > tng_data->medium_stride_length + 1) { /* FIXME: Currently only working if the previous frame set has its * medium stride pointer already set. This might need some fixing. */ - if(frame_set->medium_stride_prev_frame_set_file_pos != -1 && - frame_set->medium_stride_prev_frame_set_file_pos != 0) + if(frame_set->medium_stride_prev_frame_set_file_pos != -1 && frame_set->medium_stride_prev_frame_set_file_pos != 0) { tng_block_init(&block); tng_data->input_file = tng_data->output_file; curr_file_pos = ftello(tng_data->output_file); - fseeko(tng_data->output_file, - 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) { - fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -12276,9 +11642,7 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new * medium stride step back */ 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), - 1, tng_data->output_file) == 0) + if(fread(&frame_set->medium_stride_prev_frame_set_file_pos, sizeof(frame_set->medium_stride_prev_frame_set_file_pos), 1, tng_data->output_file) == 0) { fprintf(stderr, "TNG library: Cannot read block. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; @@ -12288,12 +11652,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new if(tng_data->input_endianness_swap_func_64) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &frame_set->medium_stride_prev_frame_set_file_pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &frame_set->medium_stride_prev_frame_set_file_pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -12302,27 +11663,22 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new /* Set the long range pointers */ if(tng_data->n_trajectory_frame_sets == tng_data->long_stride_length + 1) { - frame_set->long_stride_prev_frame_set_file_pos = - tng_data->first_trajectory_frame_set_output_file_pos; + frame_set->long_stride_prev_frame_set_file_pos = tng_data->first_trajectory_frame_set_output_file_pos; } else if(tng_data->n_trajectory_frame_sets > tng_data->medium_stride_length + 1) { /* FIXME: Currently only working if the previous frame set has its * long stride pointer already set. This might need some fixing. */ - if(frame_set->long_stride_prev_frame_set_file_pos != -1 && - frame_set->long_stride_prev_frame_set_file_pos != 0) + if(frame_set->long_stride_prev_frame_set_file_pos != -1 && frame_set->long_stride_prev_frame_set_file_pos != 0) { tng_block_init(&block); tng_data->input_file = tng_data->output_file; - fseeko(tng_data->output_file, - 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) { - fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read frame set header. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; tng_block_destroy(&block); return(TNG_CRITICAL); @@ -12330,14 +11686,11 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new /* Read the next frame set from the previous frame set and one * long stride step back */ - fseeko(tng_data->output_file, block->block_contents_size - (6 * - sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR); + fseeko(tng_data->output_file, block->block_contents_size - (6 * sizeof(int64_t) + 2 * sizeof(double)), SEEK_CUR); tng_block_destroy(&block); - if(fread(&frame_set->long_stride_prev_frame_set_file_pos, - sizeof(frame_set->long_stride_prev_frame_set_file_pos), - 1, tng_data->output_file) == 0) + if(fread(&frame_set->long_stride_prev_frame_set_file_pos, sizeof(frame_set->long_stride_prev_frame_set_file_pos), 1, tng_data->output_file) == 0) { fprintf(stderr, "TNG library: Cannot read block. %s: %d\n", __FILE__, __LINE__); tng_data->input_file = temp; @@ -12346,12 +11699,9 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new if(tng_data->input_endianness_swap_func_64) { - if(tng_data->input_endianness_swap_func_64(tng_data, - &frame_set->long_stride_prev_frame_set_file_pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64(tng_data, &frame_set->long_stride_prev_frame_set_file_pos) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } @@ -12369,21 +11719,15 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_new frame_set->n_unwritten_frames = 0; frame_set->first_frame_time = -1; - if(tng_data->first_trajectory_frame_set_output_file_pos == -1 || - tng_data->first_trajectory_frame_set_output_file_pos == 0) + if(tng_data->first_trajectory_frame_set_output_file_pos == -1 || tng_data->first_trajectory_frame_set_output_file_pos == 0) { - tng_data->first_trajectory_frame_set_output_file_pos = - tng_data->current_trajectory_frame_set_output_file_pos; + tng_data->first_trajectory_frame_set_output_file_pos = tng_data->current_trajectory_frame_set_output_file_pos; } /* FIXME: Should check the frame number instead of the file_pos, * in case frame sets are not in order */ - if(tng_data->last_trajectory_frame_set_output_file_pos == -1 || - tng_data->last_trajectory_frame_set_output_file_pos == 0 || - tng_data->last_trajectory_frame_set_output_file_pos < - tng_data->current_trajectory_frame_set_output_file_pos) + if(tng_data->last_trajectory_frame_set_output_file_pos == -1 || tng_data->last_trajectory_frame_set_output_file_pos == 0 || tng_data->last_trajectory_frame_set_output_file_pos < tng_data->current_trajectory_frame_set_output_file_pos) { - tng_data->last_trajectory_frame_set_output_file_pos = - tng_data->current_trajectory_frame_set_output_file_pos; + tng_data->last_trajectory_frame_set_output_file_pos = tng_data->current_trajectory_frame_set_output_file_pos; } return(TNG_SUCCESS); @@ -12462,8 +11806,7 @@ tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get stat = tng_block_header_read(tng_data, block); if(stat == TNG_CRITICAL || block->id != TNG_TRAJECTORY_FRAME_SET) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", file_pos, __FILE__, __LINE__); return(TNG_CRITICAL); } /* if(tng_data->current_trajectory_frame_set_input_file_pos <= 0) @@ -12474,8 +11817,7 @@ tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get if(fread(frame, sizeof(int64_t), 1, tng_data->input_file) == 0) { - fprintf(stderr, "TNG library: Cannot read first frame of next frame set. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read first frame of next frame set. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } fseeko(tng_data->input_file, file_pos, SEEK_SET); @@ -12483,20 +11825,7 @@ tng_function_status DECLSPECDLLEXPORT tng_first_frame_nr_of_next_frame_set_get return(TNG_SUCCESS); } -static tng_function_status tng_gen_data_block_add - (const tng_trajectory_t tng_data, - const int64_t id, - const tng_bool is_particle_data, - const char *block_name, - const char datatype, - const char block_type_flag, - int64_t n_frames, - const int64_t n_values_per_frame, - int64_t stride_length, - const int64_t num_first_particle, - const int64_t n_particles, - const int64_t codec_id, - void *new_data) +static tng_function_status tng_gen_data_block_add(const tng_trajectory_t tng_data, const int64_t id, const tng_bool is_particle_data, const char *block_name, const char datatype, const char block_type_flag, int64_t n_frames, const int64_t n_values_per_frame, int64_t stride_length, const int64_t num_first_particle, const int64_t n_particles, const int64_t codec_id, void *new_data) { int i, size, len; int64_t j, k; @@ -12536,21 +11865,18 @@ static tng_function_status tng_gen_data_block_add if(stat != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot create particle data block. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot create particle data block. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } if(is_particle_data) { if(block_type_flag == TNG_TRAJECTORY_BLOCK) { - data = &frame_set->tr_particle_data[frame_set-> - n_particle_data_blocks - 1]; + data = &frame_set->tr_particle_data[frame_set->n_particle_data_blocks - 1]; } else { - data = &tng_data->non_tr_particle_data[tng_data-> - n_particle_data_blocks - 1]; + data = &tng_data->non_tr_particle_data[tng_data->n_particle_data_blocks - 1]; } } else @@ -12569,8 +11895,7 @@ static tng_function_status tng_gen_data_block_add data->block_name = malloc(strlen(block_name) + 1); if(!data->block_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%ud bytes). %s: %d\n", - (unsigned int)strlen(block_name)+1, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%ud bytes). %s: %d\n", (unsigned int)strlen(block_name)+1, __FILE__, __LINE__); return(TNG_CRITICAL); } strncpy(data->block_name, block_name, strlen(block_name) + 1); @@ -12593,10 +11918,7 @@ static tng_function_status tng_gen_data_block_add { data->dependency = 0; } - if(block_type_flag == TNG_TRAJECTORY_BLOCK && - (n_frames > 1 || - frame_set->n_frames == n_frames || - stride_length > 1)) + if(block_type_flag == TNG_TRAJECTORY_BLOCK && (n_frames > 1 || frame_set->n_frames == n_frames || stride_length > 1)) { data->dependency += TNG_FRAME_DEPENDENT; } @@ -12629,19 +11951,15 @@ static tng_function_status tng_gen_data_block_add /* Allocate memory */ if(is_particle_data) { - stat = tng_allocate_particle_data_mem(tng_data, data, n_frames, - stride_length, tot_n_particles, - n_values_per_frame); + stat = tng_allocate_particle_data_mem(tng_data, data, n_frames, stride_length, tot_n_particles, n_values_per_frame); } else { - stat = tng_allocate_data_mem(tng_data, data, n_frames, stride_length, - n_values_per_frame); + stat = tng_allocate_data_mem(tng_data, data, n_frames, stride_length, n_values_per_frame); } if(stat != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot allocate particle data memory. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate particle data memory. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -12650,9 +11968,7 @@ static tng_function_status tng_gen_data_block_add frame_set->n_unwritten_frames = n_frames; } - n_frames_div = (n_frames % stride_length) ? - n_frames / stride_length + 1: - n_frames / stride_length; + n_frames_div = (n_frames % stride_length) ? n_frames / stride_length + 1 : n_frames / stride_length; if(datatype == TNG_CHAR_DATA) { @@ -12661,14 +11977,12 @@ static tng_function_status tng_gen_data_block_add for(i = 0; i < n_frames_div; i++) { first_dim_values = data->strings[i]; - for(j = num_first_particle; j < num_first_particle + n_particles; - j++) + for(j = num_first_particle; j < num_first_particle + n_particles; j++) { second_dim_values = first_dim_values[j]; for(k = 0; k < n_values_per_frame; k++) { - len = tng_min_size(strlen(new_data_c) + 1, - TNG_MAX_STR_LEN); + len = tng_min_size(strlen(new_data_c) + 1, TNG_MAX_STR_LEN); if(second_dim_values[k]) { free(second_dim_values[k]); @@ -12694,8 +12008,7 @@ static tng_function_status tng_gen_data_block_add second_dim_values = data->strings[0][i]; for(j = 0; j < n_values_per_frame; j++) { - len = tng_min_size(strlen(new_data_c) + 1, - TNG_MAX_STR_LEN); + len = tng_min_size(strlen(new_data_c) + 1, TNG_MAX_STR_LEN); if(second_dim_values[j]) { free(second_dim_values[j]); @@ -12703,12 +12016,10 @@ static tng_function_status tng_gen_data_block_add second_dim_values[j] = malloc(len); if(!second_dim_values[j]) { - fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", - len, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); return(TNG_CRITICAL); } - strncpy(second_dim_values[j], - new_data_c, len); + strncpy(second_dim_values[j], new_data_c, len); new_data_c += len; } } @@ -12731,13 +12042,11 @@ static tng_function_status tng_gen_data_block_add if(is_particle_data) { - memcpy(data->values, new_data, size * n_frames_div * - n_particles * n_values_per_frame); + memcpy(data->values, new_data, size * n_frames_div * n_particles * n_values_per_frame); } else { - memcpy(data->values, new_data, size * n_frames_div * - n_values_per_frame); + memcpy(data->values, new_data, size * n_frames_div * n_values_per_frame); } } } @@ -12745,40 +12054,16 @@ static tng_function_status tng_gen_data_block_add return(TNG_SUCCESS); } -tng_function_status DECLSPECDLLEXPORT tng_data_block_add - (const tng_trajectory_t tng_data, - const int64_t id, - const char *block_name, - const char datatype, - const char block_type_flag, - int64_t n_frames, - const int64_t n_values_per_frame, - int64_t stride_length, - const int64_t codec_id, - void *new_data) +tng_function_status DECLSPECDLLEXPORT tng_data_block_add(const tng_trajectory_t tng_data,const int64_t id, const char *block_name, const char datatype, const char block_type_flag, int64_t n_frames, const int64_t n_values_per_frame, int64_t stride_length, const int64_t codec_id, void *new_data) { TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); TNG_ASSERT(block_name, "TNG library: block_name must not be a NULL pointer."); TNG_ASSERT(n_values_per_frame > 0, "TNG library: n_values_per_frame must be a positive integer."); - - return(tng_gen_data_block_add(tng_data, id, TNG_FALSE, block_name, datatype, - block_type_flag, n_frames, n_values_per_frame, - stride_length, 0, 0, codec_id, new_data)); + //handle, id, is_particle_data, name, datatype, block_type_flag, num of fr, values/frame , stride_length, num_first_particle, n_particles, codec, data + return(tng_gen_data_block_add(tng_data, id, TNG_FALSE, block_name, datatype, block_type_flag, n_frames, n_values_per_frame, stride_length, 0, 0, codec_id, new_data)); } -tng_function_status DECLSPECDLLEXPORT tng_particle_data_block_add - (const tng_trajectory_t tng_data, - const int64_t id, - const char *block_name, - const char datatype, - const char block_type_flag, - int64_t n_frames, - const int64_t n_values_per_frame, - int64_t stride_length, - const int64_t num_first_particle, - const int64_t n_particles, - const int64_t codec_id, - void *new_data) +tng_function_status DECLSPECDLLEXPORT tng_particle_data_block_add(const tng_trajectory_t tng_data, const int64_t id, const char *block_name, const char datatype, const char block_type_flag, int64_t n_frames, const int64_t n_values_per_frame, int64_t stride_length, const int64_t num_first_particle, const int64_t n_particles, const int64_t codec_id, void *new_data) { TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); TNG_ASSERT(block_name, "TNG library: block_name mustnot be a NULL pointer."); @@ -12786,10 +12071,7 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_block_add TNG_ASSERT(num_first_particle >= 0, "TNG library: num_first_particle must be >= 0."); TNG_ASSERT(n_particles >= 0, "TNG library: n_particles must be >= 0."); - return(tng_gen_data_block_add(tng_data, id, TNG_TRUE, block_name, datatype, - block_type_flag, n_frames, n_values_per_frame, - stride_length, num_first_particle, n_particles, - codec_id, new_data)); + return(tng_gen_data_block_add(tng_data, id, TNG_TRUE, block_name, datatype, block_type_flag, n_frames, n_values_per_frame, stride_length, num_first_particle, n_particles, codec_id, new_data)); } tng_function_status DECLSPECDLLEXPORT tng_data_block_name_get @@ -13147,46 +12429,35 @@ static tng_function_status tng_frame_gen_data_write if(tng_output_file_init(tng_data) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot initialise destination file. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot initialise destination file. %s: %d\n", __FILE__, __LINE__); return(TNG_CRITICAL); } - temp_first = tng_data->first_trajectory_frame_set_input_file_pos; - temp_last = tng_data->last_trajectory_frame_set_input_file_pos; - temp_current = tng_data->current_trajectory_frame_set_input_file_pos; - tng_data->first_trajectory_frame_set_input_file_pos = - tng_data->first_trajectory_frame_set_output_file_pos; - tng_data->last_trajectory_frame_set_input_file_pos = - tng_data->last_trajectory_frame_set_output_file_pos; - tng_data->current_trajectory_frame_set_input_file_pos = - tng_data->current_trajectory_frame_set_output_file_pos; + temp_first = tng_data->first_trajectory_frame_set_input_file_pos; + temp_last = tng_data->last_trajectory_frame_set_input_file_pos; + temp_current = tng_data->current_trajectory_frame_set_input_file_pos; + tng_data->first_trajectory_frame_set_input_file_pos = tng_data->first_trajectory_frame_set_output_file_pos; + tng_data->last_trajectory_frame_set_input_file_pos = tng_data->last_trajectory_frame_set_output_file_pos; + tng_data->current_trajectory_frame_set_input_file_pos = tng_data->current_trajectory_frame_set_output_file_pos; - tng_data->input_file = tng_data->output_file; + tng_data->input_file = tng_data->output_file; - stat = tng_frame_set_of_frame_find(tng_data, frame_nr); + stat = tng_frame_set_of_frame_find(tng_data, frame_nr); - frame_set = &tng_data->current_trajectory_frame_set; + frame_set = &tng_data->current_trajectory_frame_set; if(stat != TNG_SUCCESS) { - last_frame = frame_set->first_frame + - frame_set->n_frames - 1; - /* If the wanted frame would be in the frame set after the last - * frame set create a new frame set. */ - if(stat == TNG_FAILURE && - last_frame < frame_nr) -/* (last_frame < frame_nr && - tng_data->current_trajectory_frame_set.first_frame + - tng_data->frame_set_n_frames >= frame_nr))*/ + last_frame = frame_set->first_frame + frame_set->n_frames - 1; + /* If the wanted frame would be in the frame set after the last frame set create a new frame set. */ + if(stat == TNG_FAILURE && last_frame < frame_nr) +/* (last_frame < frame_nr && tng_data->current_trajectory_frame_set.first_frame + tng_data->frame_set_n_frames >= frame_nr))*/ { if(last_frame + tng_data->frame_set_n_frames < frame_nr) { last_frame = frame_nr - 1; } - tng_frame_set_new(tng_data, - last_frame+1, - tng_data->frame_set_n_frames); + tng_frame_set_new(tng_data, last_frame+1, tng_data->frame_set_n_frames); file_pos = ftello(tng_data->output_file); fseeko(tng_data->output_file, 0, SEEK_END); output_file_len = ftello(tng_data->output_file); @@ -13196,20 +12467,15 @@ static tng_function_status tng_frame_gen_data_write tng_block_init(&block); stat = tng_block_header_read(tng_data, block); - while(file_pos < output_file_len && - stat != TNG_CRITICAL && - block->id != TNG_TRAJECTORY_FRAME_SET && - block->id != -1) + while(file_pos < output_file_len && stat != TNG_CRITICAL && block->id != TNG_TRAJECTORY_FRAME_SET && block->id != -1) { if(block->id == TNG_PARTICLE_MAPPING) { - tng_trajectory_mapping_block_read(tng_data, block, - hash_mode); + tng_trajectory_mapping_block_read(tng_data, block, hash_mode); } else { - fseeko(tng_data->output_file, block->block_contents_size, - SEEK_CUR); + fseeko(tng_data->output_file, block->block_contents_size, SEEK_CUR); } file_pos = ftello(tng_data->output_file); if(file_pos < output_file_len) @@ -13248,8 +12514,7 @@ static tng_function_status tng_frame_gen_data_write stat = tng_block_header_read(tng_data, block); if(stat == TNG_CRITICAL) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", file_pos, __FILE__, __LINE__); tng_block_destroy(&block); tng_data->input_file = temp; @@ -13258,8 +12523,7 @@ static tng_function_status tng_frame_gen_data_write tng_data->current_trajectory_frame_set_input_file_pos = temp_current; return(stat); } - fseeko(tng_data->output_file, block->block_contents_size, - SEEK_CUR); + fseeko(tng_data->output_file, block->block_contents_size, SEEK_CUR); if(is_particle_data == TNG_TRUE) { @@ -13277,10 +12541,7 @@ static tng_function_status tng_frame_gen_data_write mapping_block_end_pos = -1; /* Read all mapping blocks to find the right place to put the data */ stat = tng_block_header_read(tng_data, block); - while(file_pos < output_file_len && - stat != TNG_CRITICAL && - block->id != TNG_TRAJECTORY_FRAME_SET && - block->id != -1) + while(file_pos < output_file_len && stat != TNG_CRITICAL && block->id != TNG_TRAJECTORY_FRAME_SET && block->id != -1) { if(block->id == TNG_PARTICLE_MAPPING) { @@ -13288,18 +12549,13 @@ static tng_function_status tng_frame_gen_data_write } else { - fseeko(tng_data->output_file, block->block_contents_size, - SEEK_CUR); + fseeko(tng_data->output_file, block->block_contents_size, SEEK_CUR); } file_pos = ftello(tng_data->output_file); if(block->id == TNG_PARTICLE_MAPPING) { mapping = &frame_set->mappings[frame_set->n_mapping_blocks - 1]; - if(val_first_particle >= mapping->num_first_particle && - val_first_particle < mapping->num_first_particle + - mapping->n_particles && - val_first_particle + val_n_particles <= - mapping->num_first_particle + mapping->n_particles) + if(val_first_particle >= mapping->num_first_particle && val_first_particle < mapping->num_first_particle + mapping->n_particles && val_first_particle + val_n_particles <= mapping->num_first_particle + mapping->n_particles) { mapping_block_end_pos = file_pos; } @@ -13311,8 +12567,7 @@ static tng_function_status tng_frame_gen_data_write } if(stat == TNG_CRITICAL) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", file_pos, __FILE__, __LINE__); tng_block_destroy(&block); tng_data->input_file = temp; @@ -13338,12 +12593,7 @@ static tng_function_status tng_frame_gen_data_write /* Read all block headers until next frame set block or * until the wanted block id is found */ stat = tng_block_header_read(tng_data, block); - while(file_pos < output_file_len && - stat != TNG_CRITICAL && - block->id != block_id && - (is_particle_data != TNG_TRUE || block->id != TNG_PARTICLE_MAPPING) && - block->id != TNG_TRAJECTORY_FRAME_SET && - block->id != -1) + while(file_pos < output_file_len && stat != TNG_CRITICAL && block->id != block_id && (is_particle_data != TNG_TRUE || block->id != TNG_PARTICLE_MAPPING) && block->id != TNG_TRAJECTORY_FRAME_SET && block->id != -1) { fseeko(tng_data->output_file, block->block_contents_size, SEEK_CUR); file_pos = ftello(tng_data->output_file); @@ -13354,8 +12604,7 @@ static tng_function_status tng_frame_gen_data_write } if(stat == TNG_CRITICAL) { - fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", - file_pos, __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot read block header at pos %"PRId64". %s: %d\n", file_pos, __FILE__, __LINE__); tng_block_destroy(&block); tng_data->input_file = temp; tng_data->first_trajectory_frame_set_input_file_pos = temp_first; @@ -13370,25 +12619,19 @@ static tng_function_status tng_frame_gen_data_write header_pos = ftello(tng_data->output_file) - header_size; frame_set = &tng_data->current_trajectory_frame_set; - if(tng_file_input_numerical(tng_data, &datatype, - sizeof(datatype), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &datatype, sizeof(datatype), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &dependency, - sizeof(dependency), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &dependency, sizeof(dependency), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); } data.datatype = datatype; - if(!(dependency & TNG_FRAME_DEPENDENT) || - (is_particle_data == TNG_FALSE && dependency & TNG_PARTICLE_DEPENDENT) || - (is_particle_data == TNG_TRUE && !(dependency & TNG_PARTICLE_DEPENDENT))) + if(!(dependency & TNG_FRAME_DEPENDENT) || (is_particle_data == TNG_FALSE && dependency & TNG_PARTICLE_DEPENDENT) || (is_particle_data == TNG_TRUE && !(dependency & TNG_PARTICLE_DEPENDENT))) { tng_block_destroy(&block); tng_data->input_file = temp; @@ -13396,28 +12639,25 @@ static tng_function_status tng_frame_gen_data_write tng_data->first_trajectory_frame_set_input_file_pos = temp_first; tng_data->last_trajectory_frame_set_input_file_pos = temp_last; tng_data->current_trajectory_frame_set_input_file_pos = temp_current; + + fprintf(stderr, "TNG library: Dependency problem in %s: %d\n", __FILE__, __LINE__); + return(TNG_FAILURE); } - if(tng_file_input_numerical(tng_data, &sparse_data, - sizeof(sparse_data), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &sparse_data, sizeof(sparse_data), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &data.n_values_per_frame, - sizeof(data.n_values_per_frame), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &data.n_values_per_frame, sizeof(data.n_values_per_frame), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &data.codec_id, - sizeof(data.codec_id), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &data.codec_id, sizeof(data.codec_id), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -13425,9 +12665,7 @@ static tng_function_status tng_frame_gen_data_write if(data.codec_id != TNG_UNCOMPRESSED) { - if(tng_file_input_numerical(tng_data, &data.compression_multiplier, - sizeof(data.compression_multiplier), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &data.compression_multiplier, sizeof(data.compression_multiplier), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -13440,17 +12678,13 @@ static tng_function_status tng_frame_gen_data_write if(sparse_data) { - if(tng_file_input_numerical(tng_data, &data.first_frame_with_data, - sizeof(data.first_frame_with_data), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &data.first_frame_with_data, sizeof(data.first_frame_with_data), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &data.stride_length, - sizeof(data.stride_length), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &data.stride_length, sizeof(data.stride_length), TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -13465,17 +12699,13 @@ static tng_function_status tng_frame_gen_data_write if(is_particle_data == TNG_TRUE) { - if(tng_file_input_numerical(tng_data, &num_first_particle, - sizeof(num_first_particle), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &num_first_particle,sizeof(num_first_particle),TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_file_input_numerical(tng_data, &block_n_particles, - sizeof(block_n_particles), - TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) + if(tng_file_input_numerical(tng_data, &block_n_particles,sizeof(block_n_particles),TNG_SKIP_HASH, 0, __LINE__) == TNG_CRITICAL) { tng_block_destroy(&block); return(TNG_CRITICAL); @@ -13500,17 +12730,14 @@ static tng_function_status tng_frame_gen_data_write size = sizeof(double); break; default: - fprintf(stderr, "TNG library: Cannot calculate writing locations. %s: %d.\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Cannot calculate writing locations. %s: %d.\n", __FILE__, __LINE__); tng_block_destroy(&block); return(TNG_FAILURE); } n_values_per_frame = data.n_values_per_frame; - file_pos = (frame_nr - tng_max_i64(frame_set->first_frame, - data.first_frame_with_data)) / - data.stride_length; + file_pos = (frame_nr - tng_max_i64(frame_set->first_frame, data.first_frame_with_data)) / data.stride_length; if(is_particle_data == TNG_TRUE) { file_pos *= block_n_particles * size * n_values_per_frame; @@ -13522,8 +12749,7 @@ static tng_function_status tng_frame_gen_data_write if(file_pos > contents_size) { - fprintf(stderr, "TNG library: Attempting to write outside the block. %s: %d\n", __FILE__, - __LINE__); + fprintf(stderr, "TNG library: Attempting to write outside the block. %s: %d\n", __FILE__,__LINE__); tng_block_destroy(&block); return(TNG_FAILURE); } @@ -13540,43 +12766,32 @@ static tng_function_status tng_frame_gen_data_write } /* If the endianness is not big endian the data needs to be swapped */ - if((data.datatype == TNG_INT_DATA || - data.datatype == TNG_DOUBLE_DATA) && - tng_data->output_endianness_swap_func_64) + if((data.datatype == TNG_INT_DATA || data.datatype == TNG_DOUBLE_DATA) && tng_data->output_endianness_swap_func_64) { copy = malloc(write_n_particles * n_values_per_frame * size); memcpy(copy, values, write_n_particles * n_values_per_frame * size); for(i = 0; i < write_n_particles * n_values_per_frame; i++) { - if(tng_data->output_endianness_swap_func_64(tng_data, - (int64_t *) copy+i) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64(tng_data,(int64_t *) copy+i) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } - fwrite(copy, write_n_particles * n_values_per_frame, size, - tng_data->output_file); + fwrite(copy, write_n_particles * n_values_per_frame, size, tng_data->output_file); free(copy); } - else if(data.datatype == TNG_FLOAT_DATA && - tng_data->output_endianness_swap_func_32) + else if(data.datatype == TNG_FLOAT_DATA && tng_data->output_endianness_swap_func_32) { copy = malloc(write_n_particles * n_values_per_frame * size); memcpy(copy, values, write_n_particles * n_values_per_frame * size); for(i = 0; i < write_n_particles * n_values_per_frame; i++) { - if(tng_data->output_endianness_swap_func_32(tng_data, - (int32_t *) copy+i) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_32(tng_data, (int32_t *) copy+i) != TNG_SUCCESS) { - fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", - __FILE__, __LINE__); + fprintf(stderr, "TNG library: Cannot swap byte order. %s: %d\n", __FILE__, __LINE__); } } - fwrite(copy, write_n_particles * n_values_per_frame, size, - tng_data->output_file); + fwrite(copy, write_n_particles * n_values_per_frame, size, tng_data->output_file); free(copy); } @@ -13594,12 +12809,9 @@ static tng_function_status tng_frame_gen_data_write } /* If the last frame has been written update the hash */ - if(hash_mode == TNG_USE_HASH && (frame_nr + data.stride_length - - data.first_frame_with_data) >= - frame_set->n_frames) + if(hash_mode == TNG_USE_HASH && (frame_nr + data.stride_length - data.first_frame_with_data) >= frame_set->n_frames) { - tng_md5_hash_update(tng_data, block, header_pos, header_pos + - header_size); + tng_md5_hash_update(tng_data, block, header_pos, header_pos + header_size); } tng_block_destroy(&block); @@ -13607,12 +12819,7 @@ static tng_function_status tng_frame_gen_data_write return(TNG_SUCCESS); } -tng_function_status DECLSPECDLLEXPORT tng_frame_data_write - (const tng_trajectory_t tng_data, - const int64_t frame_nr, - const int64_t block_id, - const void *values, - const char hash_mode) +tng_function_status DECLSPECDLLEXPORT tng_frame_data_write(const tng_trajectory_t tng_data, const int64_t frame_nr, const int64_t block_id, const void *values, const char hash_mode) { TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); TNG_ASSERT(frame_nr >= 0, "TNG library: frame_nr must be >= 0."); @@ -13621,18 +12828,11 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_data_write /* This is now just calling the generic data writing function. This * function must keep its signature to let the API be backwards * compatible. */ - return(tng_frame_gen_data_write(tng_data, frame_nr, block_id, - TNG_FALSE, 0, 0, values, hash_mode)); + return(tng_frame_gen_data_write(tng_data, frame_nr, block_id, TNG_FALSE, // no particles! + 0, 0, values, hash_mode)); } -tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write - (const tng_trajectory_t tng_data, - const int64_t frame_nr, - const int64_t block_id, - const int64_t val_first_particle, - const int64_t val_n_particles, - const void *values, - const char hash_mode) +tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write(const tng_trajectory_t tng_data, const int64_t frame_nr, const int64_t block_id, const int64_t val_first_particle, const int64_t val_n_particles, const void *values, const char hash_mode) { TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); TNG_ASSERT(frame_nr >= 0, "TNG library: frame_nr must be >= 0."); @@ -13643,9 +12843,8 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_particle_data_write /* This is now just calling the generic data writing function. This * function must keep its signature to let the API be backwards * compatible. */ - return(tng_frame_gen_data_write(tng_data, frame_nr, block_id, - TNG_TRUE, val_first_particle, val_n_particles, - values, hash_mode)); + return(tng_frame_gen_data_write(tng_data, frame_nr, block_id, TNG_TRUE, //particles! + val_first_particle, val_n_particles, values, hash_mode)); } static tng_function_status tng_data_values_alloc diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index f465b6b..4bdded6 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -29,12 +29,17 @@ if(TNG_BUILD_EXAMPLES) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") add_executable(md_openmp md_openmp.c) + add_executable(sr_test sr_test.c) target_link_libraries(md_openmp tng_io ${OpenMP_LIBS}) + target_link_libraries(sr_test tng_io ${OpenMP_LIBS}) if(UNIX) target_link_libraries(md_openmp m) + target_link_libraries(sr_test m) endif() set_property(TARGET md_openmp PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) set_property(TARGET md_openmp APPEND PROPERTY COMPILE_DEFINITIONS TNG_BUILD_OPENMP_EXAMPLES) + set_property(TARGET sr_test PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples) + set_property(TARGET sr_test APPEND PROPERTY COMPILE_DEFINITIONS TNG_BUILD_OPENMP_EXAMPLES) add_executable(md_openmp_util md_openmp_util.c) diff --git a/src/tests/md_openmp.c b/src/tests/md_openmp.c index d500167..9d8f599 100644 --- a/src/tests/md_openmp.c +++ b/src/tests/md_openmp.c @@ -69,8 +69,8 @@ int main () int i; double kinetic; double mass = 1.0; - int nd = 3; - int np = 50; + int nd = 3; // number of dimensions + int np = 50; // number of particles double *pos; double potential; int proc_num; @@ -91,7 +91,7 @@ int main () tng_atom_t atom; int64_t n_frames_per_frame_set; int frames_saved_cnt = 0; - + int64_t codec_id = TNG_UNCOMPRESSED; timestamp ( ); proc_num = omp_get_num_procs ( ); @@ -133,15 +133,24 @@ int main () /* Set molecules data */ printf(" Creating molecules in trajectory.\n"); + + // name, *molecule tng_molecule_add(traj, "water", &molecule); + + // molecule, name, *chain tng_molecule_chain_add(traj, molecule, "W", &chain); + + // chain, name, residue tng_chain_residue_add(traj, chain, "WAT", &residue); - if(tng_residue_atom_add(traj, residue, "O", "O", &atom) == TNG_CRITICAL) + + //atom name,atom type, *atom + if(tng_residue_atom_add(traj, residue, "O", "O", &atom) == TNG_CRITICAL) { tng_trajectory_destroy(&traj); printf(" Cannot create molecules.\n"); exit(1); } + // molecule, number of particles tng_molecule_cnt_set(traj, molecule, np); @@ -152,17 +161,20 @@ int main () { box_shape[i] = 0.0; } + // number of dimensions for ( i = 0; i < nd; i++ ) { box[i] = 10.0; box_shape[i*nd + i] = box[i]; } + // box_shape = { 10.0 0.00 0.00 10.0 0.00 0.00 10.0 0.00 0.00 } + // i don't know (yet), what the zeroes are for /* Add the box shape data block and write the file headers */ - if(tng_data_block_add(traj, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE", TNG_DOUBLE_DATA, - TNG_NON_TRAJECTORY_BLOCK, 1, 9, 1, TNG_UNCOMPRESSED, - box_shape) == TNG_CRITICAL || + //handle, id, name, datatype, block_type_flag, number of frames, values per frame, stride_length, codec_id , data + if(tng_data_block_add(traj, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE", TNG_DOUBLE_DATA,TNG_NON_TRAJECTORY_BLOCK, 1, 9, 1, codec_id, box_shape) == TNG_CRITICAL || + // handle, hash_mode tng_file_headers_write(traj, TNG_USE_HASH) == TNG_CRITICAL) { free(box_shape); @@ -201,8 +213,7 @@ int main () Compute forces and energies, Update positions, velocities, accelerations. */ - printf(" Every %d steps particle positions, velocities and forces are\n", - step_save); + printf(" Every %d steps particle positions, velocities and forces are\n", step_save); printf(" saved to a TNG trajectory file.\n"); printf ( "\n" ); printf ( " At certain step intervals, we report the potential and kinetic energies.\n" ); @@ -215,53 +226,30 @@ int main () printf ( "\n" ); step = 0; - printf ( " %8d %14f %14f %14e\n", - step, potential, kinetic, ( potential + kinetic - e0 ) / e0 ); + printf ( " %8d %14f %14f %14e\n", step, potential, kinetic, ( potential + kinetic - e0 ) / e0 ); step_print_index++; step_print = ( step_print_index * step_num ) / step_print_num; /* Create a frame set for writing data */ tng_num_frames_per_frame_set_get(traj, &n_frames_per_frame_set); - if(tng_frame_set_new(traj, 0, - n_frames_per_frame_set) != TNG_SUCCESS) + if(tng_frame_set_new(traj, 0, n_frames_per_frame_set) != TNG_SUCCESS) { - printf("Error creating frame set %d. %s: %d\n", - i, __FILE__, __LINE__); + printf("Error creating frame set %d. %s: %d\n", i, __FILE__, __LINE__); exit(1); } /* Add empty data blocks */ - if(tng_particle_data_block_add(traj, TNG_TRAJ_POSITIONS, - "POSITIONS", - TNG_DOUBLE_DATA, - TNG_TRAJECTORY_BLOCK, - n_frames_per_frame_set, 3, - 1, 0, np, - TNG_UNCOMPRESSED, - 0) != TNG_SUCCESS) + if(tng_particle_data_block_add(traj, TNG_TRAJ_POSITIONS, "POSITIONS", TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK, n_frames_per_frame_set, 3, 1, 0, np, codec_id, 0) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); exit(1); } - if(tng_particle_data_block_add(traj, TNG_TRAJ_VELOCITIES, - "VELOCITIES", - TNG_DOUBLE_DATA, - TNG_TRAJECTORY_BLOCK, - n_frames_per_frame_set, 3, - 1, 0, np, - TNG_UNCOMPRESSED, - 0) != TNG_SUCCESS) + if(tng_particle_data_block_add(traj, TNG_TRAJ_VELOCITIES, "VELOCITIES", TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK, n_frames_per_frame_set, 3, 1, 0, np, codec_id, 0) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); exit(1); } - if(tng_particle_data_block_add(traj, TNG_TRAJ_FORCES, - "FORCES", - TNG_DOUBLE_DATA, - TNG_TRAJECTORY_BLOCK, - n_frames_per_frame_set, 3, - 1, 0, np, - TNG_UNCOMPRESSED, 0) != TNG_SUCCESS) + if(tng_particle_data_block_add(traj, TNG_TRAJ_FORCES,"FORCES",TNG_DOUBLE_DATA,TNG_TRAJECTORY_BLOCK,n_frames_per_frame_set, 3, 1, 0, np, codec_id, 0) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); exit(1); @@ -270,13 +258,7 @@ int main () /* There is no standard ID for potential energy. Pick one. The potential energy will not be saved every frame - it is sparsely saved. */ - if(tng_data_block_add(traj, 10101, - "POTENTIAL ENERGY", - TNG_DOUBLE_DATA, - TNG_TRAJECTORY_BLOCK, - n_frames_per_frame_set, 1, - sparse_save, TNG_UNCOMPRESSED, - 0) != TNG_SUCCESS) + if(tng_data_block_add(traj, 10101, "POTENTIAL ENERGY", TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK, n_frames_per_frame_set, 1, sparse_save, codec_id, 0) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); exit(1); @@ -359,8 +341,7 @@ int main () } if(step % (step_save * sparse_save) == 0) { - if(tng_frame_data_write(traj, frames_saved_cnt, 10101, &potential, - TNG_USE_HASH) != TNG_SUCCESS) + if(tng_frame_data_write(traj, frames_saved_cnt, 10101, &potential,TNG_USE_HASH) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); exit(1); diff --git a/src/tests/sr_test.c b/src/tests/sr_test.c new file mode 100644 index 0000000..513a25f --- /dev/null +++ b/src/tests/sr_test.c @@ -0,0 +1,1249 @@ +#ifdef TNG_BUILD_OPENMP_EXAMPLES + +#include "tng/tng_io.h" +#include <stdlib.h> +#include <stdio.h> +#include <time.h> +#include <math.h> +#include <omp.h> +#include <unistd.h> +#include <sys/utsname.h> // for uname +#include <time.h> +int main(); +void compute(int number_of_particles, int dimensions, double positions[], double vel[], double mass, double forces[], double *pot, double *kin); +double dist(int dimensions, double r1[], double r2[], double dr[]); +void initialize(int particle_count, int num_dims, double box[], double pos[], double vel[], double acc[]); +void timestamp(void); +void update(int number_of_particles, int dimensions, double *box, double pos[], double vel[], double foces[], double acc[], double mass, double dt); + +void fail(tng_trajectory_t *traj, int code) { + fprintf(stderr,"...failed! => %d\n",code); + tng_trajectory_destroy(traj); + exit(code); +} + +void fail2(tng_trajectory_t *traj1,tng_trajectory_t *traj2, int code) { + fprintf(stderr,"...failed! => %d\n",code); + tng_trajectory_destroy(traj1); + tng_trajectory_destroy(traj2); + exit(code); +} + +void greeter(int number_of_particles, int step_num, double dt, int proc_num, int threads, int dimensions, double *box) { + printf("\n"); + printf("MD_OPENMP\n"); + printf(" C/OpenMP version\n"); + printf("\n"); + printf(" A molecular dynamics program.\n"); + + printf("\n"); + printf(" NP, the number of particles in the simulation is %d\n", number_of_particles); + printf(" STEP_NUM, the number of time steps, is %d\n", step_num); + printf(" DT, the size of each time step, is %f\n", dt); + + + printf("\n"); + printf(" Box shape: %f", box[0]); + int dim = 1; + for (; dim < dimensions; dim++) { + printf(" x %f", box[dim]); + } + + printf("\n"); +} + +/* this creates 2/3 * number_of_particles molecules of water and 1/3 molecles of love. */ +void create_molecules(tng_trajectory_t *traj, const int number_of_particles) { + tng_molecule_t water; + tng_chain_t water_chain; + tng_residue_t water_chain_residue; + tng_atom_t water_residue_atom; + + /* Set molecules data */ + printf(" Creating molecules in trajectory.\n"); + + if (tng_molecule_add(*traj, "water", &water) != TNG_SUCCESS) fail(traj,__LINE__); + if (tng_molecule_chain_add(*traj, water, "W", &water_chain) != TNG_SUCCESS) fail(traj,__LINE__); // molecule, name + if (tng_chain_residue_add(*traj, water_chain, "WAT", &water_chain_residue) != TNG_SUCCESS) fail(traj,__LINE__);; // chain, name + if (tng_residue_atom_add(*traj, water_chain_residue, "Hydrogen", "Hydrogen Type", &water_residue_atom) != TNG_SUCCESS) fail(traj,__LINE__); //atom name,atom type, *atom + if (tng_molecule_cnt_set(*traj, water, 2 * number_of_particles / 3) != TNG_SUCCESS) fail(traj,__LINE__); + + tng_molecule_t love; + tng_chain_t love_chain; + tng_residue_t love_chain_residue; + tng_atom_t love_residue_atom; + + if (tng_molecule_add(*traj, "love", &love) != TNG_SUCCESS) fail(traj,__LINE__); // name + if (tng_molecule_chain_add(*traj, love, "W", &love_chain) != TNG_SUCCESS) fail(traj,__LINE__); // molecule, name + if (tng_chain_residue_add(*traj, love_chain, "WAT", &love_chain_residue) != TNG_SUCCESS) fail(traj,__LINE__); // chain, name + if (tng_residue_atom_add(*traj, love_chain_residue, "love atom", "love atom type", &love_residue_atom) != TNG_SUCCESS) fail(traj,__LINE__); + if (tng_molecule_cnt_set(*traj, love, number_of_particles - (2 * number_of_particles / 3)) != TNG_SUCCESS) fail(traj,__LINE__); +} + +void lammpstrj_write_positions(FILE *f, const int64_t frame_nr, int dimensions, double *box, const int64_t number_of_particles, double *values) { + fprintf(f, "ITEM: TIMESTEP\n%d\n", frame_nr); + fprintf(f, "ITEM: NUMBER OF ATOMS\n%d\n", number_of_particles); + fprintf(f, "ITEM: BOX BOUNDS\n"); + int dimension = 0; + for (; dimension < dimensions; dimension++) { + fprintf(f, "0 %f\n", box[dimension]); + } + fprintf(f, "ITEM: ATOMS id type x y z\n"); + int atom = 0; + for (; atom < number_of_particles; atom++) { + fprintf(f, "%d ", 1 + atom); + fprintf(f, "%d", atom % 7); + for (dimension = 0; dimension < dimensions; dimension++) { + int index = dimensions * atom + dimension; + fprintf(f, " %f", values[dimensions * atom + dimension]); + } + fprintf(f, "\n"); + } +} + + +void free_structures(double* d1, double* d2, double* d3, double* d4, double* d5) { + free(d1); + free(d2); + free(d3); + free(d4); + free(d5); +} + +void print_time(){ + time_t rawtime; + time ( &rawtime ); + printf ("%d",rawtime); +} + +double random_value(double max) { + return max * rand() / (RAND_MAX + 1.0); +} + +char *create_trajectory(int particle_count, int step_count, int initial_offset, int step_save, double dt, int proc_count, int thread_count, int dimensions, double *box,int dst_frames_per_block,char *filename,int save,int64_t codec_id, double precision) { + /* Start initialization */ + + char hash_mode = TNG_USE_HASH; + + printf("Initializing trajectory storage:\n"); + tng_trajectory_t sink_traj; // sink trajectory handle + if (tng_trajectory_init(&sink_traj) != TNG_SUCCESS) fail(&sink_traj, __LINE__); + + int64_t medium_stride_length = 5; + + if (tng_medium_stride_length_set(sink_traj, medium_stride_length) != TNG_SUCCESS) fail(&sink_traj,__LINE__); + printf("\t- medium stride length: %d\n", medium_stride_length); + + int64_t long_stride_length = 25; + + if (tng_long_stride_length_set(sink_traj, 25) != TNG_SUCCESS) fail(&sink_traj,__LINE__); + printf("\t- long stride length: %d\n", long_stride_length); + + if (tng_num_frames_per_frame_set_set(sink_traj,dst_frames_per_block) != TNG_SUCCESS) fail(&sink_traj,__LINE__); + printf("\t- number of frames per block (sink): %d.\n",dst_frames_per_block); + + if (tng_compression_precision_set(sink_traj, 1/precision) != TNG_SUCCESS) fail(&sink_traj, __LINE__); + printf("\t- set compression precision: %f\n", precision); + + char *username = getenv("USER"); + if (username == NULL) fail(&sink_traj, 3); + printf("\t- writing user data"); + if (tng_first_user_name_set(sink_traj, username) != TNG_SUCCESS) fail(&sink_traj,__LINE__); + + char *prog_name = getenv("_"); + if (prog_name == NULL) fail(&sink_traj, 4); + if (tng_first_program_name_set(sink_traj, prog_name) != TNG_SUCCESS) fail(&sink_traj,__LINE__); + + struct utsname buffer; + if (uname(&buffer) != 0) fail(&sink_traj, 2); + printf(".\n\t- writing computer data"); + + if (tng_first_computer_name_set(sink_traj, buffer.nodename) != TNG_SUCCESS) fail(&sink_traj,__LINE__); + + printf("writing forcfield type:\n"); + char *forcefield_name="no forcefield"; + + if (tng_forcefield_name_set(sink_traj, forcefield_name) != TNG_SUCCESS) fail(&sink_traj,__LINE__); + printf("Name of force field: %s\n", forcefield_name); + + printf("Setting output file name to %s.\n",filename); + if (tng_output_file_set(sink_traj, filename) != TNG_SUCCESS) fail(&sink_traj, __LINE__); + + /* start writing molecules */ + create_molecules(&sink_traj, particle_count); + /* end writing molecules */ + + /* start writing box settings */ + printf("Writing box shape\n"); + if (tng_data_block_add(sink_traj, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE", TNG_DOUBLE_DATA, TNG_NON_TRAJECTORY_BLOCK, 1, dimensions, 1, TNG_UNCOMPRESSED, box) == TNG_CRITICAL) fail(&sink_traj, 7); + /* end writing box settings */ + + /* start writing comments */ + printf("Adding annotation block.\n"); + char *annotation = "This is just a test file - not a real simulation trajectory."; + if (tng_data_block_add(sink_traj, TNG_TRAJ_GENERAL_COMMENTS, "COMMENTS", TNG_CHAR_DATA, TNG_NON_TRAJECTORY_BLOCK, 1, 1, 1, TNG_UNCOMPRESSED, annotation) != TNG_SUCCESS) fail(&sink_traj, 8); + /* end writing comments */ + + if(tng_time_per_frame_set(sink_traj,dt) != TNG_SUCCESS) fail(&sink_traj, __LINE__); // TODO: this has no effect + + printf("Writing file headers (including non-trajectory-data blocks).\n"); + if (tng_file_headers_write(sink_traj, hash_mode) == TNG_CRITICAL) fail(&sink_traj, __LINE__); + + int64_t frames_per_frame_set = 0; + if (tng_num_frames_per_frame_set_get(sink_traj, &frames_per_frame_set) != TNG_SUCCESS) fail(&sink_traj,__LINE__); + printf("Preparing to write %d frames per frame set", frames_per_frame_set); + + int frame_data_size = sizeof(double) * particle_count * dimensions; + + printf(".\n Allocating memory for data block"); + double *data = malloc(frame_data_size * frames_per_frame_set); + if (!data) fail(&sink_traj, 10); + + printf(".\n Allocating memory for positions"); + double *molecule_pos = malloc(frame_data_size); + if (!molecule_pos) fail(&sink_traj, 11); + + printf(".\n Allocating memory for accelerations"); + double *molecule_acc = malloc(frame_data_size); + if (!molecule_acc) fail(&sink_traj, 12); + + printf(".\n Allocating memory for forces"); + double *molecule_frc = malloc(frame_data_size); + if (!molecule_frc) fail(&sink_traj, 13); + + printf(".\n Allocating memory for velocities"); + double *molecule_vel = malloc(frame_data_size); + if (!molecule_vel) fail(&sink_traj, 14); + + initialize(particle_count, dimensions, box, molecule_pos, molecule_vel, molecule_acc); + + double mass = 2.0; + double potential, kinetic; + + printf(".\n Generating data\n"); + + int step = 0; + int frame_number = 0; + int frame_set_number = 0; + + int particle_number = 0; + int dimension = 0; + int index = 0; + + int verbosity = 1; + printf("Running %d steps without storing data.\n",initial_offset); + if (initial_offset>0){ + while (step < initial_offset) { + compute(particle_count, dimensions, molecule_pos, molecule_vel, mass, molecule_frc, &potential, &kinetic); + update(particle_count, dimensions, box, molecule_pos, molecule_vel, molecule_frc, molecule_acc, mass, dt); + step++; + } + } + step=0; + + printf("start_time="); + print_time(); + printf("\n"); + + while (step < step_count) { + + compute(particle_count, dimensions, molecule_pos, molecule_vel, mass, molecule_frc, &potential, &kinetic); + update(particle_count, dimensions, box, molecule_pos, molecule_vel, molecule_frc, molecule_acc, mass, dt); + + if ((save>0) && (step % step_save == 0)) { + if (verbosity > 1) printf("step %d used as frame %d\n", step, frame_number); + for (particle_number = 0; particle_number < particle_count; particle_number++) { + + // set particle position in each dimension + for (dimension = 0; dimension < dimensions; dimension++) { + data[index++] = molecule_pos[particle_number * dimensions + dimension]; + } + } + frame_number++; + + if ((frame_number % frames_per_frame_set == 0)) { + /* Frame set full. Write block and go on */ + + if (verbosity > 0) + printf("writing block %d\n", frame_set_number); + + // create new frameset for data + if (tng_frame_set_new(sink_traj, frame_set_number * frames_per_frame_set, frames_per_frame_set) != TNG_SUCCESS) { + free_structures(data, molecule_vel, molecule_frc, molecule_acc, molecule_pos); + fail(&sink_traj, 15); + } + + // add data to trajectory + if (tng_particle_data_block_add(sink_traj, TNG_TRAJ_POSITIONS, "POSITIONS", TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK, frames_per_frame_set, dimensions, 1, 0, particle_count, codec_id, data) != TNG_SUCCESS) { + free_structures(data, molecule_vel, molecule_frc, molecule_acc, molecule_pos); + fail(&sink_traj, 16); + } + + if (tng_frame_set_write(sink_traj, hash_mode) != TNG_SUCCESS) { // write the frameset including data to file + free_structures(data, molecule_vel, molecule_frc, molecule_acc, molecule_pos); + fail(&sink_traj, 17); + } + frame_set_number++; + index = 0; + } + + } else { + if (verbosity > 2) printf("step %d\n", step); + } + if (verbosity > 3) { + printf("%f", molecule_pos[0]); + for (dimension = 1; dimension < dimensions; dimension++) { + printf(" / %f", molecule_pos[dimension]); + } + printf("\n"); + } + + step++; + } + + free_structures(data, molecule_vel, molecule_frc, molecule_acc, molecule_pos); + tng_trajectory_destroy(&sink_traj); // finalizing and closing trajectory file, free memory + + printf("end_time="); + print_time(); + printf("\n"); + + return filename; +} + +/* copy molecule data from source trajectory to destination trajectory */ +int transfer_molecules(tng_trajectory_t src_traj,tng_trajectory_t sink_traj){ + int64_t number_of_molecule_types; + if (tng_num_molecule_types_get(src_traj, &number_of_molecule_types)!= TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf("There are %d types of molecules:\n",number_of_molecule_types); + + int mol_type_index; + for (mol_type_index=0; mol_type_index<number_of_molecule_types; mol_type_index++){ + tng_molecule_t src_molecule,sink_molecule; + if (tng_molecule_of_index_get(src_traj,mol_type_index,&src_molecule) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + char molecule_name[TNG_MAX_STR_LEN]; + if (tng_molecule_name_get(src_traj, src_molecule, molecule_name, TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf("-molecule type %d: %s\n",mol_type_index,molecule_name); + + if (tng_molecule_add(sink_traj, molecule_name, &sink_molecule) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + int64_t chain_count; + if(tng_molecule_num_chains_get(src_traj,src_molecule,&chain_count) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf(" this molecule has %d chains:\n",chain_count); + + int chain_index; + for (chain_index=0; chain_index<chain_count; chain_index++){ + + tng_chain_t src_chain,sink_chain; + if(tng_molecule_chain_of_index_get(src_traj,src_molecule,chain_index,&src_chain) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + char chain_name[TNG_MAX_STR_LEN]; + if(tng_chain_name_get(src_traj,src_chain,chain_name,TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf(" -chain %d: %s\n",chain_index,chain_name); + + if(tng_molecule_chain_add(sink_traj, sink_molecule, chain_name, &sink_chain) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + int64_t residue_count; + if(tng_chain_num_residues_get(src_traj,src_chain,&residue_count) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf(" has %d residues:\n",residue_count); + + int residue_index; + for (residue_index=0; residue_index<residue_count; residue_index++){ + + tng_residue_t src_residue,sink_residue; + if(tng_chain_residue_of_index_get(src_traj,src_chain,residue_index,&src_residue) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + char residue_name[TNG_MAX_STR_LEN]; + if(tng_residue_name_get(src_traj,src_residue,residue_name,TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf(" -residue %d: %s\n",residue_index,residue_name); + + if (tng_chain_residue_add(sink_traj, sink_chain, residue_name, &sink_residue) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + int64_t atom_count; + if(tng_residue_num_atoms_get(src_traj,src_residue,&atom_count) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf(" has %d atoms:\n",atom_count); + + int atom_index; + for (atom_index=0; atom_index<atom_count; atom_index++){ + + tng_atom_t src_atom,sink_atom; + if (tng_residue_atom_of_index_get(src_traj,src_residue,atom_index,&src_atom) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + char atom_name[TNG_MAX_STR_LEN]; + if (tng_atom_name_get(src_traj,src_atom,atom_name,TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + char atom_type[TNG_MAX_STR_LEN]; + if (tng_atom_type_get(src_traj,src_atom,atom_type,TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf(" -atom %d is of type %s: %s\n",atom_index,atom_type,atom_name); + + if(tng_residue_atom_add(sink_traj, sink_residue, atom_name, atom_type, &sink_atom) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + } + } + } + int64_t molecule_count; + if(tng_molecule_cnt_get(src_traj,src_molecule,&molecule_count) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + if(tng_molecule_cnt_set(sink_traj, sink_molecule, molecule_count) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf(" set number of %s molecules to %d\n",molecule_name,molecule_count); + } +} + +/* copy box data from source trajectory to destination trajectory */ +int transfer_box_data(tng_trajectory_t src_traj,tng_trajectory_t sink_traj, double **box, int64_t *dimensions, char *type){ + int64_t dimension,number_of_box_shape_frames; + union data_values **box_data = 0; + + if (tng_data_get(src_traj,TNG_TRAJ_BOX_SHAPE,&box_data,&number_of_box_shape_frames,dimensions,type)!=TNG_SUCCESS)fail2(&src_traj,&sink_traj,__LINE__); + printf("Read %d box dimensions: ",*dimensions); + int size=*dimensions * sizeof(double); + *box=malloc(*dimensions * sizeof(double)); + for (dimension=0; dimension<*dimensions;dimension++){ + if (*type == TNG_DOUBLE_DATA){ + (*box)[dimension] = box_data[0][dimension].d; + printf("%f",(*box)[dimension]); + if (dimension+1<*dimensions){ + printf(" x "); + } + } else { + fail2(&src_traj,&sink_traj,__LINE__); + } + } + printf(".\n"); + + if (sink_traj != NULL){ + if (tng_data_block_add(sink_traj, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE", *type, TNG_NON_TRAJECTORY_BLOCK, 1, *dimensions, 1, TNG_UNCOMPRESSED, *box) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, 472); + printf("Box size written to destination trajectory.\n"); + } +} + +/* copy comment data from source trajectory to destination trajectory */ +int transfer_comments(tng_trajectory_t src_traj,tng_trajectory_t sink_traj){ + int64_t num_comments,comment_frame_num; + char comment_type; + union data_values **comment_data = 0; + if(tng_data_get(src_traj,TNG_TRAJ_GENERAL_COMMENTS,&comment_data,&comment_frame_num,&num_comments,&comment_type) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + if (comment_type != TNG_CHAR_DATA)fail2(&src_traj,&sink_traj,__LINE__); + char *annotation=0; + switch (num_comments){ + case 1: + annotation = comment_data[0][0].c; + printf("Found comment: \"%s\"\n",annotation); + printf("Adding comment block.\n"); + if (tng_data_block_add(sink_traj, TNG_TRAJ_GENERAL_COMMENTS, "COMMENTS", TNG_CHAR_DATA, TNG_NON_TRAJECTORY_BLOCK, 1, 1, 1, TNG_UNCOMPRESSED, annotation) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + break; + case 0: + break; + default: + fail2(&src_traj,&sink_traj,__LINE__); + } +} + + +int rewrite_file(char *sink_tng_file, int64_t dst_frames_per_block, int steps_save,int64_t sink_codec_id, double precision, char *src_tng_file) { + /* Start initialization */ + printf("Preparing to read stored trajectory...\n"); + tng_trajectory_t src_traj; // source trajectory handle + if (tng_trajectory_init(&src_traj) != TNG_SUCCESS) fail(&src_traj, __LINE__); + + char hash_mode = TNG_USE_HASH; + + printf("Setting input file to %s.\n", src_tng_file); + if (tng_input_file_set(src_traj, src_tng_file) != TNG_SUCCESS) fail(&src_traj, __LINE__); + if (tng_file_headers_read(src_traj, hash_mode) != TNG_SUCCESS) fail(&src_traj, __LINE__); + + printf("Initializing trajectory storage:\n"); + tng_trajectory_t sink_traj; // sink trajectory handle + if (tng_trajectory_init(&sink_traj) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + + int64_t medium_stride_length; + + if (tng_medium_stride_length_get(src_traj, &medium_stride_length) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + if (tng_medium_stride_length_set(sink_traj, medium_stride_length) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf("medium stride length: %d\n", medium_stride_length); + + int64_t long_stride_length; + + if (tng_long_stride_length_get(src_traj, &long_stride_length) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + if (tng_long_stride_length_set(sink_traj, long_stride_length) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf("long stride length: %d\n", long_stride_length); + + int64_t src_frames_per_block; + if (tng_num_frames_per_frame_set_get(src_traj,&src_frames_per_block) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + if (tng_num_frames_per_frame_set_set(sink_traj,dst_frames_per_block) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf("Number of frames per block (source => sink): %d => %d.\n",src_frames_per_block,dst_frames_per_block); + + printf("reading computer information:\n"); + + + char username[TNG_MAX_STR_LEN]; + if (tng_first_user_name_get(src_traj, username, TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + if (tng_first_user_name_set(sink_traj, username) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf("File was created by %s", username); + + char prog_name[TNG_MAX_STR_LEN]; + if (tng_first_program_name_get(src_traj, prog_name, TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + + if (tng_first_program_name_set(sink_traj, prog_name) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf(" running %s", prog_name); + + char computer_name[TNG_MAX_STR_LEN]; + if(tng_first_computer_name_get(src_traj, computer_name, TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + + + if (tng_first_computer_name_set(sink_traj, computer_name) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf(" on %s\n", computer_name); + + printf("writing forcfield type:\n"); + char forcefield_name[TNG_MAX_STR_LEN]; + if(tng_forcefield_name_get(src_traj, forcefield_name, TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + + if (tng_forcefield_name_set(sink_traj, forcefield_name) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf("Name of force field: %s\n", forcefield_name); + + printf("Setting output file name to %s.\n", sink_tng_file); + if (tng_output_file_set(sink_traj, sink_tng_file) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + + /* start writing molecules */ + transfer_molecules(src_traj,sink_traj); + /* end writing molecules */ + + /* start writing box settings */ + printf("Writing box shape\n"); + int64_t dimensions; + char type; + double *box=NULL; + transfer_box_data(src_traj,sink_traj,&box,&dimensions,&type); + /* end writing box settings */ + + /* start writing comments */ + printf("Adding annotation block.\n"); + transfer_comments(src_traj,sink_traj); + /* end writing comments */ + + double time_per_frame; + if(tng_time_per_frame_get(src_traj, &time_per_frame) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf("time per frame: %f\n", time_per_frame); + // TODO: somehow this returns a wrong value + if(tng_time_per_frame_set(sink_traj,0.0002) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + printf("Writing file headers (including non-trajectory-data blocks).\n"); + if (tng_file_headers_write(sink_traj, hash_mode) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,494); + + int64_t frames_per_frame_set = 0; + if (tng_num_frames_per_frame_set_get(sink_traj, &frames_per_frame_set) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf("Preparing to write %d frames per frame set", frames_per_frame_set); + + + + + if (tng_compression_precision_set(sink_traj, 1/precision) != TNG_SUCCESS) fail2(&src_traj,&sink_traj, __LINE__); + printf("Set compression precision: %f\n", precision); + /* End of Initialization */ + + + + + + + + int64_t stride_length; + if (tng_data_get_stride_length(src_traj, TNG_TRAJ_POSITIONS, 0, &stride_length)!=TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf("stride length of first frame is %d.\n", stride_length); + + int64_t source_number_of_blocks; + if(tng_num_frame_sets_get(src_traj, &source_number_of_blocks) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + + printf("total number of frame sets in source file: %d.\n",source_number_of_blocks); + + transfer_box_data(sink_traj,NULL,&box,&dimensions,&type); + + + union data_values ***src_positions = 0; // data structure to handle position data between input and output + double *dst_positions=NULL; + int dst_pos_index=0; + int64_t src_block_num=0; + int64_t src_frame_num=0; + + int64_t dst_frame_num=0; + + /* loop through each block of the source file */ + + + + + while (src_block_num<source_number_of_blocks){ + if (tng_frame_set_read(src_traj,hash_mode) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + int64_t src_number_of_particles,src_values_per_particle,src_number_of_frames_in_current_block; + if (tng_particle_data_get(src_traj,TNG_TRAJ_POSITIONS,&src_positions,&src_number_of_frames_in_current_block,&src_number_of_particles,&src_values_per_particle,&type) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + printf("Opened frameset %d (%d frames with %d particles, each having %d values).\n",src_block_num,src_number_of_frames_in_current_block,src_number_of_particles,src_values_per_particle); + + if (src_values_per_particle != dimensions){ + printf("This does not match the number of dimensions! Aborting now.\n"); + fail2(&src_traj,&sink_traj,__LINE__); + } + if (type != TNG_DOUBLE_DATA) fail2(&src_traj,&sink_traj,__LINE__); + + char block_name[TNG_MAX_STR_LEN]; + if(tng_data_block_name_get(src_traj, TNG_TRAJ_POSITIONS, block_name, TNG_MAX_STR_LEN) != TNG_SUCCESS) fail2(&src_traj,&sink_traj,__LINE__); + + int64_t src_values_per_frame=src_number_of_particles*src_values_per_particle; + + if (src_frame_num == 0) { + printf("allocating space for dst_postisions: "); + dst_positions=malloc(dst_frames_per_block * src_values_per_frame * sizeof(double)); + printf("done\n"); + } + + int64_t src_local_frame; + /* loop through all frames of the current block */ + for (src_local_frame=0; src_local_frame<src_number_of_frames_in_current_block; src_local_frame++){ + printf("read frame %d",src_frame_num); + /* resampling option: only store frames that meet the new sampling rate */ + if (src_frame_num % steps_save == 0){ + + int particle; + /* get positions for all particles */ + for (particle=0; particle<src_number_of_particles;particle++){ + int dimension; + + /* for each particle get location in each dimension */ + for (dimension=0; dimension<dimensions; dimension++){ + double value=src_positions[src_local_frame][particle][dimension].d; + dst_positions[dst_pos_index]=value; + dst_pos_index++; + } + } // fore each particle + dst_frame_num++; + printf(" - will be stored!\n"); + + if (dst_frame_num % dst_frames_per_block == 0){ + printf("writing block.\n"); + if (tng_frame_set_new(sink_traj, dst_frame_num-dst_frames_per_block, dst_frames_per_block)!= TNG_SUCCESS){ + fail2(&src_traj,&sink_traj,__LINE__); + } + printf(" created new frame set\n"); + + if (tng_particle_data_block_add(sink_traj, TNG_TRAJ_POSITIONS, block_name, type, TNG_TRAJECTORY_BLOCK, dst_frames_per_block, dimensions, stride_length, 0, src_number_of_particles, sink_codec_id, dst_positions) != TNG_SUCCESS){ + fail2(&src_traj,&sink_traj,__LINE__); + } + printf(" added particle data block\n"); + + if (tng_frame_set_write(sink_traj, hash_mode) != TNG_SUCCESS){ + fail2(&src_traj,&sink_traj,__LINE__); + } + printf(" written frame set\n"); + + dst_pos_index=0; + printf("flushed.\n"); + } + + + } // if frame meets resampling rate + else { + printf("\n"); + } + src_frame_num++; + } + + src_block_num++; + } + + free(dst_positions); + free(box); + tng_trajectory_destroy(&sink_traj); + tng_trajectory_destroy(&src_traj); + + return 0; +} + +int translate_file(char *src_tng_file){ + /* Start initialization */ + printf("Preparing to read stored trajectory...\n"); + tng_trajectory_t src_traj; // source trajectory handle + if (tng_trajectory_init(&src_traj) != TNG_SUCCESS) fail(&src_traj, __LINE__); + + printf("Setting input file to %s.\n", src_tng_file); + if (tng_input_file_set(src_traj, src_tng_file) != TNG_SUCCESS) fail(&src_traj, __LINE__); + + char hash_mode = TNG_USE_HASH; + if (tng_file_headers_read(src_traj, hash_mode) != TNG_SUCCESS) fail(&src_traj, __LINE__); + /* End of Initialization */ + + /* get box data (we actually need type and dimensions) */ + int64_t dimensions; + char type; + double *box=NULL; + transfer_box_data(src_traj,NULL,&box,&dimensions,&type); + /* end get box data */ + + int64_t source_number_of_blocks; + if(tng_num_frame_sets_get(src_traj, &source_number_of_blocks) != TNG_SUCCESS) fail(&src_traj,__LINE__); + printf("total number of frame sets in file: %d.\n",source_number_of_blocks); + + FILE *lammpfile; + { // open lammpstrj file for writing trajectory data in vmd-readable format + char *lammp_output_file; + char *extension = ".lammpstrj"; + lammp_output_file=malloc(strlen(src_tng_file)+strlen(extension)+1); + lammp_output_file[0]='\0'; + strcat(lammp_output_file,src_tng_file); + strcat(lammp_output_file,extension); + lammpfile = fopen(lammp_output_file,"w"); + free(lammp_output_file); + printf("Opened %s for writing.\n",lammp_output_file); + } + + union data_values ***src_positions = 0; // data structure to handle position data between input and output + double *positions=NULL; + int64_t src_block_num=0; + int64_t src_frame_num=0; + + /* loop through each block of the source file */ + while (src_block_num<source_number_of_blocks){ + if (tng_frame_set_read(src_traj,hash_mode) != TNG_SUCCESS) fail(&src_traj,__LINE__); + + int64_t src_number_of_particles,src_values_per_particle,src_number_of_frames_in_current_block; + if (tng_particle_data_get(src_traj,TNG_TRAJ_POSITIONS,&src_positions,&src_number_of_frames_in_current_block,&src_number_of_particles,&src_values_per_particle,&type) != TNG_SUCCESS) fail(&src_traj,__LINE__); + printf("Opened frameset %d (%d frames with %d particles, each having %d values).\n",src_block_num,src_number_of_frames_in_current_block,src_number_of_particles,src_values_per_particle); + + if (src_values_per_particle != dimensions){ + printf("This does not match the number of dimensions! Aborting now.\n"); + fail(&src_traj,__LINE__); + } + if (type != TNG_DOUBLE_DATA) fail(&src_traj,__LINE__); + + char block_name[TNG_MAX_STR_LEN]; + if(tng_data_block_name_get(src_traj, TNG_TRAJ_POSITIONS, block_name, TNG_MAX_STR_LEN) != TNG_SUCCESS) fail(&src_traj,__LINE__); + + int64_t src_values_per_frame=src_number_of_particles*src_values_per_particle; + + positions=malloc(src_number_of_frames_in_current_block * src_values_per_frame * sizeof(double)); + + int64_t src_local_frame; + /* loop through all frames of the current block */ + for (src_local_frame=0; src_local_frame<src_number_of_frames_in_current_block; src_local_frame++){ + int index=0; + /* resampling option: only store frames that meet the new sampling rate */ + + int particle; + /* get positions for all particles */ + for (particle=0; particle<src_number_of_particles;particle++){ + int dimension; + /* for each particle get location in each dimension */ + for (dimension=0; dimension<dimensions; dimension++){ + double value=src_positions[src_local_frame][particle][dimension].d; + positions[index]=value; + index++; + } + } // fore each particle + lammpstrj_write_positions(lammpfile,src_frame_num,dimensions,box,src_number_of_particles,positions); + printf("read frame %d.\n",src_frame_num); + src_frame_num++; + } + free(positions); + src_block_num++; + } + + free(box); + tng_trajectory_destroy(&src_traj); + fclose(lammpfile); // close lammp file + + return 0; + +} + +/******************************************************************************/ + +/* arguments taken: + * <number of blocks> <number of frames per block> <cubic box length> <filename> + */ +int generate(char *orig_file,int frames_per_block,int step_save,int64_t codec_id, double precision, int framesets,int particle_count,int box_size,int initial_offset,int save){ + + int step_count = framesets*frames_per_block*step_save; + int dimensions = 3; + double dt = 0.0002; + int proc_count = omp_get_num_procs(); + int thread_count = omp_get_max_threads(); + double box[dimensions]; + int dim = 0; + for (; dim < dimensions; dim++) { + box[dim] = box_size+dim; + } + printf("Simulating %dx%dx%d box with %d molecules. ",box_size,box_size+1,box_size+2,particle_count); + if (step_save<10 || step_save>15){ + switch (step_save%10){ + case 1: + printf(" Storing every %dst frame.",step_save); + break; + case 2: + printf(" Storing every %dnd frame.",step_save); + break; + case 3: + printf(" Storing every %drd frame.",step_save); + break; + default: + printf(" Storing every %dth frame.",step_save); + break; + } + } else { + printf(" Storing every %dth frame.",step_save); + } + printf(" Generating %d frame sets with each %d frames.\n",framesets,frames_per_block); + printf(" Number of processors available = %d\n", proc_count); + printf(" Number of threads = %d\n", thread_count); + + orig_file = create_trajectory(particle_count, step_count, initial_offset, step_save, dt, proc_count, thread_count, dimensions, box,frames_per_block,orig_file,save,codec_id, precision); + printf("\nWritten original trajectory to %s.\n",orig_file); + return 0; +} + + +int show_help(char *argv[]){ + printf("Usage:\n"); + printf("%s -g [-b <blocks>] [-c <codec>] [-d <precision>] [-f <fpb>] [-o <offset>] [-p <parts>] [-s <save_interval>] [-x <box_size>] -n <outfile>\n\tto generate a trajectory or\n",*argv); + printf("%s -r -i <infile> [-c <codec>] [-d <precision>] [-f <fpb>] [-s <save_interval>] -n <outfile> \n\tto rewrite (compress) a trajectory or\n",*argv); + printf("%s -t <infile>\n\tto translate the tng file to a lammpstrj file or\n",*argv); + printf("%s -v\nto print the version of the used hrtc lib."); + printf("\n"); + printf("<blocks> : number of frame sets (blocks)\n"); + printf("<box_size> : length of the reactor box\n"); + printf("<codec> = NONE | TNG | HRTC\n"); + printf("<fpb> : number of frames per block/frame set\n"); + printf("<infile> : name of the input file\n"); + printf("<offset> : number of frames to simulate BEFORE storagestarts.\n"); + printf("<outfile> : name of the output file\n"); + printf("<parts> : number of particles\n"); + printf("<precision> : precision value for compression (default: 0.001)\n"); + printf("<save_interval>: determines, which frames of the simulation shall be saved.\n"); + printf("\n"); +} + +void print_version(){ + hrtc_version(); +} + +int main(int argc, char *argv[]) { + setlinebuf(stdout); + + int cmd_arg; + + int generate_flag=0; + int rewrite_flag=0; + int translate_flag=0; + int number_of_blocks=10; + int number_of_particles=32; + int frames_per_block=100; + int box_size=10; + int codec=TNG_UNCOMPRESSED; + int save=1; + int steps_save=100; + int initial_offset=0; + double precision=0.001; + char *in_filename=NULL; + char *out_filename=NULL; + + while ((cmd_arg=getopt(argc,argv,"b:c:d:f:ghi:n:o:p:rs:t:vx:")) != -1){ + switch (cmd_arg){ + case 'b': + number_of_blocks=atoi(optarg); + break; + case 'c': + if (strcmp(optarg,"HRTC")==0){ + codec=TNG_HRTC_COMPRESSION; + } + if (strcmp(optarg,"NONE")==0){ + codec=TNG_UNCOMPRESSED; + } + if (strcmp(optarg,"TNG")==0){ + codec=TNG_TNG_COMPRESSION; + } + if (strcmp(optarg,"NO_SAVE")==0){ + save=0; + } + break; + case 'd': + precision=atof(optarg); + break; + case 'f': + frames_per_block=atoi(optarg); + break; + case 'g': + generate_flag=1; + break; + case 'h': + show_help(argv); + break; + case 'i': + in_filename=optarg; + break; + case 'n': + out_filename=optarg; + break; + case 'o': + initial_offset=atoi(optarg); + break; + case 'p': + number_of_particles=atoi(optarg); + break; + case 'r': + rewrite_flag=1; + break; + case 's': + steps_save=atoi(optarg); + break; + case 't': + translate_flag=1; + in_filename=optarg; + break; + case 'v': + print_version(); + return 0; + break; + case 'x': + box_size=atoi(optarg); + break; + case '?': + fprintf(stderr,"Option -%c requires an argument!\n",optopt); + break; + } + + } + + if (generate_flag + rewrite_flag + translate_flag > 1){ + fprintf(stderr,"-g, -r, and -t are exclusive flags!\n"); + return __LINE__; + } + if (! (generate_flag || rewrite_flag || translate_flag)){ + fprintf(stderr,"You need to specify either -g, -r, or -t!\n"); + return __LINE__; + } + if (generate_flag || rewrite_flag){ + if (out_filename==NULL){ + fprintf(stderr,"No output filename given!\n"); + return __LINE__; + } + } + if (rewrite_flag || translate_flag){ + if (in_filename==NULL){ + fprintf(stderr,"No input filename given!\n"); + return __LINE__; + } + } + + if (generate_flag) return generate ( out_filename, frames_per_block, steps_save, codec, precision, number_of_blocks, number_of_particles, box_size, initial_offset, save); + if (rewrite_flag) return rewrite_file(out_filename, frames_per_block, steps_save, codec, precision, in_filename); + if (translate_flag) return translate_file(in_filename); + + return __LINE__; +} +/******************************************************************************/ + + +void compute(int number_of_particles, int dimensions, double positions[], double vel[], double mass, double forces[], double *pot, double *kin) +/******************************************************************************/ +/* + Purpose: + + COMPUTE computes the forces and energies. + + Discussion: + + The computation of forces and energies is fully parallel. + + The potential function V(X) is a harmonic well which smoothly + saturates to a maximum value at PI/2: + + v(x) = ( sin ( min ( x, PI2 ) ) )**2 + + The derivative of the potential is: + + dv(x) = 2.0 * sin ( min ( x, PI2 ) ) * cos ( min ( x, PI2 ) ) + = sin ( 2.0 * min ( x, PI2 ) ) + + Licensing: + + This code is distributed under the GNU LGPL license. + + Modified: + + 21 November 2007 + + Author: + + Original FORTRAN77 version by Bill Magro. + C version by John Burkardt. + + Parameters: + + Input, int NP, the number of particles. + + Input, int ND, the number of spatial dimensions. + + Input, double POS[ND*NP], the position of each particle. + + Input, double VEL[ND*NP], the velocity of each particle. + + Input, double MASS, the mass of each particle. + + Output, double F[ND*NP], the forces. + + Output, double *POT, the total potential energy. + + Output, double *KIN, the total kinetic energy. + */ +{ + double distance; + double d2; + int dimension; + int particleB; + int particleA; + double ke = 0.0; + double pe = 0.0; + double half_Pi = 3.141592653589793 / 2.0; + double rij[dimensions]; + +# pragma omp parallel \ + shared ( forces, dimensions, number_of_particles, positions, vel ) \ + private ( dimension, particleB, particleA, rij, distance, d2 ) + +# pragma omp for reduction ( + : pe, ke ) + for (particleA = 0; particleA < number_of_particles; particleA++) { + /* + Compute the potential energy and forces. + */ + for (dimension = 0; dimension < dimensions; dimension++) { + forces[dimension + particleA * dimensions] = 0.0; + } + + for (particleB = 0; particleB < number_of_particles; particleB++) { + if (particleA != particleB) { + distance = dist(dimensions, positions + particleA * dimensions, positions + particleB * dimensions, rij); + if (distance < half_Pi) { + d2 = distance; + } else { + d2 = half_Pi; + } + + pe = pe + 0.5 * pow(sin(d2), 2); + /* + Attribute half of the potential energy to particle J. + */ + for (dimension = 0; dimension < dimensions; dimension++) { + forces[dimension + particleA * dimensions] = forces[dimension + particleA * dimensions] - rij[dimension] * sin(2.0 * d2) / distance; + } + } + } + /* + Compute the kinetic energy. + */ + for (dimension = 0; dimension < dimensions; dimension++) { + ke = ke + vel[dimension + particleA * dimensions] * vel[dimension + particleA * dimensions]; + } + } + + ke = ke * 0.5 * mass; + + *pot = pe; + *kin = ke; + + return; +} +/******************************************************************************/ + +double dist(int dimensions, double r1[], double r2[], double dr[]) + +/******************************************************************************/ +/* + Purpose: + + DIST computes the displacement (and its norm) between two particles. + + Licensing: + + This code is distributed under the GNU LGPL license. + + Modified: + + 21 November 2007 + + Author: + + Original FORTRAN77 version by Bill Magro. + C version by John Burkardt. + + Parameters: + + Input, int ND, the number of spatial dimensions. + + Input, double R1[ND], R2[ND], the positions of the particles. + + Output, double DR[ND], the displacement vector. + + Output, double D, the Euclidean norm of the displacement. + */ +{ + double d; + int i; + + d = 0.0; + for (i = 0; i < dimensions; i++) { + dr[i] = r1[i] - r2[i]; + d = d + dr[i] * dr[i]; + } + d = sqrt(d); + + return d; +} +/******************************************************************************/ + +void initialize(int particle_count, int num_dims, double box[], double pos[], double vel[], double acc[]) { + printf(".\n Initializing particle positions"); + int curernt_dim; + int particle; + int index; + int seed = 0; + for (particle = 0; particle < particle_count; particle++) { + for (curernt_dim = 0; curernt_dim < num_dims; curernt_dim++) { + index = particle * num_dims + curernt_dim; + pos[index] = random_value(box[curernt_dim]); + vel[index] = 0.0; + acc[index] = 0.0; + } + } + + return; +} +/******************************************************************************/ + +void timestamp(void) + +/******************************************************************************/ +/* + Purpose: + + TIMESTAMP prints the current YMDHMS date as a time stamp. + + Example: + + 31 May 2001 09:45:54 AM + + Licensing: + + This code is distributed under the GNU LGPL license. + + Modified: + + 24 September 2003 + + Author: + + John Burkardt + + Parameters: + + None + */ +{ +# define TIME_SIZE 40 + + static char time_buffer[TIME_SIZE]; + const struct tm *tm; + time_t now; + + now = time(NULL); + tm = localtime(&now); + + strftime(time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm); + + printf("%s\n", time_buffer); + + return; +# undef TIME_SIZE +} +/******************************************************************************/ + +void update(int number_of_particles, int dimensions, double *box, double pos[], double vel[], double foces[], double acc[], double mass, double dt) + +/******************************************************************************/ +/* + Purpose: + + UPDATE updates positions, velocities and accelerations. + + Discussion: + + The time integration is fully parallel. + + A velocity Verlet algorithm is used for the updating. + + x(t+dt) = x(t) + v(t) * dt + 0.5 * a(t) * dt * dt + v(t+dt) = v(t) + 0.5 * ( a(t) + a(t+dt) ) * dt + a(t+dt) = f(t) / m + + Licensing: + + This code is distributed under the GNU LGPL license. + + Modified: + + 17 April 2009 + + Author: + + Original FORTRAN77 version by Bill Magro. + C version by John Burkardt. + + Parameters: + + Input, int NP, the number of particles. + + Input, int ND, the number of spatial dimensions. + + Input/output, double POS[ND*NP], the position of each particle. + + Input/output, double VEL[ND*NP], the velocity of each particle. + + Input, double F[ND*NP], the force on each particle. + + Input/output, double ACC[ND*NP], the acceleration of each particle. + + Input, double MASS, the mass of each particle. + + Input, double DT, the time step. + */ +{ + int dimension; + int particle_num; + double rmass; + int index; + + rmass = 1.0 / mass; + +# pragma omp parallel \ + shared ( acc, dt, foces, dimensions, number_of_particles, pos, rmass, vel, box ) \ + private ( dimension, particle_num, index ) + +# pragma omp for + for (particle_num = 0; particle_num < number_of_particles; particle_num++) { + for (dimension = 0; dimension < dimensions; dimension++) { + index = particle_num * dimensions + dimension; + + pos[index] = pos[index] + vel[index] * dt + 0.5 * acc[index] * dt * dt; + if (pos[index] > box[dimension]) { + pos[index] = 2 * box[dimension] - pos[index]; + vel[index] = -vel[index]; + } + if (pos[index] < 0) { + pos[index] = -pos[index]; + vel[index] = -vel[index]; + } + vel[index] = vel[index] + 0.5 * dt * (foces[index] * rmass + acc[index]); + acc[index] = foces[index] * rmass; + } + } + + return; +} + +#endif diff --git a/src/tests/tng_io_testing.c b/src/tests/tng_io_testing.c index 28f8f47..ee0bb94 100644 --- a/src/tests/tng_io_testing.c +++ b/src/tests/tng_io_testing.c @@ -709,6 +709,17 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t *traj, free(data); tng_trajectory_destroy(traj); + + /***********************************************************/ + /***********************************************************/ + /***********************************************************/ + /***********************************************************/ + /***********************************************************/ + /***********************************************************/ + /***********************************************************/ + /***********************************************************/ + + tng_trajectory_init(traj); tng_input_file_set(*traj, TNG_EXAMPLE_FILES_DIR "tng_test.tng"); |