diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2012-12-12 10:58:25 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2012-12-12 10:59:56 (GMT) |
commit | 6ba2a6ef831b4c210b7e62a89eccb7f6a423bdc3 (patch) | |
tree | ab87c26a00c6923054bdaa5d961e42710a377d9e | |
parent | efaa82d1c92452665af79835325092591604d9ec (diff) |
first and last program name, user name, computer name and signature in general block according to specs.
-rw-r--r-- | example_files/tng_example.tng | bin | 2617 -> 2621 bytes | |||
-rw-r--r-- | src/lib/tng_io.c | 557 | ||||
-rw-r--r-- | src/lib/tng_io.h | 110 |
3 files changed, 490 insertions, 177 deletions
diff --git a/example_files/tng_example.tng b/example_files/tng_example.tng Binary files differindex 4716443..10e9679 100644 --- a/example_files/tng_example.tng +++ b/example_files/tng_example.tng diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 9a707a2..f195551 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -565,75 +565,121 @@ static tng_function_status tng_read_general_info_block } len = min(strlen(block->block_contents) + 1, TNG_MAX_STR_LEN); - tng_data->program_name = (char *) malloc(len); - if(!tng_data->program_name) + tng_data->first_program_name = (char *) malloc(len); + if(!tng_data->first_program_name) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); tng_block_destroy(block); return(TNG_CRITICAL); } - strncpy(tng_data->program_name, block->block_contents, len); + strncpy(tng_data->first_program_name, block->block_contents, len); offset += len; + len = min(strlen(block->block_contents) + 1, TNG_MAX_STR_LEN); + tng_data->last_program_name = (char *) malloc(len); + if(!tng_data->last_program_name) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", len, + __FILE__, __LINE__); + tng_block_destroy(block); + return(TNG_CRITICAL); + } + strncpy(tng_data->last_program_name, block->block_contents, len); + offset += len; + len = min(strlen(block->block_contents+offset) + 1, TNG_MAX_STR_LEN); - tng_data->forcefield_name = (char *) malloc(len); - if(!tng_data->forcefield_name) + tng_data->first_user_name = (char *) malloc(len); + if(!tng_data->first_user_name) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); tng_block_destroy(block); return(TNG_CRITICAL); } - strncpy(tng_data->forcefield_name, block->block_contents+offset, len); + strncpy(tng_data->first_user_name, block->block_contents+offset, len); offset += len; len = min(strlen(block->block_contents+offset) + 1, TNG_MAX_STR_LEN); - tng_data->user_name = (char *) malloc(len); - if(!tng_data->user_name) + tng_data->last_user_name = (char *) malloc(len); + if(!tng_data->last_user_name) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); tng_block_destroy(block); return(TNG_CRITICAL); } - strncpy(tng_data->user_name, block->block_contents+offset, len); + strncpy(tng_data->last_user_name, block->block_contents+offset, len); offset += len; - - memcpy(&tng_data->time, block->block_contents+offset, - sizeof(tng_data->time)); - if(tng_data->endianness_64 != TNG_BIG_ENDIAN_64) + + len = min(strlen(block->block_contents+offset) + 1, TNG_MAX_STR_LEN); + tng_data->first_computer_name = (char *) malloc(len); + if(!tng_data->first_computer_name) { - if(tng_swap_byte_order_64(tng_data, &tng_data->time) != TNG_SUCCESS) - { - printf("Cannot swap byte order to get big endian. %s: %d\n", - __FILE__, __LINE__); - } + printf("Cannot allocate memory (%d bytes). %s: %d\n", len, + __FILE__, __LINE__); + return(TNG_CRITICAL); } - offset += sizeof(tng_data->time); + strncpy(tng_data->first_computer_name, block->block_contents+offset, len); + offset += len; + + len = min(strlen(block->block_contents+offset) + 1, TNG_MAX_STR_LEN); + tng_data->last_computer_name = (char *) malloc(len); + if(!tng_data->last_computer_name) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", len, + __FILE__, __LINE__); + return(TNG_CRITICAL); + } + strncpy(tng_data->last_computer_name, block->block_contents+offset, len); + offset += len; len = min(strlen(block->block_contents+offset) + 1, TNG_MAX_STR_LEN); - tng_data->computer_name = (char *) malloc(len); - if(!tng_data->computer_name) + tng_data->first_pgp_signature = (char *) malloc(len); + if(!tng_data->first_pgp_signature) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); return(TNG_CRITICAL); } - strncpy(tng_data->computer_name, block->block_contents+offset, len); + strncpy(tng_data->first_pgp_signature, block->block_contents+offset, len); offset += len; len = min(strlen(block->block_contents+offset) + 1, TNG_MAX_STR_LEN); - tng_data->pgp_signature = (char *) malloc(len); - if(!tng_data->pgp_signature) + tng_data->last_pgp_signature = (char *) malloc(len); + if(!tng_data->last_pgp_signature) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); return(TNG_CRITICAL); } - strncpy(tng_data->pgp_signature, block->block_contents+offset, len); + strncpy(tng_data->last_pgp_signature, block->block_contents+offset, len); offset += len; + len = min(strlen(block->block_contents+offset) + 1, TNG_MAX_STR_LEN); + tng_data->forcefield_name = (char *) malloc(len); + if(!tng_data->forcefield_name) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", len, + __FILE__, __LINE__); + tng_block_destroy(block); + return(TNG_CRITICAL); + } + strncpy(tng_data->forcefield_name, block->block_contents+offset, len); + offset += len; + + memcpy(&tng_data->time, block->block_contents+offset, + sizeof(tng_data->time)); + if(tng_data->endianness_64 != TNG_BIG_ENDIAN_64) + { + if(tng_swap_byte_order_64(tng_data, &tng_data->time) != TNG_SUCCESS) + { + printf("Cannot swap byte order to get big endian. %s: %d\n", + __FILE__, __LINE__); + } + } + offset += sizeof(tng_data->time); + memcpy(&tng_data->var_num_atoms_flag, block->block_contents+offset, sizeof(tng_data->var_num_atoms_flag)); offset += sizeof(tng_data->var_num_atoms_flag); @@ -719,86 +765,147 @@ static tng_function_status tng_write_general_info_block const tng_write_mode mode, const tng_hash_mode hash_mode) { - int program_name_len, forcefield_name_len, user_name_len; - int computer_name_len, pgp_signature_len; + int first_program_name_len, first_user_name_len; + int first_computer_name_len, first_pgp_signature_len; + int last_program_name_len, last_user_name_len; + int last_computer_name_len, last_pgp_signature_len; + int forcefield_name_len; int offset = 0; if(tng_init_output_file(tng_data, FALSE) != TNG_SUCCESS) { return(TNG_CRITICAL); } - - if(!tng_data->program_name) + + /* If the strings are unallocated allocate memory for just string + * termination */ + if(!tng_data->first_program_name) { - tng_data->program_name = (char *) malloc(1); - if(!tng_data->program_name) + tng_data->first_program_name = (char *) malloc(1); + if(!tng_data->first_program_name) { printf("Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); tng_block_destroy(block); return(TNG_CRITICAL); } - tng_data->program_name[0] = 0; + tng_data->first_program_name[0] = 0; } - if(!tng_data->forcefield_name) + if(!tng_data->last_program_name) { - tng_data->forcefield_name = (char *) malloc(1); - if(!tng_data->forcefield_name) + tng_data->last_program_name = (char *) malloc(1); + if(!tng_data->last_program_name) { printf("Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); tng_block_destroy(block); return(TNG_CRITICAL); } - tng_data->forcefield_name[0] = 0; + tng_data->last_program_name[0] = 0; + } + if(!tng_data->first_user_name) + { + tng_data->first_user_name = (char *) malloc(1); + if(!tng_data->first_user_name) + { + printf("Cannot allocate memory (1 byte). %s: %d\n", + __FILE__, __LINE__); + tng_block_destroy(block); + return(TNG_CRITICAL); + } + tng_data->first_user_name[0] = 0; } - if(!tng_data->user_name) + if(!tng_data->last_user_name) { - tng_data->user_name = (char *) malloc(1); - if(!tng_data->user_name) + tng_data->last_user_name = (char *) malloc(1); + if(!tng_data->last_user_name) { printf("Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); tng_block_destroy(block); return(TNG_CRITICAL); } - tng_data->user_name[0] = 0; + tng_data->last_user_name[0] = 0; } - if(!tng_data->computer_name) + if(!tng_data->first_computer_name) { - tng_data->computer_name = (char *) malloc(1); - if(!tng_data->computer_name) + tng_data->first_computer_name = (char *) malloc(1); + if(!tng_data->first_computer_name) { printf("Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); tng_block_destroy(block); return(TNG_CRITICAL); } - tng_data->computer_name[0] = 0; + tng_data->first_computer_name[0] = 0; } - if(!tng_data->pgp_signature) + if(!tng_data->last_computer_name) { - tng_data->pgp_signature = (char *) malloc(1); - if(!tng_data->pgp_signature) + tng_data->last_computer_name = (char *) malloc(1); + if(!tng_data->last_computer_name) { printf("Cannot allocate memory (1 byte). %s: %d\n", __FILE__, __LINE__); tng_block_destroy(block); return(TNG_CRITICAL); } - tng_data->pgp_signature[0] = 0; + tng_data->last_computer_name[0] = 0; + } + if(!tng_data->first_pgp_signature) + { + tng_data->first_pgp_signature = (char *) malloc(1); + if(!tng_data->first_pgp_signature) + { + printf("Cannot allocate memory (1 byte). %s: %d\n", + __FILE__, __LINE__); + tng_block_destroy(block); + return(TNG_CRITICAL); + } + tng_data->first_pgp_signature[0] = 0; + } + if(!tng_data->last_pgp_signature) + { + tng_data->last_pgp_signature = (char *) malloc(1); + if(!tng_data->last_pgp_signature) + { + printf("Cannot allocate memory (1 byte). %s: %d\n", + __FILE__, __LINE__); + tng_block_destroy(block); + return(TNG_CRITICAL); + } + tng_data->last_pgp_signature[0] = 0; + } + if(!tng_data->forcefield_name) + { + tng_data->forcefield_name = (char *) malloc(1); + if(!tng_data->forcefield_name) + { + printf("Cannot allocate memory (1 byte). %s: %d\n", + __FILE__, __LINE__); + tng_block_destroy(block); + return(TNG_CRITICAL); + } + tng_data->forcefield_name[0] = 0; } - program_name_len = min(strlen(tng_data->program_name) + 1, + first_program_name_len = min(strlen(tng_data->first_program_name) + 1, TNG_MAX_STR_LEN); - forcefield_name_len = min(strlen(tng_data->forcefield_name) + 1, - TNG_MAX_STR_LEN); - user_name_len = min(strlen(tng_data->user_name) + 1, + last_program_name_len = min(strlen(tng_data->last_program_name) + 1, + TNG_MAX_STR_LEN); + first_user_name_len = min(strlen(tng_data->first_user_name) + 1, TNG_MAX_STR_LEN); - computer_name_len = min(strlen(tng_data->computer_name) + 1, + last_user_name_len = min(strlen(tng_data->last_user_name) + 1, + TNG_MAX_STR_LEN); + first_computer_name_len = min(strlen(tng_data->first_computer_name) + 1, + TNG_MAX_STR_LEN); + last_computer_name_len = min(strlen(tng_data->last_computer_name) + 1, + TNG_MAX_STR_LEN); + first_pgp_signature_len = min(strlen(tng_data->first_pgp_signature) + 1, TNG_MAX_STR_LEN); - pgp_signature_len = min(strlen(tng_data->pgp_signature) + 1, + last_pgp_signature_len = min(strlen(tng_data->last_pgp_signature) + 1, TNG_MAX_STR_LEN); + forcefield_name_len = min(strlen(tng_data->forcefield_name) + 1, + TNG_MAX_STR_LEN); /* If just dumping the whole block_contents it is not certain that the * contents are known beforehand (e.g. due to different file versions) */ @@ -835,11 +942,15 @@ static tng_function_status tng_write_general_info_block sizeof(tng_data->last_trajectory_frame_set_input_file_pos) + sizeof(tng_data->medium_stride_length) + sizeof(tng_data->long_stride_length) + - program_name_len + - forcefield_name_len + - user_name_len + - computer_name_len + - pgp_signature_len; + first_program_name_len + + last_program_name_len + + first_user_name_len + + last_user_name_len + + first_computer_name_len + + last_computer_name_len + + first_pgp_signature_len + + last_pgp_signature_len + + forcefield_name_len; if(block->block_contents) { @@ -854,16 +965,38 @@ static tng_function_status tng_write_general_info_block return(TNG_CRITICAL); } - strncpy(block->block_contents, tng_data->program_name, program_name_len); - offset += program_name_len; + strncpy(block->block_contents, tng_data->first_program_name, first_program_name_len); + offset += first_program_name_len; + + strncpy(block->block_contents, tng_data->last_program_name, last_program_name_len); + offset += last_program_name_len; + + strncpy(block->block_contents+offset, tng_data->first_user_name, first_user_name_len); + offset += first_user_name_len; + + strncpy(block->block_contents+offset, tng_data->last_user_name, last_user_name_len); + offset += last_user_name_len; + + strncpy(block->block_contents+offset, tng_data->first_computer_name, + first_computer_name_len); + offset += first_computer_name_len; + + strncpy(block->block_contents+offset, tng_data->last_computer_name, + last_computer_name_len); + offset += last_computer_name_len; + + strncpy(block->block_contents+offset, tng_data->first_pgp_signature, + first_pgp_signature_len); + offset += first_pgp_signature_len; + + strncpy(block->block_contents+offset, tng_data->last_pgp_signature, + last_pgp_signature_len); + offset += last_pgp_signature_len; strncpy(block->block_contents+offset, tng_data->forcefield_name, forcefield_name_len); offset += forcefield_name_len; - strncpy(block->block_contents+offset, tng_data->user_name, user_name_len); - offset += user_name_len; - memcpy(block->block_contents+offset, &tng_data->time, sizeof(tng_data->time)); if(tng_data->endianness_64 != TNG_BIG_ENDIAN_64) @@ -878,14 +1011,6 @@ static tng_function_status tng_write_general_info_block } offset += sizeof(tng_data->time); - strncpy(block->block_contents+offset, tng_data->computer_name, - computer_name_len); - offset += computer_name_len; - - strncpy(block->block_contents+offset, tng_data->pgp_signature, - pgp_signature_len); - offset += pgp_signature_len; - memcpy(block->block_contents+offset, &tng_data->var_num_atoms_flag, sizeof(tng_data->var_num_atoms_flag)); offset += sizeof(tng_data->var_num_atoms_flag); @@ -5380,19 +5505,16 @@ tng_function_status tng_trajectory_init(tng_trajectory_t tng_data) tng_data->output_file = 0; tng_data->output_file_pos = 0; - tng_data->program_name = 0; + tng_data->first_program_name = 0; + tng_data->first_user_name = 0; + tng_data->first_computer_name = 0; + tng_data->first_pgp_signature = 0; + tng_data->last_program_name = 0; + tng_data->last_user_name = 0; + tng_data->last_computer_name = 0; + tng_data->last_pgp_signature = 0; tng_data->forcefield_name = 0; - /* FIXME: No unistd.h on Windows!! */ -// tng_data->user_name = (char *) malloc(LOGIN_NAME_MAX); -// if(getlogin_r(tng_data->user_name, LOGIN_NAME_MAX) != 0) -// { -// printf("Cannot get user name. %s: %d\n", __FILE__, __LINE__); -// free(tng_data->user_name); -// tng_data->user_name = 0; -// } - tng_data->user_name = 0; - seconds = time(0); if ( seconds == -1) { @@ -5402,19 +5524,7 @@ tng_function_status tng_trajectory_init(tng_trajectory_t tng_data) { tng_data->time = seconds; } - - /* FIXME: No unistd.h on Windows!! */ - /* FIXME: Append operating system to computer_name */ -// tng_data->computer_name = (char *) malloc(HOST_NAME_MAX); -// if(gethostname(tng_data->computer_name, HOST_NAME_MAX) != 0) -// { -// printf("Cannot get computer name. %s: %d\n", __FILE__, __LINE__); -// free(tng_data->computer_name); -// tng_data->computer_name = 0; -// } - tng_data->computer_name = 0; - tng_data->pgp_signature = 0; tng_data->var_num_atoms_flag = TNG_CONSTANT_N_ATOMS; tng_data->first_trajectory_frame_set_input_file_pos = -1; tng_data->last_trajectory_frame_set_input_file_pos = -1; @@ -5445,6 +5555,13 @@ tng_function_status tng_trajectory_init(tng_trajectory_t tng_data) frame_set->tr_particle_data = 0; frame_set->tr_data = 0; + + frame_set->next_frame_set_file_pos = -1; + frame_set->prev_frame_set_file_pos = -1; + frame_set->medium_stride_next_frame_set_file_pos = -1; + frame_set->medium_stride_prev_frame_set_file_pos = -1; + frame_set->long_stride_next_frame_set_file_pos = -1; + frame_set->long_stride_prev_frame_set_file_pos = -1; tng_data->n_molecules = 0; tng_data->molecules = 0; @@ -5553,34 +5670,58 @@ tng_function_status tng_trajectory_destroy(tng_trajectory_t tng_data) tng_data->output_file = 0; } - if(tng_data->program_name) + if(tng_data->first_program_name) { - free(tng_data->program_name); - tng_data->program_name = 0; + free(tng_data->first_program_name); + tng_data->first_program_name = 0; } - if(tng_data->forcefield_name) + if(tng_data->last_program_name) { - free(tng_data->forcefield_name); - tng_data->forcefield_name = 0; + free(tng_data->last_program_name); + tng_data->last_program_name = 0; } - - if(tng_data->user_name) + + if(tng_data->first_user_name) { - free(tng_data->user_name); - tng_data->user_name = 0; + free(tng_data->first_user_name); + tng_data->first_user_name = 0; } - if(tng_data->computer_name) + if(tng_data->last_user_name) + { + free(tng_data->last_user_name); + tng_data->last_user_name = 0; + } + + if(tng_data->first_computer_name) { - free(tng_data->computer_name); - tng_data->computer_name = 0; + free(tng_data->first_computer_name); + tng_data->first_computer_name = 0; } - if(tng_data->pgp_signature) + if(tng_data->last_computer_name) { - free(tng_data->pgp_signature); - tng_data->pgp_signature = 0; + free(tng_data->last_computer_name); + tng_data->last_computer_name = 0; + } + + if(tng_data->first_pgp_signature) + { + free(tng_data->first_pgp_signature); + tng_data->first_pgp_signature = 0; + } + + if(tng_data->last_pgp_signature) + { + free(tng_data->last_pgp_signature); + tng_data->last_pgp_signature = 0; + } + + if(tng_data->forcefield_name) + { + free(tng_data->forcefield_name); + tng_data->forcefield_name = 0; } if(frame_set->contents.block_names) @@ -5803,22 +5944,22 @@ tng_function_status tng_output_file_set(tng_trajectory_t tng_data, } -tng_function_status tng_program_name_set(tng_trajectory_t tng_data, +tng_function_status tng_first_program_name_set(tng_trajectory_t tng_data, const char *new_name) { int len; len = min(strlen(new_name) + 1, TNG_MAX_STR_LEN); - if(tng_data->program_name && strlen(tng_data->program_name) < len) + if(tng_data->first_program_name && strlen(tng_data->first_program_name) < len) { - free(tng_data->program_name); - tng_data->program_name = 0; + free(tng_data->first_program_name); + tng_data->first_program_name = 0; } - if(!tng_data->program_name) + if(!tng_data->first_program_name) { - tng_data->program_name = (char *) malloc(len); - if(!tng_data->program_name) + tng_data->first_program_name = (char *) malloc(len); + if(!tng_data->first_program_name) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); @@ -5826,27 +5967,27 @@ tng_function_status tng_program_name_set(tng_trajectory_t tng_data, } } - strncpy(tng_data->program_name, new_name, len); + strncpy(tng_data->first_program_name, new_name, len); return(TNG_SUCCESS); } -tng_function_status tng_forcefield_name_set(tng_trajectory_t tng_data, - const char *new_name) +tng_function_status tng_last_program_name_set(tng_trajectory_t tng_data, + const char *new_name) { int len; len = min(strlen(new_name) + 1, TNG_MAX_STR_LEN); - if(tng_data->forcefield_name && strlen(tng_data->forcefield_name) < len) + if(tng_data->last_program_name && strlen(tng_data->last_program_name) < len) { - free(tng_data->forcefield_name); - tng_data->forcefield_name = 0; + free(tng_data->last_program_name); + tng_data->last_program_name = 0; } - if(!tng_data->forcefield_name) + if(!tng_data->last_program_name) { - tng_data->forcefield_name = (char *) malloc(len); - if(!tng_data->forcefield_name) + tng_data->last_program_name = (char *) malloc(len); + if(!tng_data->last_program_name) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); @@ -5854,27 +5995,83 @@ tng_function_status tng_forcefield_name_set(tng_trajectory_t tng_data, } } - strncpy(tng_data->forcefield_name, new_name, len); + strncpy(tng_data->last_program_name, new_name, len); + + return(TNG_SUCCESS); +} + +tng_function_status tng_first_user_name_set(tng_trajectory_t tng_data, + const char *new_name) +{ + int len; + + len = min(strlen(new_name) + 1, TNG_MAX_STR_LEN); + + if(tng_data->first_user_name && strlen(tng_data->first_user_name) < len) + { + free(tng_data->first_user_name); + tng_data->first_user_name = 0; + } + if(!tng_data->first_user_name) + { + tng_data->first_user_name = (char *) malloc(len); + if(!tng_data->first_user_name) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", len, + __FILE__, __LINE__); + return(TNG_CRITICAL); + } + } + + strncpy(tng_data->first_user_name, new_name, len); return(TNG_SUCCESS); } -tng_function_status tng_user_name_set(tng_trajectory_t tng_data, +tng_function_status tng_last_user_name_set(tng_trajectory_t tng_data, const char *new_name) { int len; len = min(strlen(new_name) + 1, TNG_MAX_STR_LEN); - if(tng_data->user_name && strlen(tng_data->user_name) < len) + if(tng_data->last_user_name && strlen(tng_data->last_user_name) < len) + { + free(tng_data->last_user_name); + tng_data->last_user_name = 0; + } + if(!tng_data->last_user_name) + { + tng_data->last_user_name = (char *) malloc(len); + if(!tng_data->last_user_name) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", len, + __FILE__, __LINE__); + return(TNG_CRITICAL); + } + } + + strncpy(tng_data->last_user_name, new_name, len); + + return(TNG_SUCCESS); +} + +tng_function_status tng_first_computer_name_set(tng_trajectory_t tng_data, + const char *new_name) +{ + int len; + + len = min(strlen(new_name) + 1, TNG_MAX_STR_LEN); + + if(tng_data->first_computer_name && strlen(tng_data->first_computer_name) < len) { - free(tng_data->user_name); - tng_data->user_name = 0; + free(tng_data->first_computer_name); + tng_data->first_computer_name = 0; } - if(!tng_data->user_name) + if(!tng_data->first_computer_name) { - tng_data->user_name = (char *) malloc(len); - if(!tng_data->user_name) + tng_data->first_computer_name = (char *) malloc(len); + if(!tng_data->first_computer_name) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); @@ -5882,27 +6079,27 @@ tng_function_status tng_user_name_set(tng_trajectory_t tng_data, } } - strncpy(tng_data->user_name, new_name, len); + strncpy(tng_data->first_computer_name, new_name, len); return(TNG_SUCCESS); } -tng_function_status tng_computer_name_set(tng_trajectory_t tng_data, +tng_function_status tng_last_computer_name_set(tng_trajectory_t tng_data, const char *new_name) { int len; len = min(strlen(new_name) + 1, TNG_MAX_STR_LEN); - if(tng_data->computer_name && strlen(tng_data->computer_name) < len) + if(tng_data->last_computer_name && strlen(tng_data->last_computer_name) < len) { - free(tng_data->computer_name); - tng_data->computer_name = 0; + free(tng_data->last_computer_name); + tng_data->last_computer_name = 0; } - if(!tng_data->computer_name) + if(!tng_data->last_computer_name) { - tng_data->computer_name = (char *) malloc(len); - if(!tng_data->computer_name) + tng_data->last_computer_name = (char *) malloc(len); + if(!tng_data->last_computer_name) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); @@ -5910,27 +6107,27 @@ tng_function_status tng_computer_name_set(tng_trajectory_t tng_data, } } - strncpy(tng_data->computer_name, new_name, len); + strncpy(tng_data->last_computer_name, new_name, len); return(TNG_SUCCESS); } -tng_function_status tng_signature_set(tng_trajectory_t tng_data, +tng_function_status tng_first_signature_set(tng_trajectory_t tng_data, const char *signature) { int len; len = min(strlen(signature) + 1, TNG_MAX_STR_LEN); - if(tng_data->pgp_signature && strlen(tng_data->pgp_signature) < len) + if(tng_data->first_pgp_signature && strlen(tng_data->first_pgp_signature) < len) { - free(tng_data->pgp_signature); - tng_data->pgp_signature = 0; + free(tng_data->first_pgp_signature); + tng_data->first_pgp_signature = 0; } - if(!tng_data->pgp_signature) + if(!tng_data->first_pgp_signature) { - tng_data->pgp_signature = (char *) malloc(len); - if(!tng_data->pgp_signature) + tng_data->first_pgp_signature = (char *) malloc(len); + if(!tng_data->first_pgp_signature) { printf("Cannot allocate memory (%d bytes). %s: %d\n", len, __FILE__, __LINE__); @@ -5938,7 +6135,63 @@ tng_function_status tng_signature_set(tng_trajectory_t tng_data, } } - strncpy(tng_data->pgp_signature, signature, len); + strncpy(tng_data->first_pgp_signature, signature, len); + + return(TNG_SUCCESS); +} + +tng_function_status tng_last_signature_set(tng_trajectory_t tng_data, + const char *signature) +{ + int len; + + len = min(strlen(signature) + 1, TNG_MAX_STR_LEN); + + if(tng_data->last_pgp_signature && strlen(tng_data->last_pgp_signature) < len) + { + free(tng_data->last_pgp_signature); + tng_data->last_pgp_signature = 0; + } + if(!tng_data->last_pgp_signature) + { + tng_data->last_pgp_signature = (char *) malloc(len); + if(!tng_data->last_pgp_signature) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", len, + __FILE__, __LINE__); + return(TNG_CRITICAL); + } + } + + strncpy(tng_data->last_pgp_signature, signature, len); + + return(TNG_SUCCESS); +} + +tng_function_status tng_forcefield_name_set(tng_trajectory_t tng_data, + const char *new_name) +{ + int len; + + len = min(strlen(new_name) + 1, TNG_MAX_STR_LEN); + + if(tng_data->forcefield_name && strlen(tng_data->forcefield_name) < len) + { + free(tng_data->forcefield_name); + tng_data->forcefield_name = 0; + } + if(!tng_data->forcefield_name) + { + tng_data->forcefield_name = (char *) malloc(len); + if(!tng_data->forcefield_name) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", len, + __FILE__, __LINE__); + return(TNG_CRITICAL); + } + } + + strncpy(tng_data->forcefield_name, new_name, len); return(TNG_SUCCESS); } diff --git a/src/lib/tng_io.h b/src/lib/tng_io.h index badbb56..0c1d6e0 100644 --- a/src/lib/tng_io.h +++ b/src/lib/tng_io.h @@ -343,17 +343,28 @@ struct tng_trajectory { tng_endianness_64 endianness_64; /** The name of the program producing this trajectory */ - char *program_name; + char *first_program_name; /** The forcefield used in the simulations */ char *forcefield_name; /** The name of the user running the simulations */ - char *user_name; - /** The time (n seconds since 1970) when the file was created */ - int64_t time; + char *first_user_name; /** The name of the computer on which the simulations were performed */ - char *computer_name; + char *first_computer_name; /** The PGP signature of the user creating the file. */ - char *pgp_signature; + char *first_pgp_signature; + /** The name of the program used when making last modifications to the + * file */ + char *last_program_name; + /** The name of the user making the last modifications to the file */ + char *last_user_name; + /** The name of the computer on which the last modifications were made */ + char *last_computer_name; + /** The PGP signature of the user making the last modifications to the + * file. */ + char *last_pgp_signature; + /** The time (n seconds since 1970) when the file was created */ + int64_t time; + /** A flag indicating if the number of atoms can vary throughout the * simulation, e.g. using a grand canonical ensemble */ char var_num_atoms_flag; @@ -459,18 +470,18 @@ tng_function_status tng_output_file_set(tng_trajectory_t tng_data, * @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. */ -tng_function_status tng_program_name_set(tng_trajectory_t tng_data, - const char *new_name); +tng_function_status tng_first_program_name_set(tng_trajectory_t tng_data, + const char *new_name); /** - * @brief Set the name of the forcefield used in the trajectory. - * @param tng_data the trajectory of which to set the forcefield name. + * @brief Set the name of the program used when last modifying the trajectory. + * @param tng_data the trajectory of which to set the program name. * @param new_name is a string containing the wanted name. * @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. */ -tng_function_status tng_forcefield_name_set(tng_trajectory_t tng_data, - const char *new_name); +tng_function_status tng_last_program_name_set(tng_trajectory_t tng_data, + const char *new_name); /** * @brief Set the name of the user who created the trajectory. @@ -479,8 +490,18 @@ tng_function_status tng_forcefield_name_set(tng_trajectory_t tng_data, * @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. */ -tng_function_status tng_user_name_set(tng_trajectory_t tng_data, - const char *new_name); +tng_function_status tng_first_user_name_set(tng_trajectory_t tng_data, + const char *new_name); + +/** + * @brief Set the name of the user who last modified the trajectory. + * @param tng_data the trajectory of which to set the user name. + * @param new_name is a string containing the wanted name. + * @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. + */ +tng_function_status tng_last_user_name_set(tng_trajectory_t tng_data, + const char *new_name); /** * @brief Set the name of the computer used when creating the trajectory. @@ -489,18 +510,48 @@ tng_function_status tng_user_name_set(tng_trajectory_t tng_data, * @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. */ -tng_function_status tng_computer_name_set(tng_trajectory_t tng_data, - const char *new_name); +tng_function_status tng_first_computer_name_set(tng_trajectory_t tng_data, + const char *new_name); /** - * @brief Set the pgp_signature of the trajectory. + * @brief Set the name of the computer used when last modifying the trajectory. + * @param tng_data the trajectory of which to set the computer name. + * @param new_name is a string containing the wanted name. + * @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. + */ +tng_function_status tng_last_computer_name_set(tng_trajectory_t tng_data, + const char *new_name); + +/** + * @brief Set the pgp_signature of the user creating the trajectory. + * @param tng_data the trajectory of which to set the computer name. + * @param signature is a string containing the pgp_signature. + * @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. + */ +tng_function_status tng_first_signature_set(tng_trajectory_t tng_data, + const char *signature); + +/** + * @brief Set the pgp_signature of the user last modifying the trajectory. * @param tng_data the trajectory of which to set the computer name. * @param signature is a string containing the pgp_signature. * @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. */ -tng_function_status tng_signature_set(tng_trajectory_t tng_data, - const char *signature); +tng_function_status tng_last_signature_set(tng_trajectory_t tng_data, + const char *signature); + +/** + * @brief Set the name of the forcefield used in the trajectory. + * @param tng_data the trajectory of which to set the forcefield name. + * @param new_name is a string containing the wanted name. + * @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. + */ +tng_function_status tng_forcefield_name_set(tng_trajectory_t tng_data, + const char *new_name); /** * @brief Setup a molecule container. @@ -682,7 +733,7 @@ tng_function_status tng_atom_name_set(tng_trajectory_t tng_data, * @brief Set the atom type of an atom. * @param tng_data is the trajectory data container containing the atom.. * @param atom is the atom to change. - * @param new_name is a string containing the atom type. + * @param new_type is a string containing the atom type. * @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. */ @@ -698,7 +749,8 @@ tng_function_status tng_atom_type_set(tng_trajectory_t tng_data, * @details tng_data->input_file_path specifies * which file to read from. If the file (input_file) is not open it will be * opened. - * @details If hash_mode == TNG_USE_HASH the written md5 hash in the file will be + * @param hash_mode is an option to decide whether to use the md5 hash or not. + * If hash_mode == TNG_USE_HASH the written md5 hash in the file will be * compared to the md5 hash of the read contents to ensure valid data. * @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. @@ -714,7 +766,8 @@ tng_function_status tng_file_headers_read(tng_trajectory_t tng_data, * @details tng_data->output_file_path * specifies which file to write to. If the file (output_file) is not open it * will be opened. - * @details If hash_mode == TNG_USE_HASH an md5 hash for each header block will be generated. + * @param hash_mode is an option to decide whether to use the md5 hash or not. + * If hash_mode == TNG_USE_HASH an md5 hash for each header block will be generated. * @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. */ @@ -732,7 +785,8 @@ tng_function_status tng_file_headers_write(tng_trajectory_t tng_data, * data. * @details If block_data->input_file_pos > 0 it is the position from where the * reading starts otherwise it starts from the current position. - * @details If hash_mode == TNG_USE_HASH the written md5 hash in the file will be + * @param hash_mode is an option to decide whether to use the md5 hash or not. + * If hash_mode == TNG_USE_HASH the written md5 hash in the file will be * compared to the md5 hash of the read contents to ensure valid data. * @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. @@ -749,7 +803,8 @@ tng_function_status tng_block_read_next(tng_trajectory_t tng_data, * @details tng_data->input_file_path specifies * which file to read from. If the file (input_file) is not open it will be * opened. - * @details If hash_mode == TNG_USE_HASH the written md5 hash in the file will be + * @param hash_mode is an option to decide whether to use the md5 hash or not. + * If hash_mode == TNG_USE_HASH the written md5 hash in the file will be * compared to the md5 hash of the read contents to ensure valid data. * @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. @@ -764,7 +819,8 @@ tng_function_status tng_frame_set_read_next(tng_trajectory_t tng_data, * @details tng_data->output_file_path specifies * which file to write to. If the file (output_file) is not open it will be * opened. - * @details If hash_mode == TNG_USE_HASH an md5 hash for each block will be generated. + * @param hash_mode is an option to decide whether to use the md5 hash or not. + * If hash_mode == TNG_USE_HASH an md5 hash for each header block will be generated. * @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. */ @@ -962,6 +1018,7 @@ tng_function_status tng_particle_data_values_free(union data_values ***values, * needed to properly reach and/or free the data afterwards. * @param n_values_per_frame is set to the number of values per frame in the data. * This is needed to properly reach and/or free the data afterwards. + * @param type is set to the data type of the data in the array. * @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. */ @@ -987,6 +1044,7 @@ tng_function_status tng_data_get(tng_trajectory_t tng_data, * responsibility to free the memory. * @param n_values_per_frame is set to the number of values per frame in the data. * This is needed to properly reach and/or free the data afterwards. + * @param type is set to the data type of the data in the array. * @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. */ @@ -1015,6 +1073,7 @@ tng_function_status tng_data_interval_get(tng_trajectory_t tng_data, * needed to properly reach and/or free the data afterwards. * @param n_values_per_frame is set to the number of values per frame in the data. * This is needed to properly reach and/or free the data afterwards. + * @param type is set to the data type of the data in the array. * @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. */ @@ -1045,6 +1104,7 @@ tng_function_status tng_particle_data_get(tng_trajectory_t tng_data, * responsibility to free the memory. * @param n_values_per_frame is set to the number of values per frame in the data. * This is needed to properly reach and/or free the data afterwards. + * @param type is set to the data type of the data in the array. * @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. */ |