diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-02-08 14:32:48 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-02-08 14:32:48 (GMT) |
commit | c5020baa6a27af8288d79f02f9ea646ae580710a (patch) | |
tree | 6f3f4df01a515489d1addcfee7edccade72514bf /src | |
parent | 0bbc8e714795d00f12edbaec48fd76aa1d3cd26e (diff) |
File endianness can be changed. No byte swapping needed if file endianness is the same as the architecture endianness. Use function pointers to determine how to swap byte orders. Changes untested
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/tng_io.c | 1743 | ||||
-rw-r--r-- | src/lib/tng_io.h | 2 |
2 files changed, 1160 insertions, 585 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 4f9f768..f2a0e3f 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -236,10 +236,18 @@ struct tng_trajectory { char *output_file_path; /** A handle to the output file */ FILE *output_file; - /** The endianness of the input file */ - tng_file_endianness input_endianness; - /** The endianness of the output file */ - tng_file_endianness output_endianness; + /** Function to swap 32 bit values to and from the endianness of the + * input file */ + tng_function_status (*input_endianness_swap_func_32)(const tng_trajectory_t, int32_t *); + /** Function to swap 64 bit values to and from the endianness of the + * input file */ + tng_function_status (*input_endianness_swap_func_64)(const tng_trajectory_t, int64_t *); + /** Function to swap 32 bit values to and from the endianness of the + * input file */ + tng_function_status (*output_endianness_swap_func_32)(const tng_trajectory_t, int32_t *); + /** Function to swap 64 bit values to and from the endianness of the + * input file */ + tng_function_status (*output_endianness_swap_func_64)(const tng_trajectory_t, int64_t *); /** The endianness of 32 bit values of the current computer */ tng_endianness_32 endianness_32; /** The endianness of 64 bit values of the current computer */ @@ -335,7 +343,7 @@ struct tng_trajectory { * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if the current * byte order is not recognised. */ -static inline tng_function_status tng_byte_order_to_big_endian_32 +static tng_function_status tng_swap_byte_order_big_endian_32 (const tng_trajectory_t tng_data, int32_t *v) { switch(tng_data->endianness_32) @@ -373,7 +381,7 @@ static inline tng_function_status tng_byte_order_to_big_endian_32 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if the current * byte order is not recognised. */ -static inline tng_function_status tng_byte_order_to_big_endian_64 +static tng_function_status tng_swap_byte_order_big_endian_64 (const tng_trajectory_t tng_data, int64_t *v) { switch(tng_data->endianness_64) @@ -425,7 +433,7 @@ static inline tng_function_status tng_byte_order_to_big_endian_64 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if the current * byte order is not recognised. */ -static inline tng_function_status tng_byte_order_to_little_endian_32 +static tng_function_status tng_swap_byte_order_little_endian_32 (const tng_trajectory_t tng_data, int32_t *v) { switch(tng_data->endianness_32) @@ -463,7 +471,7 @@ static inline tng_function_status tng_byte_order_to_little_endian_32 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if the current * byte order is not recognised. */ -static inline tng_function_status tng_byte_order_to_little_endian_64 +static tng_function_status tng_swap_byte_order_little_endian_64 (const tng_trajectory_t tng_data, int64_t *v) { switch(tng_data->endianness_64) @@ -739,11 +747,71 @@ static tng_function_status tng_block_header_read return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, - &block->header_contents_size) != TNG_SUCCESS) + /* If this was the size of the general info block check the endianness */ + if(ftell(tng_data->input_file) < 9) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + /* File is little endian */ + if ( *(const uint8_t*)&block->header_contents_size != 0x00 && + *(const uint8_t*)(&block->header_contents_size + 7) == 0x00) + { + /* If the architecture endianness is little endian no byte swap + * will be needed. Otherwise use the functions to swap to little + * endian */ + if(tng_data->endianness_32 == TNG_LITTLE_ENDIAN_32) + { + tng_data->input_endianness_swap_func_32 = 0; + } + else + { + tng_data->input_endianness_swap_func_32 = + &tng_swap_byte_order_little_endian_32; + } + if(tng_data->endianness_64 == TNG_LITTLE_ENDIAN_64) + { + tng_data->input_endianness_swap_func_64 = 0; + } + else + { + tng_data->input_endianness_swap_func_64 = + &tng_swap_byte_order_little_endian_64; + } + } + /* File is big endian */ + else + { + /* If the architecture endianness is big endian no byte swap + * will be needed. Otherwise use the functions to swap to big + * endian */ + if(tng_data->endianness_32 == TNG_BIG_ENDIAN_32) + { + tng_data->input_endianness_swap_func_32 = 0; + } + else + { + tng_data->input_endianness_swap_func_32 = + &tng_swap_byte_order_big_endian_32; + } + if(tng_data->endianness_64 == TNG_BIG_ENDIAN_64) + { + tng_data->input_endianness_swap_func_64 = 0; + } + else + { + tng_data->input_endianness_swap_func_64 = + &tng_swap_byte_order_big_endian_64; + } + } + } + + if(tng_data->input_endianness_swap_func_64) + { + if(tng_data->input_endianness_swap_func_64(tng_data, + &block->header_contents_size) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } /* Move the reading position to the beginning of the header. */ @@ -782,20 +850,31 @@ static tng_function_status tng_block_header_read /* Copy the respective parameters from the header contents block */ memcpy(&block->block_contents_size, block->header_contents+offset, sizeof(block->block_contents_size)); - if(tng_byte_order_to_big_endian_64(tng_data, &block->block_contents_size) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &block->block_contents_size) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } + offset += sizeof(block->block_contents_size); memcpy(&block->id, block->header_contents+offset, sizeof(block->id)); - if(tng_byte_order_to_big_endian_64(tng_data, &block->id) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &block->id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } + offset += sizeof(block->id); memcpy(block->hash, block->header_contents+offset, TNG_HASH_LEN); @@ -822,11 +901,15 @@ static tng_function_status tng_block_header_read memcpy(&block->block_version, block->header_contents+offset, sizeof(block->block_version)); - if(tng_byte_order_to_big_endian_64(tng_data, &block->block_version) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &block->block_version) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(block->block_version); @@ -938,33 +1021,42 @@ static tng_function_status tng_block_header_write * the whole block at once. */ memcpy(block->header_contents, &block->header_contents_size, sizeof(block->header_contents_size)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->header_contents)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(block->header_contents_size); memcpy(block->header_contents+offset, &block->block_contents_size, sizeof(block->block_contents_size)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->header_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(block->block_contents_size); memcpy(block->header_contents+offset, &block->id, sizeof(block->id)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->header_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(block->id); @@ -976,12 +1068,15 @@ static tng_function_status tng_block_header_write memcpy(block->header_contents+offset, &block->block_version, sizeof(block->block_version)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->header_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(block->block_version); @@ -1171,10 +1266,15 @@ static tng_function_status tng_general_info_block_read memcpy(&tng_data->time, block->block_contents+offset, sizeof(tng_data->time)); - if(tng_byte_order_to_big_endian_64(tng_data, &tng_data->time) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->time) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->time); @@ -1184,25 +1284,33 @@ static tng_function_status tng_general_info_block_read memcpy(&tng_data->frame_set_n_frames, block->block_contents+offset, sizeof(tng_data->frame_set_n_frames)); - if(tng_byte_order_to_big_endian_64(tng_data, &tng_data->frame_set_n_frames) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->frame_set_n_frames) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->frame_set_n_frames); memcpy(&tng_data->first_trajectory_frame_set_input_file_pos, block->block_contents+offset, sizeof(tng_data->first_trajectory_frame_set_input_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, - &tng_data->first_trajectory_frame_set_input_file_pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->first_trajectory_frame_set_input_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->first_trajectory_frame_set_input_file_pos); + tng_data->current_trajectory_frame_set.next_frame_set_file_pos = tng_data->first_trajectory_frame_set_input_file_pos; @@ -1210,32 +1318,43 @@ static tng_function_status tng_general_info_block_read memcpy(&tng_data->last_trajectory_frame_set_input_file_pos, block->block_contents+offset, sizeof(tng_data->last_trajectory_frame_set_input_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, - &tng_data->last_trajectory_frame_set_input_file_pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->last_trajectory_frame_set_input_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->last_trajectory_frame_set_input_file_pos); memcpy(&tng_data->medium_stride_length, block->block_contents+offset, sizeof(tng_data->medium_stride_length)); - if(tng_byte_order_to_big_endian_64(tng_data, &tng_data->medium_stride_length) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->medium_stride_length) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->medium_stride_length); memcpy(&tng_data->long_stride_length, block->block_contents+offset, sizeof(tng_data->long_stride_length)); - if(tng_byte_order_to_big_endian_64(tng_data, &tng_data->long_stride_length) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->long_stride_length) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } return(TNG_SUCCESS); @@ -1466,12 +1585,15 @@ static tng_function_status tng_general_info_block_write memcpy(block->block_contents+offset, &tng_data->time, sizeof(tng_data->time)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->time); @@ -1481,58 +1603,73 @@ static tng_function_status tng_general_info_block_write memcpy(block->block_contents+offset, &tng_data->frame_set_n_frames, sizeof(tng_data->frame_set_n_frames)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->frame_set_n_frames); memcpy(block->block_contents+offset, &tng_data->first_trajectory_frame_set_input_file_pos, sizeof(tng_data->first_trajectory_frame_set_input_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->first_trajectory_frame_set_input_file_pos); memcpy(block->block_contents+offset, &tng_data->last_trajectory_frame_set_input_file_pos, sizeof(tng_data->last_trajectory_frame_set_input_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->last_trajectory_frame_set_input_file_pos); memcpy(block->block_contents+offset, &tng_data->medium_stride_length, sizeof(tng_data->medium_stride_length)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->medium_stride_length); memcpy(block->block_contents+offset, &tng_data->long_stride_length, sizeof(tng_data->long_stride_length)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(tng_block_header_write(tng_data, block, hash_mode) != TNG_SUCCESS) @@ -1631,11 +1768,15 @@ static tng_function_status tng_molecules_block_read memcpy(&tng_data->n_molecules, block->block_contents, sizeof(tng_data->n_molecules)); - if(tng_byte_order_to_big_endian_64(tng_data, &tng_data->n_molecules) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->n_molecules) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->n_molecules); @@ -1680,10 +1821,15 @@ static tng_function_status tng_molecules_block_read memcpy(&molecule->id, block->block_contents+offset, sizeof(molecule->id)); - if(tng_byte_order_to_big_endian_64(tng_data, &molecule->id) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &molecule->id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->id); @@ -1695,10 +1841,15 @@ static tng_function_status tng_molecules_block_read memcpy(&molecule->quaternary_str, block->block_contents+offset, sizeof(molecule->quaternary_str)); - if(tng_byte_order_to_big_endian_64(tng_data, &molecule->quaternary_str) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &molecule->quaternary_str) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->quaternary_str); @@ -1707,11 +1858,15 @@ static tng_function_status tng_molecules_block_read memcpy(&tng_data->molecule_cnt_list[i], block->block_contents+offset, sizeof(int64_t)); - if(tng_byte_order_to_big_endian_64(tng_data, - &tng_data->molecule_cnt_list[i]) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->molecule_cnt_list[i]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(int64_t); } @@ -1719,31 +1874,43 @@ static tng_function_status tng_molecules_block_read memcpy(&molecule->n_chains, block->block_contents+offset, sizeof(molecule->n_chains)); - if(tng_byte_order_to_big_endian_64(tng_data, &molecule->n_chains) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &molecule->n_chains) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->n_chains); memcpy(&molecule->n_residues, block->block_contents+offset, sizeof(molecule->n_residues)); - if(tng_byte_order_to_big_endian_64(tng_data, &molecule->n_residues) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &molecule->n_residues) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->n_residues); memcpy(&molecule->n_atoms, block->block_contents+offset, sizeof(molecule->n_atoms)); - if(tng_byte_order_to_big_endian_64(tng_data, &molecule->n_atoms) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &molecule->n_atoms) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->n_atoms); @@ -1793,10 +1960,15 @@ static tng_function_status tng_molecules_block_read memcpy(&chain->id, block->block_contents+offset, sizeof(chain->id)); - if(tng_byte_order_to_big_endian_64(tng_data, &chain->id) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &chain->id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(chain->id); @@ -1809,12 +1981,16 @@ static tng_function_status tng_molecules_block_read memcpy(&chain->n_residues, block->block_contents+offset, sizeof(chain->n_residues)); - if(tng_byte_order_to_big_endian_64(tng_data, &chain->n_residues) + if(tng_data->input_endianness_swap_func_64) + { + if(tng_data->input_endianness_swap_func_64(tng_data, + &chain->n_residues) != TNG_SUCCESS) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); } + } offset += sizeof(chain->n_residues); chain->residues = residue; @@ -1824,10 +2000,15 @@ static tng_function_status tng_molecules_block_read residue->chain = chain; memcpy(&residue->id, block->block_contents+offset, sizeof(residue->id)); - if(tng_byte_order_to_big_endian_64(tng_data, &residue->id) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &residue->id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(residue->id); @@ -1839,12 +2020,16 @@ static tng_function_status tng_molecules_block_read offset += len; memcpy(&residue->n_atoms, block->block_contents+offset, - sizeof(residue->n_atoms)); - if(tng_byte_order_to_big_endian_64(tng_data, &residue->n_atoms) - != TNG_SUCCESS) + sizeof(residue->n_atoms)); + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &residue->n_atoms) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(residue->n_atoms); @@ -1856,10 +2041,15 @@ static tng_function_status tng_molecules_block_read memcpy(&atom->id, block->block_contents+offset, sizeof(atom->id)); - if(tng_byte_order_to_big_endian_64(tng_data, &atom->id) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &atom->id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(atom->id); @@ -1886,11 +2076,15 @@ static tng_function_status tng_molecules_block_read memcpy(&molecule->n_bonds, block->block_contents+offset, sizeof(molecule->n_bonds)); - if(tng_byte_order_to_big_endian_64(tng_data, &molecule->n_bonds) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &molecule->n_bonds) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->n_bonds); @@ -1910,21 +2104,29 @@ static tng_function_status tng_molecules_block_read { memcpy(&bond->from_atom_id, block->block_contents+offset, sizeof(bond->from_atom_id)); - if(tng_byte_order_to_big_endian_64(tng_data, &bond->from_atom_id) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &bond->from_atom_id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(bond->from_atom_id); memcpy(&bond->to_atom_id, block->block_contents+offset, sizeof(bond->to_atom_id)); - if(tng_byte_order_to_big_endian_64(tng_data, &bond->to_atom_id) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &bond->to_atom_id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(bond->to_atom_id); @@ -2105,12 +2307,15 @@ static tng_function_status tng_molecules_block_write memcpy(block->block_contents+offset, &tng_data->n_molecules, sizeof(tng_data->n_molecules)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(tng_data->n_molecules); @@ -2120,12 +2325,15 @@ static tng_function_status tng_molecules_block_write // printf("i=%d\n", i); memcpy(block->block_contents+offset, &molecule->id, sizeof(molecule->id)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->id); @@ -2136,12 +2344,15 @@ static tng_function_status tng_molecules_block_write memcpy(block->block_contents+offset, &molecule->quaternary_str, sizeof(molecule->quaternary_str)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->quaternary_str); @@ -2149,46 +2360,58 @@ static tng_function_status tng_molecules_block_write { memcpy(block->block_contents+offset, &tng_data->molecule_cnt_list[i], sizeof(int64_t)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(int64_t); } memcpy(block->block_contents+offset, &molecule->n_chains, sizeof(molecule->n_chains)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->n_chains); memcpy(block->block_contents+offset, &molecule->n_residues, sizeof(molecule->n_residues)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->n_residues); memcpy(block->block_contents+offset, &molecule->n_atoms, sizeof(molecule->n_atoms)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->n_atoms); @@ -2196,12 +2419,15 @@ static tng_function_status tng_molecules_block_write for(j = molecule->n_chains; j--;) { memcpy(block->block_contents+offset, &chain->id, sizeof(chain->id)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(chain->id); @@ -2211,12 +2437,15 @@ static tng_function_status tng_molecules_block_write memcpy(block->block_contents+offset, &chain->n_residues, sizeof(chain->n_residues)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(chain->n_residues); @@ -2224,12 +2453,15 @@ static tng_function_status tng_molecules_block_write for(k = chain->n_residues; k--;) { memcpy(block->block_contents+offset, &residue->id, sizeof(residue->id)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(residue->id); @@ -2239,12 +2471,15 @@ static tng_function_status tng_molecules_block_write memcpy(block->block_contents+offset, &residue->n_atoms, sizeof(residue->n_atoms)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(residue->n_atoms); @@ -2252,13 +2487,17 @@ static tng_function_status tng_molecules_block_write for(l = residue->n_atoms; l--;) { // printf("j=%d\n", j); - memcpy(block->block_contents+offset, &atom->id, sizeof(atom->id)); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)) - != TNG_SUCCESS) + memcpy(block->block_contents+offset, &atom->id, + sizeof(atom->id)); + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(atom->id); @@ -2279,12 +2518,15 @@ static tng_function_status tng_molecules_block_write memcpy(block->block_contents+offset, &molecule->n_bonds, sizeof(molecule->n_bonds)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(molecule->n_bonds); @@ -2293,22 +2535,29 @@ static tng_function_status tng_molecules_block_write { memcpy(block->block_contents+offset, &bond->from_atom_id, sizeof(bond->from_atom_id)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(bond->from_atom_id); memcpy(block->block_contents+offset, &bond->to_atom_id, sizeof(bond->to_atom_id)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(bond->to_atom_id); @@ -2435,21 +2684,29 @@ static tng_function_status tng_frame_set_block_read memcpy(&frame_set->first_frame, block->block_contents, sizeof(frame_set->first_frame)); - if(tng_byte_order_to_big_endian_64(tng_data, &frame_set->first_frame) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->first_frame) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->first_frame); memcpy(&frame_set->n_frames, block->block_contents + offset, sizeof(frame_set->n_frames)); - if(tng_byte_order_to_big_endian_64(tng_data, &frame_set->n_frames) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->n_frames) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->n_frames); @@ -2477,12 +2734,15 @@ static tng_function_status tng_frame_set_block_read memcpy(&frame_set->molecule_cnt_list[i], block->block_contents + offset, sizeof(int64_t)); - if(tng_byte_order_to_big_endian_64(tng_data, - &frame_set->molecule_cnt_list[i]) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->molecule_cnt_list[i]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(int64_t); frame_set->n_particles += tng_data->molecules[i].n_atoms * @@ -2497,72 +2757,90 @@ static tng_function_status tng_frame_set_block_read memcpy(&frame_set->next_frame_set_file_pos, block->block_contents + offset, sizeof(frame_set->next_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, - &frame_set->next_frame_set_file_pos) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->next_frame_set_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->next_frame_set_file_pos); memcpy(&frame_set->prev_frame_set_file_pos, block->block_contents + offset, sizeof(frame_set->prev_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, - &frame_set->prev_frame_set_file_pos) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->prev_frame_set_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->prev_frame_set_file_pos); memcpy(&frame_set->medium_stride_next_frame_set_file_pos, block->block_contents + offset, sizeof(frame_set->medium_stride_next_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, &frame_set-> - medium_stride_next_frame_set_file_pos) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->medium_stride_next_frame_set_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->medium_stride_next_frame_set_file_pos); memcpy(&frame_set->medium_stride_prev_frame_set_file_pos, block->block_contents + offset, sizeof(frame_set->medium_stride_prev_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, &frame_set-> - medium_stride_prev_frame_set_file_pos) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->medium_stride_prev_frame_set_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->medium_stride_prev_frame_set_file_pos); memcpy(&frame_set->long_stride_next_frame_set_file_pos, block->block_contents + offset, sizeof(frame_set->long_stride_next_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, &frame_set-> - long_stride_next_frame_set_file_pos) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->long_stride_next_frame_set_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->long_stride_next_frame_set_file_pos); memcpy(&frame_set->long_stride_prev_frame_set_file_pos, block->block_contents + offset, sizeof(frame_set->long_stride_prev_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, &frame_set-> - long_stride_prev_frame_set_file_pos) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->long_stride_prev_frame_set_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->long_stride_prev_frame_set_file_pos); @@ -2630,23 +2908,29 @@ static tng_function_status tng_frame_set_block_write memcpy(block->block_contents, &frame_set->first_frame, sizeof(frame_set->first_frame)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->first_frame); memcpy(block->block_contents+offset, &frame_set->n_frames, sizeof(frame_set->n_frames)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->n_frames); @@ -2657,12 +2941,15 @@ static tng_function_status tng_frame_set_block_write memcpy(block->block_contents+offset, &frame_set->molecule_cnt_list[i], sizeof(int64_t)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(int64_t); } @@ -2671,71 +2958,89 @@ static tng_function_status tng_frame_set_block_write memcpy(block->block_contents+offset, &frame_set->next_frame_set_file_pos, sizeof(frame_set->next_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->next_frame_set_file_pos); memcpy(block->block_contents+offset, &frame_set->prev_frame_set_file_pos, sizeof(frame_set->prev_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->prev_frame_set_file_pos); memcpy(block->block_contents+offset, &frame_set->medium_stride_next_frame_set_file_pos, sizeof(frame_set->medium_stride_next_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->medium_stride_next_frame_set_file_pos); memcpy(block->block_contents+offset, &frame_set->medium_stride_prev_frame_set_file_pos, sizeof(frame_set->medium_stride_prev_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->medium_stride_prev_frame_set_file_pos); memcpy(block->block_contents+offset, &frame_set->long_stride_next_frame_set_file_pos, sizeof(frame_set->long_stride_next_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->long_stride_next_frame_set_file_pos); memcpy(block->block_contents+offset, &frame_set->long_stride_prev_frame_set_file_pos, sizeof(frame_set->long_stride_prev_frame_set_file_pos)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(frame_set->long_stride_prev_frame_set_file_pos); @@ -2839,21 +3144,29 @@ static tng_function_status tng_trajectory_mapping_block_read memcpy(&mapping->num_first_particle, block->block_contents+offset, sizeof(mapping->num_first_particle)); - if(tng_byte_order_to_big_endian_64(tng_data, &mapping->num_first_particle) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &mapping->num_first_particle) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(mapping->num_first_particle); memcpy(&mapping->n_particles, block->block_contents+offset, sizeof(mapping->n_particles)); - if(tng_byte_order_to_big_endian_64(tng_data, &mapping->n_particles) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &mapping->n_particles) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(mapping->n_particles); @@ -2866,20 +3179,32 @@ static tng_function_status tng_trajectory_mapping_block_read return(TNG_CRITICAL); } - for(i = 0; i < mapping->n_particles; i++) + /* If the byte order needs to be swapped the data must be read one value at + * a time and swapped */ + if(tng_data->input_endianness_swap_func_64) { - memcpy(&mapping->real_particle_numbers[i], - block->block_contents + offset, - sizeof(int64_t)); - if(tng_byte_order_to_big_endian_64(tng_data, - &mapping->real_particle_numbers[i]) != - TNG_SUCCESS) + for(i = 0; i < mapping->n_particles; i++) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + memcpy(&mapping->real_particle_numbers[i], + block->block_contents + offset, + sizeof(int64_t)); + if(tng_data->input_endianness_swap_func_64(tng_data, + &mapping->real_particle_numbers[i]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + offset += sizeof(int64_t); } - offset += sizeof(int64_t); } + /* Otherwise the data can be read all at once */ + else + { + memcpy(mapping->real_particle_numbers, block->block_contents + offset, + mapping->n_particles * sizeof(int64_t)); + } + return(TNG_SUCCESS); } @@ -2950,38 +3275,52 @@ static tng_function_status tng_trajectory_mapping_block_write memcpy(block->block_contents, &mapping->num_first_particle, sizeof(mapping->num_first_particle)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(mapping->num_first_particle); memcpy(block->block_contents+offset, &mapping->n_particles, sizeof(mapping->n_particles)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(mapping->n_particles); - for(i = 0; i < mapping->n_particles; i++) + if(tng_data->output_endianness_swap_func_64) { - memcpy(block->block_contents+offset, &mapping->real_particle_numbers[i], - sizeof(int64_t)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + for(i = 0; i < mapping->n_particles; i++) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + memcpy(block->block_contents+offset, &mapping->real_particle_numbers[i], + sizeof(int64_t)); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + offset += sizeof(int64_t); } - offset += sizeof(int64_t); + } + else + { + memcpy(block->block_contents+offset, mapping->real_particle_numbers, + mapping->n_particles * sizeof(int64_t)); } @@ -3310,6 +3649,8 @@ static tng_function_status tng_particle_data_read n_frames = max(1, n_frames / stride_length); + /* FIXME: If not using a union to store data a whole dimension + * or the whole block can be read at once if byte swapping is not needed */ switch(datatype) { case TNG_FLOAT_DATA: @@ -3323,14 +3664,17 @@ static tng_function_status tng_particle_data_read for(k = 0; k < n_values; k++) { memcpy(&second_dim_values[k].f, - block->block_contents+*offset, - size); - if(tng_byte_order_to_big_endian_32(tng_data, - (int32_t *) &second_dim_values[k]) != TNG_SUCCESS) + block->block_contents+*offset, + size); + if(tng_data->input_endianness_swap_func_32) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_32(tng_data, + (int32_t *)&second_dim_values[k]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } *offset += size; } @@ -3350,12 +3694,15 @@ static tng_function_status tng_particle_data_read memcpy(&second_dim_values[k].i, block->block_contents+*offset, size); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *) &second_dim_values[k].i) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + (int64_t *)&second_dim_values[k]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } *offset += size; } @@ -3406,12 +3753,15 @@ static tng_function_status tng_particle_data_read memcpy(&second_dim_values[k].d, block->block_contents+*offset, size); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *) &second_dim_values[k].d) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + (int64_t *)&second_dim_values[k]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } *offset += size; } @@ -3621,23 +3971,29 @@ static tng_function_status tng_particle_data_block_write memcpy(block->block_contents+offset, &data->n_values_per_frame, sizeof(data->n_values_per_frame)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->n_values_per_frame); memcpy(block->block_contents+offset, &data->codec_id, sizeof(data->codec_id)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->codec_id); @@ -3645,12 +4001,15 @@ static tng_function_status tng_particle_data_block_write { memcpy(block->block_contents+offset, &data->compression_multiplier, sizeof(data->compression_multiplier)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->compression_multiplier); } @@ -3662,23 +4021,29 @@ static tng_function_status tng_particle_data_block_write data->first_frame_with_data = frame_set->first_frame; memcpy(block->block_contents+offset, &data->first_frame_with_data, sizeof(data->first_frame_with_data)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->first_frame_with_data); memcpy(block->block_contents+offset, &stride_length, sizeof(stride_length)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(stride_length); } @@ -3686,26 +4051,34 @@ static tng_function_status tng_particle_data_block_write memcpy(block->block_contents+offset, &num_first_particle, sizeof(num_first_particle)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(num_first_particle); memcpy(block->block_contents+offset, &n_particles, sizeof(n_particles)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents+offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(n_particles); + /* FIXME: If not using a union to store data a whole dimension or the + * whole block can be written at once if byte swapping is not needed */ switch(data->datatype) { case TNG_FLOAT_DATA: @@ -3721,8 +4094,16 @@ static tng_function_status tng_particle_data_block_write memcpy(block->block_contents+offset, &second_dim_values[k].f, size); - tng_byte_order_to_big_endian_32(tng_data, - (int32_t *)(block->block_contents+offset)); + if(tng_data->output_endianness_swap_func_32) + { + if(tng_data->output_endianness_swap_func_32(tng_data, + (int32_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + } offset += size; } } @@ -3742,8 +4123,16 @@ static tng_function_status tng_particle_data_block_write memcpy(block->block_contents+offset, &second_dim_values[k].i, size); - tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)); + if(tng_data->output_endianness_swap_func_64) + { + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + } offset += size; } } @@ -3781,8 +4170,16 @@ static tng_function_status tng_particle_data_block_write memcpy(block->block_contents+offset, &second_dim_values[k].d, size); - tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)); + if(tng_data->output_endianness_swap_func_64) + { + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + } offset += size; } } @@ -4084,6 +4481,8 @@ static tng_function_status tng_data_read(tng_trajectory_t tng_data, n_frames = max(1, n_frames / stride_length); + /* FIXME: If not using a union to store data a whole dimension + * or the whole block can be read at once if byte swapping is not needed */ switch(datatype) { case TNG_FLOAT_DATA: @@ -4093,12 +4492,15 @@ static tng_function_status tng_data_read(tng_trajectory_t tng_data, { memcpy(&data->values[i][j].f, block->block_contents+*offset, size); - if(tng_byte_order_to_big_endian_32(tng_data, - (int32_t *) &data->values[i][j]) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_32) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_32(tng_data, + (int32_t *)&data->values[i][j]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } *offset += size; } @@ -4111,12 +4513,15 @@ static tng_function_status tng_data_read(tng_trajectory_t tng_data, { memcpy(&data->values[i][j].i, block->block_contents+*offset, size); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *) &data->values[i][j].i) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + (int64_t *)&data->values[i][j]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } *offset += size; } @@ -4154,12 +4559,15 @@ static tng_function_status tng_data_read(tng_trajectory_t tng_data, { memcpy(&data->values[i][j].d, block->block_contents+*offset, size); - if(tng_byte_order_to_big_endian_64(tng_data, - (int64_t *) &data->values[i][j].d) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + (int64_t *)&data->values[i][j]) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } *offset += size; } @@ -4337,25 +4745,29 @@ static tng_function_status tng_data_block_write(tng_trajectory_t tng_data, memcpy(block->block_contents+offset, &data->n_values_per_frame, sizeof(data->n_values_per_frame)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->n_values_per_frame); memcpy(block->block_contents+offset, &data->codec_id, sizeof(data->codec_id)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->codec_id); @@ -4363,13 +4775,15 @@ static tng_function_status tng_data_block_write(tng_trajectory_t tng_data, { memcpy(block->block_contents+offset, &data->compression_multiplier, sizeof(data->compression_multiplier)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->compression_multiplier); } @@ -4381,29 +4795,35 @@ static tng_function_status tng_data_block_write(tng_trajectory_t tng_data, data->first_frame_with_data = frame_set->first_frame; memcpy(block->block_contents+offset, &data->first_frame_with_data, sizeof(data->first_frame_with_data)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->first_frame_with_data); memcpy(block->block_contents+offset, &stride_length, sizeof(data->stride_length)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - (block->block_contents + offset)) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. " - "%s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(data->stride_length); } + /* FIXME: If not using a union to store data a whole dimension or the + * whole block can be written at once if byte swapping is not needed */ switch(data->datatype) { case TNG_FLOAT_DATA: @@ -4413,8 +4833,16 @@ static tng_function_status tng_data_block_write(tng_trajectory_t tng_data, { memcpy(block->block_contents+offset, &data->values[i][j].f, size); - tng_byte_order_to_big_endian_32(tng_data, - (int32_t *)(block->block_contents+offset)); + if(tng_data->output_endianness_swap_func_32) + { + if(tng_data->output_endianness_swap_func_32(tng_data, + (int32_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + } offset += size; } } @@ -4426,8 +4854,16 @@ static tng_function_status tng_data_block_write(tng_trajectory_t tng_data, { memcpy(block->block_contents+offset, &data->values[i][j].i, size); - tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)); + if(tng_data->output_endianness_swap_func_64) + { + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + } offset += size; } } @@ -4452,8 +4888,16 @@ static tng_function_status tng_data_block_write(tng_trajectory_t tng_data, { memcpy(block->block_contents+offset, &data->values[i][j].d, size); - tng_byte_order_to_big_endian_64(tng_data, - (int64_t *)(block->block_contents+offset)); + if(tng_data->output_endianness_swap_func_64) + { + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + } offset += size; } } @@ -4558,19 +5002,29 @@ static tng_function_status tng_data_block_contents_read memcpy(&n_values, block->block_contents+offset, sizeof(n_values)); - if(tng_byte_order_to_big_endian_64(tng_data, &n_values) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &n_values) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(n_values); memcpy(&codec_id, block->block_contents+offset, sizeof(codec_id)); - if(tng_byte_order_to_big_endian_64(tng_data, &codec_id) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &codec_id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(codec_id); @@ -4578,11 +5032,15 @@ static tng_function_status tng_data_block_contents_read { memcpy(&multiplier, block->block_contents+offset, sizeof(multiplier)); - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *)&multiplier) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + (int64_t *) &multiplier) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(multiplier); } @@ -4597,21 +5055,29 @@ static tng_function_status tng_data_block_contents_read { memcpy(&first_frame_with_data, block->block_contents+offset, sizeof(first_frame_with_data)); - if(tng_byte_order_to_big_endian_64(tng_data, &first_frame_with_data) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &first_frame_with_data) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(first_frame_with_data); memcpy(&stride_length, block->block_contents+offset, sizeof(stride_length)); - if(tng_byte_order_to_big_endian_64(tng_data, &stride_length) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &stride_length) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(stride_length); } @@ -4632,22 +5098,30 @@ static tng_function_status tng_data_block_contents_read if (dependency & TNG_PARTICLE_DEPENDENT) { memcpy(&num_first_particle, block->block_contents+offset, - sizeof(num_first_particle)); - if(tng_byte_order_to_big_endian_64(tng_data, &num_first_particle) != - TNG_SUCCESS) + sizeof(num_first_particle)); + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &num_first_particle) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(num_first_particle); memcpy(&block_n_particles, block->block_contents+offset, sizeof(block_n_particles)); - if(tng_byte_order_to_big_endian_64(tng_data, &block_n_particles) != - TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &block_n_particles) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } offset += sizeof(block_n_particles); } @@ -4758,10 +5232,15 @@ static tng_function_status tng_header_pointers_update pos = tng_data->first_trajectory_frame_set_output_file_pos; - if(tng_byte_order_to_big_endian_64(tng_data, &pos) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fwrite(&pos, sizeof(int64_t), 1, tng_data->output_file) != 1) @@ -4772,10 +5251,15 @@ static tng_function_status tng_header_pointers_update pos = tng_data->last_trajectory_frame_set_output_file_pos; - if(tng_byte_order_to_big_endian_64(tng_data, &pos) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fwrite(&pos, @@ -4852,10 +5336,15 @@ static tng_function_status tng_frame_set_pointers_update pos = tng_data->current_trajectory_frame_set_output_file_pos; - if(tng_byte_order_to_big_endian_64(tng_data, &pos) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fwrite(&pos, sizeof(int64_t), 1, tng_data->output_file) != 1) @@ -4898,10 +5387,15 @@ static tng_function_status tng_frame_set_pointers_update pos = tng_data->current_trajectory_frame_set_output_file_pos; - if(tng_byte_order_to_big_endian_64(tng_data, &pos) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fwrite(&pos, sizeof(int64_t), 1, tng_data->output_file) != 1) @@ -4943,10 +5437,15 @@ static tng_function_status tng_frame_set_pointers_update pos = tng_data->current_trajectory_frame_set_output_file_pos; - if(tng_byte_order_to_big_endian_64(tng_data, &pos) != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fwrite(&pos, sizeof(int64_t), 1, tng_data->output_file) != 1) @@ -6060,17 +6559,14 @@ tng_function_status tng_trajectory_init(tng_trajectory_t *tng_data_p) tng_data->endianness_64 = TNG_BYTE_SWAP_64; } - if(tng_data->endianness_32 == TNG_LITTLE_ENDIAN_32 || - tng_data->endianness_64 == TNG_LITTLE_ENDIAN_64) - { - tng_data->input_endianness = TNG_LITTLE_ENDIAN; - tng_data->output_endianness = TNG_LITTLE_ENDIAN; - } - else - { - tng_data->input_endianness = TNG_BIG_ENDIAN; - tng_data->output_endianness = TNG_BIG_ENDIAN; - } + /* By default do not swap the byte order, i.e. keep the byte order of the + * architecture. The input file endianness will be set when reading the + * header. The output endianness can be changed - before the file is + * written. */ + tng_data->input_endianness_swap_func_32 = 0; + tng_data->input_endianness_swap_func_64 = 0; + tng_data->output_endianness_swap_func_32 = 0; + tng_data->output_endianness_swap_func_64 = 0; tng_data->current_trajectory_frame_set.next_frame_set_file_pos = -1; tng_data->current_trajectory_frame_set.prev_frame_set_file_pos = -1; @@ -6421,8 +6917,10 @@ tng_function_status tng_trajectory_init_from_src(tng_trajectory_t src, dest->endianness_32 = src->endianness_32; dest->endianness_64 = src->endianness_64; - dest->input_endianness = src->input_endianness; - dest->output_endianness = src->output_endianness; + dest->input_endianness_swap_func_32 = src->input_endianness_swap_func_32; + dest->input_endianness_swap_func_64 = src->input_endianness_swap_func_64; + dest->output_endianness_swap_func_32 = src->output_endianness_swap_func_32; + dest->output_endianness_swap_func_64 = src->output_endianness_swap_func_64; dest->current_trajectory_frame_set.next_frame_set_file_pos = -1; dest->current_trajectory_frame_set.prev_frame_set_file_pos = -1; @@ -8258,13 +8756,15 @@ tng_function_status tng_frame_set_new(tng_trajectory_t tng_data, return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, - &frame_set-> - medium_stride_prev_frame_set_file_pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->medium_stride_prev_frame_set_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } tng_block_destroy(&block); @@ -8314,13 +8814,15 @@ tng_function_status tng_frame_set_new(tng_trajectory_t tng_data, return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, - &frame_set-> - long_stride_prev_frame_set_file_pos) - != TNG_SUCCESS) + if(tng_data->input_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->input_endianness_swap_func_64(tng_data, + &frame_set->long_stride_prev_frame_set_file_pos) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } } @@ -8955,10 +9457,15 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &data.n_values_per_frame) != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &data.n_values_per_frame) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fread(&data.codec_id, sizeof(data.codec_id), 1, @@ -8968,10 +9475,15 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &data.codec_id) != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &data.codec_id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(data.codec_id != TNG_UNCOMPRESSED) @@ -8984,12 +9496,15 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - &data.compression_multiplier) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)&data.compression_multiplier) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } } else @@ -9006,11 +9521,15 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &data.first_frame_with_data) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &data.first_frame_with_data) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fread(&data.stride_length, sizeof(data.stride_length), @@ -9020,11 +9539,15 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &data.stride_length) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &data.stride_length) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } } else @@ -9078,26 +9601,38 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, /* 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->endianness_64 != TNG_BIG_ENDIAN_64) + tng_data->output_endianness_swap_func_64) { copy = malloc(n_values_per_frame * size); memcpy(copy, values, n_values_per_frame * size); for(i = 0; i < n_values_per_frame; i++) { - tng_byte_order_to_big_endian_64(tng_data, (int64_t *)copy+i); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)copy+i) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } fwrite(copy, n_values_per_frame, size, tng_data->output_file); free(copy); } else if(data.datatype == TNG_FLOAT_DATA && - tng_data->endianness_32 != TNG_BIG_ENDIAN_32) + tng_data->output_endianness_swap_func_32) { copy = malloc(n_values_per_frame * size); memcpy(copy, values, n_values_per_frame * size); for(i = 0; i < n_values_per_frame; i++) { - tng_byte_order_to_big_endian_32(tng_data, (int32_t *)copy+i); + if(tng_data->output_endianness_swap_func_32(tng_data, + (int32_t *)copy+i) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } fwrite(copy, n_values_per_frame, size, tng_data->output_file); @@ -9401,11 +9936,15 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &data.n_values_per_frame) - != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &data.n_values_per_frame) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fread(&data.codec_id, sizeof(data.codec_id), 1, @@ -9415,10 +9954,15 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &data.codec_id) != TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &data.codec_id) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(data.codec_id != TNG_UNCOMPRESSED) @@ -9432,12 +9976,15 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, (int64_t *) - &data.compression_multiplier) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)&data.compression_multiplier) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } } else @@ -9455,11 +10002,15 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &data.first_frame_with_data) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &data.first_frame_with_data) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fread(&data.stride_length, sizeof(data.stride_length), @@ -9469,11 +10020,15 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &data.stride_length) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &data.stride_length) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } } else @@ -9490,11 +10045,15 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &num_first_particle) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &num_first_particle) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } if(fread(&block_n_particles, sizeof(block_n_particles), 1, @@ -9504,11 +10063,15 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, tng_block_destroy(&block); return(TNG_CRITICAL); } - if(tng_byte_order_to_big_endian_64(tng_data, &block_n_particles) != - TNG_SUCCESS) + if(tng_data->output_endianness_swap_func_64) { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); + if(tng_data->output_endianness_swap_func_64(tng_data, + &block_n_particles) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } @@ -9557,26 +10120,38 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, /* 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->endianness_64 != TNG_BIG_ENDIAN_64) + tng_data->output_endianness_swap_func_64) { copy = malloc(val_n_particles * n_values_per_frame * size); memcpy(copy, values, val_n_particles * n_values_per_frame * size); for(i = 0; i < val_n_particles * n_values_per_frame; i++) { - tng_byte_order_to_big_endian_64(tng_data, (int64_t *)copy+i); + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *) copy+i) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } fwrite(copy, val_n_particles * n_values_per_frame, size, tng_data->output_file); free(copy); } else if(data.datatype == TNG_FLOAT_DATA && - tng_data->endianness_32 != TNG_BIG_ENDIAN_32) + tng_data->output_endianness_swap_func_32) { copy = malloc(val_n_particles * n_values_per_frame * size); memcpy(copy, values, val_n_particles * n_values_per_frame * size); for(i = 0; i < val_n_particles * n_values_per_frame; i++) { - tng_byte_order_to_big_endian_32(tng_data, (int32_t *)copy+i); + if(tng_data->output_endianness_swap_func_32(tng_data, + (int32_t *) copy+i) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } } fwrite(copy, val_n_particles * n_values_per_frame, size, tng_data->output_file); diff --git a/src/lib/tng_io.h b/src/lib/tng_io.h index b2d07ff..9fa13b2 100644 --- a/src/lib/tng_io.h +++ b/src/lib/tng_io.h @@ -228,7 +228,7 @@ #include <inttypes.h> /** The version of this TNG build */ -#define TNG_VERSION 1 +#define TNG_VERSION 2 /** Flag to indicate frame dependent data. */ #define TNG_FRAME_DEPENDENT 1 |