diff options
author | Magnus Lundborg <magnus.lundborg@scilifelab.se> | 2013-01-08 09:19:20 (GMT) |
---|---|---|
committer | Magnus Lundborg <magnus.lundborg@scilifelab.se> | 2013-01-08 09:19:20 (GMT) |
commit | 7fbd0e5b2231171c4e82d0bd89d27b396328ad9b (patch) | |
tree | 4aacd6720e8ed230a185dcb44565932a0bc15957 | |
parent | 8f32a616b110b9f9510c289aef8c6e5d8e47b5f3 (diff) |
Automatically add frame sets if trying to write frame data beyond the last frame set. Minor fixes.
-rw-r--r-- | src/lib/tng_io.c | 395 | ||||
-rw-r--r-- | src/tests/md_openmp.c | 140 | ||||
-rw-r--r-- | src/tests/tng_io_testing.c | 28 |
3 files changed, 298 insertions, 265 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 12b7a4e..954d1d7 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -7032,6 +7032,7 @@ tng_function_status tng_frame_set_write(tng_trajectory_t tng_data, tng_data->current_trajectory_frame_set_output_file_pos = + tng_data->last_trajectory_frame_set_output_file_pos = ftell(tng_data->output_file); tng_block_init(&block); @@ -7300,6 +7301,7 @@ tng_function_status tng_data_block_add(tng_trajectory_t tng_data, int i, j, block_index, size, len; tng_trajectory_frame_set_t frame_set; tng_non_particle_data_t data; + union data_values *first_dim_values; void *orig; frame_set = &tng_data->current_trajectory_frame_set; @@ -7399,71 +7401,89 @@ tng_function_status tng_data_block_add(tng_trajectory_t tng_data, break; } - orig = new_data; - - switch(datatype) + if(new_data) { - case TNG_FLOAT_DATA: - for(i = 0; i < n_frames; i++) + orig = new_data; + + switch(datatype) { - for(j = 0; j < n_values_per_frame; j++) + case TNG_FLOAT_DATA: + for(i = 0; i < n_frames; i++) { - memcpy(&data->values[i][j].f, - new_data, size); - new_data += size; + first_dim_values = data->values[i]; + for(j = 0; j < n_values_per_frame; j++) + { + memcpy(&first_dim_values[j].f, + new_data, size); + new_data += size; + } } - } - break; - case TNG_CHAR_DATA: - for(i = 0; i < n_frames; i++) - { - for(j = 0; j < n_values_per_frame; j++) + break; + case TNG_CHAR_DATA: + for(i = 0; i < n_frames; i++) { - len = min(strlen(new_data) + 1, - TNG_MAX_STR_LEN); - if(data->values[i][j].c) + first_dim_values = data->values[i]; + for(j = 0; j < n_values_per_frame; j++) { - free(data->values[i][j].c); + len = min(strlen(new_data) + 1, + TNG_MAX_STR_LEN); + if(first_dim_values[j].c) + { + free(first_dim_values[j].c); + } + first_dim_values[j].c = malloc(len); + if(!first_dim_values[j].c) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", + len, __FILE__, __LINE__); + return(TNG_CRITICAL); + } + strncpy(first_dim_values[j].c, + new_data, len); + new_data += len; } - data->values[i][j].c = malloc(len); - if(!data->values[i][j].c) + } + break; + case TNG_INT_DATA: + for(i = 0; i < n_frames; i++) + { + first_dim_values = data->values[i]; + for(j = 0; j < n_values_per_frame; j++) { - printf("Cannot allocate memory (%d bytes). %s: %d\n", - len, __FILE__, __LINE__); - return(TNG_CRITICAL); + memcpy(&first_dim_values[j].i, + new_data, size); + new_data += size; } - strncpy(data->values[i][j].c, - new_data, len); - new_data += len; } - } - break; - case TNG_INT_DATA: - for(i = 0; i < n_frames; i++) - { - for(j = 0; j < n_values_per_frame; j++) + break; + case TNG_DOUBLE_DATA: + default: + for(i = 0; i < n_frames; i++) { - memcpy(&data->values[i][j].i, - new_data, size); - new_data += size; + first_dim_values = data->values[i]; + for(j = 0; j < n_values_per_frame; j++) + { + memcpy(&first_dim_values[j].d, + new_data, size); + new_data += size; + } } } - break; - case TNG_DOUBLE_DATA: - default: + + new_data = orig; + } + else + { for(i = 0; i < n_frames; i++) { + first_dim_values = data->values[i]; for(j = 0; j < n_values_per_frame; j++) { - memcpy(&data->values[i][j].d, - new_data, size); - new_data += size; + first_dim_values[j].d = 0; } } } - - new_data = orig; - + return(TNG_SUCCESS); } @@ -7581,79 +7601,105 @@ tng_function_status tng_particle_data_block_add(tng_trajectory_t tng_data, } } - orig = new_data; - - switch(datatype) + /* If data values are supplied add that data to the data block. */ + if(new_data) { - case TNG_FLOAT_DATA: - size = sizeof(float); - for(i = 0; i < n_frames; i++) + orig = new_data; + + switch(datatype) { - first_dim_values = data->values[i]; - for(j = num_first_particle; j < num_first_particle + n_particles; - j++) + case TNG_FLOAT_DATA: + size = sizeof(float); + for(i = 0; i < n_frames; i++) { - second_dim_values = first_dim_values[j]; - for(k = 0; k < n_values_per_frame; k++) + first_dim_values = data->values[i]; + for(j = num_first_particle; j < num_first_particle + n_particles; + j++) { - memcpy(&second_dim_values[k].f, - new_data, size); - new_data += size; + second_dim_values = first_dim_values[j]; + for(k = 0; k < n_values_per_frame; k++) + { + memcpy(&second_dim_values[k].f, + new_data, size); + new_data += size; + } } } - } - break; - case TNG_INT_DATA: - size = sizeof(int64_t); - for(i = 0; i < n_frames; i++) - { - first_dim_values = data->values[i]; - for(j = num_first_particle; j < num_first_particle + n_particles; - j++) + break; + case TNG_INT_DATA: + size = sizeof(int64_t); + for(i = 0; i < n_frames; i++) { - second_dim_values = first_dim_values[j]; - for(k = 0; k < n_values_per_frame; k++) + first_dim_values = data->values[i]; + for(j = num_first_particle; j < num_first_particle + n_particles; + j++) { - memcpy(&second_dim_values[k].i, - new_data, size); - new_data += size; + second_dim_values = first_dim_values[j]; + for(k = 0; k < n_values_per_frame; k++) + { + memcpy(&second_dim_values[k].i, + new_data, size); + new_data += size; + } } } - } - break; - case TNG_CHAR_DATA: - for(i = 0; i < n_frames; i++) - { - first_dim_values = data->values[i]; - for(j = num_first_particle; j < num_first_particle + n_particles; - j++) + break; + case TNG_CHAR_DATA: + for(i = 0; i < n_frames; i++) { - second_dim_values = first_dim_values[j]; - for(k = 0; k < n_values_per_frame; k++) + first_dim_values = data->values[i]; + for(j = num_first_particle; j < num_first_particle + n_particles; + j++) { - len = min(strlen(new_data) + 1, - TNG_MAX_STR_LEN); - if(second_dim_values[k].c) + second_dim_values = first_dim_values[j]; + for(k = 0; k < n_values_per_frame; k++) { - free(second_dim_values[k].c); + len = min(strlen(new_data) + 1, + TNG_MAX_STR_LEN); + if(second_dim_values[k].c) + { + free(second_dim_values[k].c); + } + second_dim_values[k].c = malloc(len); + if(!second_dim_values[k].c) + { + printf("Cannot allocate memory (%d bytes). %s: %d\n", + len, __FILE__, __LINE__); + return(TNG_CRITICAL); + } + strncpy(second_dim_values[k].c, + new_data, len); + new_data += len; } - second_dim_values[k].c = malloc(len); - if(!second_dim_values[k].c) + } + } + break; + case TNG_DOUBLE_DATA: + default: + size = sizeof(double); + for(i = 0; i < n_frames; i++) + { + first_dim_values = data->values[i]; + for(j = num_first_particle; j < num_first_particle + n_particles; + j++) + { + second_dim_values = first_dim_values[j]; + for(k = 0; k < n_values_per_frame; k++) { - printf("Cannot allocate memory (%d bytes). %s: %d\n", - len, __FILE__, __LINE__); - return(TNG_CRITICAL); + memcpy(&second_dim_values[k].d, + new_data, size); + new_data += size; } - strncpy(second_dim_values[k].c, - new_data, len); - new_data += len; } } + break; } - break; - case TNG_DOUBLE_DATA: - default: - size = sizeof(double); + + new_data = orig; + } + /* Otherwise fill the data block with zeroes */ + else + { for(i = 0; i < n_frames; i++) { first_dim_values = data->values[i]; @@ -7663,16 +7709,12 @@ tng_function_status tng_particle_data_block_add(tng_trajectory_t tng_data, second_dim_values = first_dim_values[j]; for(k = 0; k < n_values_per_frame; k++) { - memcpy(&second_dim_values[k].d, - new_data, size); - new_data += size; + second_dim_values[k].d = 0; } } } - break; } - - new_data = orig; + return(TNG_SUCCESS); } @@ -7686,12 +7728,14 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, int64_t header_pos, file_pos; int64_t output_file_len, n_values_per_frame, size, contents_size; int64_t header_size, temp_first, temp_last, temp_current; + int64_t i, last_frame; tng_gen_block_t block; tng_trajectory_frame_set_t frame_set; FILE *temp = tng_data->input_file; struct tng_non_particle_data data; tng_function_status stat; char dependency, sparse_data, datatype; + void *copy; if(tng_output_file_init(tng_data, FALSE) != TNG_SUCCESS) { @@ -7716,11 +7760,33 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, if(stat != TNG_SUCCESS) { - tng_data->input_file = temp; - tng_data->first_trajectory_frame_set_input_file_pos = temp_first; - tng_data->last_trajectory_frame_set_input_file_pos = temp_last; - tng_data->current_trajectory_frame_set_input_file_pos = temp_current; - return(stat); + last_frame = tng_data->current_trajectory_frame_set.first_frame + + tng_data->current_trajectory_frame_set.n_frames - 1; + /* If the wanted frame would be in the frame set after the last + * frame set create a new frame set. */ + if(stat == TNG_FAILURE && + (last_frame < frame_nr && + tng_data->current_trajectory_frame_set.first_frame + + tng_data->frame_set_n_frames > frame_nr)) + { + tng_frame_set_new(tng_data, + last_frame+1, + tng_data->frame_set_n_frames); + /* Write the frame set to disk */ + if(tng_frame_set_write(tng_data, hash_mode) != TNG_SUCCESS) + { + printf("Error writing frame set. %s: %d\n", __FILE__, __LINE__); + exit(1); + } + } + else + { + tng_data->input_file = temp; + tng_data->first_trajectory_frame_set_input_file_pos = temp_first; + tng_data->last_trajectory_frame_set_input_file_pos = temp_last; + tng_data->current_trajectory_frame_set_input_file_pos = temp_current; + return(stat); + } } tng_block_init(&block); @@ -7911,7 +7977,39 @@ tng_function_status tng_frame_data_write(tng_trajectory_t tng_data, fseek(tng_data->output_file, file_pos, SEEK_CUR); - fwrite(values, n_values_per_frame, size, tng_data->output_file); + /* 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) + { + 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_swap_byte_order_64(tng_data, (int64_t *)copy+i); + } + 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) + { + 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_swap_byte_order_32(tng_data, (int32_t *)copy+i); + } + fwrite(copy, n_values_per_frame, size, + tng_data->output_file); + free(copy); + } + + else + { + fwrite(values, n_values_per_frame, size, tng_data->output_file); + } fflush(tng_data->output_file); @@ -7941,7 +8039,7 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, int64_t output_file_len, n_values_per_frame, size, contents_size; int64_t header_size, temp_first, temp_last, temp_current; int64_t mapping_block_end_pos, num_first_particle, block_n_particles; - int64_t i; + int64_t i, last_frame; tng_gen_block_t block; tng_trajectory_frame_set_t frame_set; FILE *temp = tng_data->input_file; @@ -7972,20 +8070,75 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, stat = tng_frame_set_find(tng_data, frame_nr); + frame_set = &tng_data->current_trajectory_frame_set; + if(stat != TNG_SUCCESS) { - tng_data->input_file = temp; + last_frame = tng_data->current_trajectory_frame_set.first_frame + + tng_data->current_trajectory_frame_set.n_frames - 1; +// printf("Frame %"PRId64" not found. Last frame: %"PRId64"\n", frame_nr, +// last_frame); + /* If the wanted frame would be in the frame set after the last + * frame set create a new frame set. */ + if(stat == TNG_FAILURE && + (last_frame < frame_nr && + last_frame + tng_data->frame_set_n_frames >= frame_nr)) + { + tng_frame_set_new(tng_data, + last_frame+1, + tng_data->frame_set_n_frames); - tng_data->first_trajectory_frame_set_input_file_pos = temp_first; - tng_data->last_trajectory_frame_set_input_file_pos = temp_last; - tng_data->current_trajectory_frame_set_input_file_pos = temp_current; - return(stat); + file_pos = ftell(tng_data->output_file); + fseek(tng_data->output_file, 0, SEEK_END); + output_file_len = ftell(tng_data->output_file); + fseek(tng_data->output_file, file_pos, SEEK_SET); + + /* Read mapping blocks from the last frame set */ + tng_block_init(&block); + + stat = tng_block_header_read(tng_data, block); + while(file_pos < output_file_len && + stat != TNG_CRITICAL && + block->id != TNG_TRAJECTORY_FRAME_SET) + { + if(block->id == TNG_PARTICLE_MAPPING) + { + tng_trajectory_mapping_block_read(tng_data, block, + hash_mode); + } + else + { + fseek(tng_data->output_file, block->block_contents_size, + SEEK_CUR); + } + file_pos = ftell(tng_data->output_file); + if(file_pos < output_file_len) + { + stat = tng_block_header_read(tng_data, block); + } + } + + tng_block_destroy(&block); + /* Write the frame set to disk */ + if(tng_frame_set_write(tng_data, hash_mode) != TNG_SUCCESS) + { + printf("Error writing frame set. %s: %d\n", __FILE__, __LINE__); + exit(1); + } + } + else + { + tng_data->input_file = temp; + tng_data->first_trajectory_frame_set_input_file_pos = temp_first; + tng_data->last_trajectory_frame_set_input_file_pos = temp_last; + tng_data->current_trajectory_frame_set_input_file_pos = temp_current; + return(stat); + } } + tng_block_init(&block); - frame_set = &tng_data->current_trajectory_frame_set; - file_pos = tng_data->current_trajectory_frame_set_output_file_pos; fseek(tng_data->output_file, 0, SEEK_END); @@ -8275,7 +8428,7 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, memcpy(copy, values, val_n_particles * n_values_per_frame * size); for(i = 0; i < val_n_particles * n_values_per_frame; i++) { - tng_swap_byte_order_64(tng_data, (int64_t *)copy+i*size); + tng_swap_byte_order_64(tng_data, (int64_t *)copy+i); } fwrite(copy, val_n_particles * n_values_per_frame, size, tng_data->output_file); @@ -8288,7 +8441,7 @@ tng_function_status tng_frame_particle_data_write(tng_trajectory_t tng_data, memcpy(copy, values, val_n_particles * n_values_per_frame * size); for(i = 0; i < val_n_particles * n_values_per_frame; i++) { - tng_swap_byte_order_32(tng_data, (int32_t *)copy+i*size); + tng_swap_byte_order_32(tng_data, (int32_t *)copy+i); } fwrite(copy, val_n_particles * n_values_per_frame, size, tng_data->output_file); diff --git a/src/tests/md_openmp.c b/src/tests/md_openmp.c index 0b5241a..2b33b7a 100644 --- a/src/tests/md_openmp.c +++ b/src/tests/md_openmp.c @@ -72,7 +72,7 @@ int main ( int argc, char *argv[] ) int proc_num; int seed = 123456789; int step; - int step_num = 1000; + int step_num = 2000; int step_print; int step_print_index; int step_print_num; @@ -87,7 +87,6 @@ int main ( int argc, char *argv[] ) int64_t n_frames_per_frame_set; int frames_saved_cnt = 0; int frame_set_cnt = 0; - double **data; timestamp ( ); @@ -112,7 +111,7 @@ int main ( int argc, char *argv[] ) printf ( " DT, the size of each time step, is %f\n", dt ); printf ( "\n" ); - printf ( " Number of processors available = %d\n", omp_get_num_procs ( ) ); + printf ( " Number of processors available = %d\n", proc_num ); printf ( " Number of threads = %d\n", omp_get_max_threads ( ) ); @@ -185,13 +184,24 @@ int main ( int argc, char *argv[] ) compute ( np, nd, pos, vel, mass, force, &potential, &kinetic ); e0 = potential + kinetic; + + /* Saving frequency */ + step_save = 5; + + step_print = 0; + step_print_index = 0; + step_print_num = 10; + /* This is the main time stepping loop: Compute forces and energies, Update positions, velocities, accelerations. */ + printf(" Every %d steps particle positions, velocities and forces are\n", + step_save); + printf(" saved to a TNG trajectory file.\n"); printf ( "\n" ); - printf ( " At each step, we report the potential and kinetic energies.\n" ); + printf ( " At certain step intervals, we report the potential and kinetic energies.\n" ); printf ( " The sum of these energies should be a constant.\n" ); printf ( " As an accuracy check, we also print the relative error\n" ); printf ( " in the total energy.\n" ); @@ -200,19 +210,12 @@ int main ( int argc, char *argv[] ) printf ( " Energy P Energy K Relative Energy Error\n" ); printf ( "\n" ); - step_print = 0; - step_print_index = 0; - step_print_num = 10; - step = 0; printf ( " %8d %14f %14f %14e\n", step, potential, kinetic, ( potential + kinetic - e0 ) / e0 ); step_print_index++; step_print = ( step_print_index * step_num ) / step_print_num; - /* Saving frequency */ - step_save = 5; - wtime = omp_get_wtime ( ); /* Create a frame set for writing data */ @@ -225,19 +228,8 @@ int main ( int argc, char *argv[] ) exit(1); } frame_set_cnt++; - - /* Setup an empty data array - this will be written to the frame set - * (since the block size needs to be correct in the file. After that it - * is filled with data. */ - data = malloc(n_frames_per_frame_set * 3 * np * sizeof(double)); - - for(i = 0; i < n_frames_per_frame_set * 3 * np; i++) - { - data[i] = 0; - } - - /* Add data blocks */ + /* Add empty data blocks */ if(tng_particle_data_block_add(traj, TNG_TRAJ_POSITIONS, "POSITIONS", TNG_DOUBLE_DATA, @@ -245,10 +237,9 @@ int main ( int argc, char *argv[] ) n_frames_per_frame_set, 3, 1, 0, np, TNG_UNCOMPRESSED, - data) != TNG_SUCCESS) + 0) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); exit(1); } if(tng_particle_data_block_add(traj, TNG_TRAJ_VELOCITIES, @@ -258,10 +249,9 @@ int main ( int argc, char *argv[] ) n_frames_per_frame_set, 3, 1, 0, np, TNG_UNCOMPRESSED, - data) != TNG_SUCCESS) + 0) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); exit(1); } if(tng_particle_data_block_add(traj, TNG_TRAJ_FORCES, @@ -271,10 +261,9 @@ int main ( int argc, char *argv[] ) n_frames_per_frame_set, 3, 1, 0, np, TNG_UNCOMPRESSED, - data) != TNG_SUCCESS) + 0) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); exit(1); } @@ -282,38 +271,8 @@ int main ( int argc, char *argv[] ) if(tng_frame_set_write(traj, TNG_SKIP_HASH) != TNG_SUCCESS) { printf("Error writing frame set. %s: %d\n", __FILE__, __LINE__); - free(data); - exit(1); - } - - if(tng_frame_particle_data_write(traj, 0, - TNG_TRAJ_POSITIONS, 0, np, - pos, TNG_USE_HASH) != TNG_SUCCESS) - { - printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); exit(1); } - if(tng_frame_particle_data_write(traj, 0, - TNG_TRAJ_VELOCITIES, 0, np, - vel, TNG_USE_HASH) != TNG_SUCCESS) - { - printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); - exit(1); - } - if(tng_frame_particle_data_write(traj, 0, - TNG_TRAJ_FORCES, 0, np, - force, TNG_USE_HASH) != TNG_SUCCESS) - { - printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); - exit(1); - } - frames_saved_cnt++; - - -// printf("pos: %f, vel: %f, force: %f\n", pos[0], vel[0], force[0]); for ( step = 1; step <= step_num; step++ ) { @@ -328,72 +287,11 @@ int main ( int argc, char *argv[] ) } if(step % step_save == 0) { - if(frames_saved_cnt % n_frames_per_frame_set == 0) - { - if(tng_frame_set_new(traj, frames_saved_cnt, - n_frames_per_frame_set) != TNG_SUCCESS) - { - printf("Error creating frame set %d. %s: %d\n", - i, __FILE__, __LINE__); - free(data); - exit(1); - } - /* Add data blocks */ - if(tng_particle_data_block_add(traj, TNG_TRAJ_POSITIONS, - "POSITIONS", - TNG_DOUBLE_DATA, - TNG_TRAJECTORY_BLOCK, - n_frames_per_frame_set, 3, - 1, 0, np, - TNG_UNCOMPRESSED, - data) != TNG_SUCCESS) - { - printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); - exit(1); - } - if(tng_particle_data_block_add(traj, TNG_TRAJ_VELOCITIES, - "VELOCITIES", - TNG_DOUBLE_DATA, - TNG_TRAJECTORY_BLOCK, - n_frames_per_frame_set, 3, - 1, 0, np, - TNG_UNCOMPRESSED, - data) != TNG_SUCCESS) - { - printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); - exit(1); - } - if(tng_particle_data_block_add(traj, TNG_TRAJ_FORCES, - "FORCES", - TNG_DOUBLE_DATA, - TNG_TRAJECTORY_BLOCK, - n_frames_per_frame_set, 3, - 1, 0, np, - TNG_UNCOMPRESSED, - data) != TNG_SUCCESS) - { - printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); - exit(1); - } - - /* Write the frame set to disk */ - if(tng_frame_set_write(traj, TNG_SKIP_HASH) != TNG_SUCCESS) - { - printf("Error writing frame set. %s: %d\n", __FILE__, __LINE__); - free(data); - exit(1); - } - - } if(tng_frame_particle_data_write(traj, frames_saved_cnt, TNG_TRAJ_POSITIONS, 0, np, pos, TNG_USE_HASH) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); exit(1); } if(tng_frame_particle_data_write(traj, frames_saved_cnt, @@ -401,7 +299,6 @@ int main ( int argc, char *argv[] ) vel, TNG_USE_HASH) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); exit(1); } if(tng_frame_particle_data_write(traj, frames_saved_cnt, @@ -409,7 +306,6 @@ int main ( int argc, char *argv[] ) force, TNG_USE_HASH) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); - free(data); exit(1); } frames_saved_cnt++; diff --git a/src/tests/tng_io_testing.c b/src/tests/tng_io_testing.c index c45668f..4b95c38 100644 --- a/src/tests/tng_io_testing.c +++ b/src/tests/tng_io_testing.c @@ -280,27 +280,11 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj) } } - /* Write one more frame set one frame at a time */ + /* Write two more frame sets one frame at a time */ cnt = 0; - /* Setup an empty data array - this will be written to the frame set - * (since the block size needs to be correct in the file. After that it - * is filled with data. */ - for(j = 0; j < n_frames_per_frame_set; j++) - { - for(k = 0; k < tot_n_mols; k++) - { - data[cnt++] = 0; - data[cnt++] = 0; - data[cnt++] = 0; - data[cnt++] = 0; - data[cnt++] = 0; - data[cnt++] = 0; - data[cnt++] = 0; - data[cnt++] = 0; - data[cnt++] = 0; - } - } - /* Make a new frame set */ + /* Make a new frame set - if always using the same mapping blocks + * it is not necessary to explicitly add a new frame set - it will + * be added automatically when adding data for a frame */ if(tng_frame_set_new(traj, i * n_frames_per_frame_set, n_frames_per_frame_set) != TNG_SUCCESS) { @@ -347,7 +331,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj) n_frames_per_frame_set, 3, 1, 0, n_particles, TNG_UNCOMPRESSED, - data) != TNG_SUCCESS) + 0) != TNG_SUCCESS) { printf("Error adding data. %s: %d\n", __FILE__, __LINE__); free(molpos); @@ -365,7 +349,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj) } /* Write particle data to disk - one frame at a time */ - for(i = 0; i < n_frames_per_frame_set; i++) + for(i = 0; i < n_frames_per_frame_set * 2; i++) { for(j = 0; j < 2; j++) { |