diff options
author | Magnus Lundborg <magnus.lundborg@scilifelab.se> | 2012-12-04 12:53:26 (GMT) |
---|---|---|
committer | Magnus Lundborg <magnus.lundborg@scilifelab.se> | 2012-12-04 12:53:26 (GMT) |
commit | 8fb3c94cb9359de1db7938f2c284690e34d9d6cc (patch) | |
tree | ffc8b99b5866182ce78779f9392459001f502e5b /src | |
parent | 7d8af09a7ec914886daa85365b4b9e884cf502d2 (diff) |
Remove flag to close file after reading and writing.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/tng_io.c | 67 | ||||
-rw-r--r-- | src/lib/tng_io.h | 44 | ||||
-rw-r--r-- | src/tests/tng_io_testing.c | 16 |
3 files changed, 25 insertions, 102 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 2be56fd..51fa9c2 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -5964,7 +5964,6 @@ tng_function_status tng_set_signature(tng_trajectory_t tng_data, } tng_function_status tng_read_file_headers(tng_trajectory_t tng_data, - tng_close_file_flag close_file, const tng_hash_mode hash_mode) { int i, cnt = 0, prev_pos = 0; @@ -6003,7 +6002,7 @@ tng_function_status tng_read_file_headers(tng_trajectory_t tng_data, { // printf("Reading block header %d: %s\n", (int)block->id, block->name); if(tng_read_next_block(tng_data, block, - TNG_KEEP_FILE_OPEN, hash_mode) == TNG_SUCCESS) + hash_mode) == TNG_SUCCESS) { // printf("Read block %s\n", block->name); block++; @@ -6028,18 +6027,10 @@ tng_function_status tng_read_file_headers(tng_trajectory_t tng_data, fseek(tng_data->input_file, prev_pos, SEEK_SET); } - if(close_file) - { - tng_data->input_file_pos=ftell(tng_data->input_file); - fclose(tng_data->input_file); - tng_data->input_file = 0; - } - return(TNG_SUCCESS); } tng_function_status tng_write_file_headers(tng_trajectory_t tng_data, - tng_close_file_flag close_file, const tng_hash_mode hash_mode) { int i; @@ -6104,19 +6095,11 @@ tng_function_status tng_write_file_headers(tng_trajectory_t tng_data, tng_destroy_block(&data_block); - if(close_file) - { - tng_data->output_file_pos=ftell(tng_data->output_file); - fclose(tng_data->output_file); - tng_data->output_file = 0; - } - return(TNG_SUCCESS); } tng_function_status tng_read_next_block(tng_trajectory_t tng_data, struct tng_gen_block *block, - const tng_close_file_flag close_file, const tng_hash_mode hash_mode) { switch(block->id) @@ -6143,14 +6126,6 @@ tng_function_status tng_read_next_block(tng_trajectory_t tng_data, return(TNG_FAILURE); } } - - /* FIXME: Never reached. */ - if(close_file) - { - tng_data->input_file_pos=ftell(tng_data->input_file); - fclose(tng_data->input_file); - tng_data->input_file = 0; - } } // tng_function_status tng_write_block(tng_trajectory_t tng_data @@ -6212,7 +6187,6 @@ tng_function_status tng_read_next_block(tng_trajectory_t tng_data, // } tng_function_status tng_read_next_frame_set(tng_trajectory_t tng_data, - const tng_close_file_flag close_file, const tng_hash_mode hash_mode) { long int file_pos; @@ -6255,7 +6229,6 @@ tng_function_status tng_read_next_frame_set(tng_trajectory_t tng_data, tng_data->current_trajectory_frame_set_input_file_pos = file_pos; if(tng_read_next_block(tng_data, &block, - TNG_KEEP_FILE_OPEN, hash_mode) == TNG_SUCCESS) { file_pos = ftell(tng_data->input_file); @@ -6266,7 +6239,6 @@ tng_function_status tng_read_next_frame_set(tng_trajectory_t tng_data, block.id != TNG_TRAJECTORY_FRAME_SET) { stat = tng_read_next_block(tng_data, &block, - TNG_KEEP_FILE_OPEN, hash_mode) == TNG_SUCCESS; if(stat != TNG_CRITICAL) @@ -6293,17 +6265,10 @@ tng_function_status tng_read_next_frame_set(tng_trajectory_t tng_data, tng_destroy_block(&block); - if(close_file) - { - fclose(tng_data->input_file); - tng_data->input_file = 0; - } - return(TNG_SUCCESS); } tng_function_status tng_write_frame_set(tng_trajectory_t tng_data, - const tng_close_file_flag close_file, const tng_hash_mode hash_mode) { int i, j; @@ -6382,12 +6347,6 @@ tng_function_status tng_write_frame_set(tng_trajectory_t tng_data, tng_destroy_block(&block); - if(close_file) - { - fclose(tng_data->input_file); - tng_data->input_file = 0; - } - return(stat); } @@ -6893,47 +6852,41 @@ tng_function_status tng_add_particle_data_block(tng_trajectory_t tng_data, } -tng_function_status tng_read_next_traj_block(tng_trajectory_t tng_data, - tng_close_file_flag close_file) +tng_function_status tng_read_next_traj_block(tng_trajectory_t tng_data) { /* STUB */ return(TNG_SUCCESS); } -tng_function_status tng_write_next_traj_block(tng_trajectory_t tng_data, - tng_close_file_flag close_file) +tng_function_status tng_write_next_traj_block(tng_trajectory_t tng_data) { /* STUB */ return(TNG_SUCCESS); } tng_function_status tng_read_traj_block(tng_trajectory_t tng_data, - int64_t block_id, - tng_close_file_flag close_file) + int64_t block_id) { /* STUB */ return(TNG_SUCCESS); } tng_function_status tng_write_traj_block(tng_trajectory_t tng_data, - int64_t block_id, - tng_close_file_flag close_file) + int64_t block_id) { /* STUB */ return(TNG_SUCCESS); } tng_function_status tng_read_frame_nr(tng_trajectory_t tng_data, - int64_t frame_nr, - tng_close_file_flag close_file) + int64_t frame_nr) { /* STUB */ return(TNG_SUCCESS); } tng_function_status tng_write_frame_nr(tng_trajectory_t tng_data, - int64_t frame_nr, - tng_close_file_flag close_file) + int64_t frame_nr) { /* STUB */ return(TNG_SUCCESS); @@ -6941,8 +6894,7 @@ tng_function_status tng_write_frame_nr(tng_trajectory_t tng_data, tng_function_status tng_read_frame_nrs(tng_trajectory_t tng_data, int64_t start_frame_nr, - int64_t end_frame_nr, - tng_close_file_flag close_file) + int64_t end_frame_nr) { /* STUB */ return(TNG_SUCCESS); @@ -6950,8 +6902,7 @@ tng_function_status tng_read_frame_nrs(tng_trajectory_t tng_data, tng_function_status tng_write_frame_nrs(tng_trajectory_t tng_data, int64_t start_frame_nr, - int64_t end_frame_nr, - tng_close_file_flag close_file) + int64_t end_frame_nr) { /* STUB */ return(TNG_SUCCESS); diff --git a/src/lib/tng_io.h b/src/lib/tng_io.h index 16db334..37d8229 100644 --- a/src/lib/tng_io.h +++ b/src/lib/tng_io.h @@ -67,8 +67,6 @@ typedef enum {TNG_NON_PARTICLE_BLOCK_DATA, typedef enum {FALSE, TRUE} tng_bool; -typedef enum {TNG_KEEP_FILE_OPEN, TNG_CLOSE_FILE} tng_close_file_flag; - typedef enum {TNG_CONSTANT_N_ATOMS, TNG_VARIABLE_N_ATOMS} tng_variable_n_atoms_flag; typedef enum {TNG_SUCCESS, TNG_FAILURE, TNG_CRITICAL} tng_function_status; @@ -571,13 +569,11 @@ tng_function_status tng_set_atom_type(tng_trajectory_t tng_data, to fit in memory. tng_data is a trajectory data container. tng_data->input_file_path specifies which file to read from. If the file (input_file) is not open it will be opened. - If close_file == TNG_CLOSE_FILE (1) the input_file will be closed after reading the data. 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. Returns 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_read_file_headers(tng_trajectory_t tng_data, - const tng_close_file_flag close_file, const tng_hash_mode hash_mode); /* Write the header blocks to the output_file of tng_data. @@ -585,12 +581,10 @@ tng_function_status tng_read_file_headers(tng_trajectory_t tng_data, to fit in memory. tng_data is a trajectory data container. tng_data->output_file_path specifies which file to write to. If the file (output_file) is not open it will be opened. - If close_file == TNG_CLOSE_FILE (1) the output_file will be closed after writing the data. If hash_mode == TNG_USE_HASH an md5 hash for each header block will be generated. Returns 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_write_file_headers(tng_trajectory_t tng_data, - const tng_close_file_flag close_file, const tng_hash_mode hash_mode); @@ -600,14 +594,12 @@ tng_function_status tng_write_file_headers(tng_trajectory_t tng_data, *block_data is a pointer to the struct which will be populated with the data. If block_data->input_file_pos > 0 it is the position from where the reading starts otherwise it starts from the current position. - If close_file == TNG_CLOSE_FILE (1) the input_file will be closed after reading the data. 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. Returns 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_read_next_block(tng_trajectory_t tng_data, struct tng_gen_block *block_data, - const tng_close_file_flag close_file, const tng_hash_mode hash_mode); @@ -615,25 +607,21 @@ tng_function_status tng_read_next_block(tng_trajectory_t tng_data, from the input_file of tng_data. tng_data is a trajectory data container. tng_data->input_file_path specifies which file to read from. If the file (input_file) is not open it will be opened. - If close_file == TNG_CLOSE_FILE (1) the input_file will be closed after reading the data. 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. Returns 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_read_next_frame_set(tng_trajectory_t tng_data, - const tng_close_file_flag close_file, const tng_hash_mode hash_mode); /* Write one (the next) frame set, including toc, mapping and related data blocks to the output_file of tng_data. tng_data is a trajectory data container. tng_data->output_file_path specifies which file to write to. If the file (output_file) is not open it will be opened. - If close_file == TNG_CLOSE_FILE (1) the output_file will be closed after writing the data. If hash_mode == TNG_USE_HASH an md5 hash for each block will be generated. Returns 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_write_frame_set(tng_trajectory_t tng_data, - const tng_close_file_flag close_file, const tng_hash_mode hash_mode); tng_function_status tng_new_frame_set(tng_trajectory_t tng_data, @@ -656,42 +644,34 @@ tng_function_status tng_add_particle_data_block(tng_trajectory_t tng_data, /* Read one (the next) trajectory block from the input_file of tng_data. tng_data is a trajectory data container. tng_data->input_file_path specifies which file to read from. If the file (input_file) is not open it will be opened. - If close_file == TNG_CLOSE_FILE (1) the input_file will be closed after reading the data. Returns 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_read_next_traj_block(tng_trajectory_t tng_data, - tng_close_file_flag close_file); +tng_function_status tng_read_next_traj_block(tng_trajectory_t tng_data); /* Write one (the next) trajectory block to the output_file of tng_data. tng_data is a trajectory data container. tng_data->output_file_path specifies which file to write to. If the file (output_file) is not open it will be opened. - If close_file == TNG_CLOSE_FILE (1) the output_file will be closed after writing the data. Returns 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_write_next_traj_block(tng_trajectory_t tng_data, - tng_close_file_flag close_file); +tng_function_status tng_write_next_traj_block(tng_trajectory_t tng_data); /* Read one trajectory block from the input_file of tng_data. tng_data is a trajectory data container. tng_data->input_file_path specifies which file to read from. If the file (input_file) is not open it will be opened. block_id is the ID of the block to read. - If close_file == TNG_CLOSE_FILE (1) the input_file will be closed after reading the data. Returns 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_read_traj_block(tng_trajectory_t tng_data, - int64_t block_id, - tng_close_file_flag close_file); + int64_t block_id); /* Write one trajectory block to the output_file of tng_data. tng_data is a trajectory data container. tng_data->output_file_path specifies which file to write to. If the file (output_file) is not open it will be opened. block_id is the ID of the block to write. - If close_file == TNG_CLOSE_FILE (1) the output_file will be closed after writing the data. Returns 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_write_traj_block(tng_trajectory_t tng_data, - int64_t block_id, - tng_close_file_flag close_file); + int64_t block_id); /* Read a requested frame set. tng_data is a trajectory data container. tng_data->current_trajectory_frame_set @@ -706,49 +686,41 @@ tng_function_status tng_read_frame_set_nr(tng_trajectory_t tng_data, tng_data is a trajectory data container. tng_data->input_file_path specifies which file to read from. If the file (input_file) is not open it will be opened. frame_nr is the index number of the frame to read. - If close_file == TNG_CLOSE_FILE (1) the input_file will be closed after reading the data. Returns 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_read_frame_nr(tng_trajectory_t tng_data, - int64_t frame_nr, - const tng_close_file_flag close_file); + int64_t frame_nr); /* Write one trajectory frame to the output_file of tng_data. tng_data is a trajectory data container. tng_data->output_file_path specifies which file to write to. If the file (output_file) is not open it will be opened. frame_nr is the index number of the frame to write. - If close_file == TNG_CLOSE_FILE (1) the output_file will be closed after writing the data. Returns 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_write_frame_nr(tng_trajectory_t tng_data, - int64_t frame_nr, - const tng_close_file_flag close_file); + int64_t frame_nr); /* Read a number of consecutive trajectory frames from the input_file of tng_data. tng_data is a trajectory data container. tng_data->input_file_path specifies which file to read from. If the file (input_file) is not open it will be opened. start_frame_nr is the index number of the first frame to read. end_frame_nr is the index number of the last frame to read. - If close_file == TNG_CLOSE_FILE (1) the input_file will be closed after reading the data. Returns 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_read_frame_nrs(tng_trajectory_t tng_data, int64_t start_frame_nr, - int64_t end_frame_nr, - const tng_close_file_flag close_file); + int64_t end_frame_nr); /* Write a number of consecutive trajectory frames to the output_file of tng_data. tng_data is a trajectory data container. tng_data->output_file_path specifies which file to write to. If the file (input_file) is not open it will be opened. start_frame_nr is the index number of the first frame to write. end_frame_nr is the index number of the last frame to write. - If close_file == TNG_CLOSE_FILE (1) the output_file will be closed after writing the data. Returns 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_write_frame_nrs(tng_trajectory_t tng_data, int64_t start_frame_nr, - int64_t end_frame_nr, - const tng_close_file_flag close_file); + int64_t end_frame_nr); /* Get the date and time of initial file creation in ISO format (string). tng_data is a trajectory data container. diff --git a/src/tests/tng_io_testing.c b/src/tests/tng_io_testing.c index 4bb982a..7ee3628 100644 --- a/src/tests/tng_io_testing.c +++ b/src/tests/tng_io_testing.c @@ -99,12 +99,12 @@ static tng_function_status tng_test_read_and_write_file { tng_function_status stat; - stat = tng_read_file_headers(traj, TNG_KEEP_FILE_OPEN, TNG_USE_HASH); + stat = tng_read_file_headers(traj, TNG_USE_HASH); if(stat == TNG_CRITICAL) { return(stat); } - stat = tng_write_file_headers(traj, TNG_KEEP_FILE_OPEN, TNG_USE_HASH); + stat = tng_write_file_headers(traj, TNG_USE_HASH); if(stat == TNG_CRITICAL) { return(stat); @@ -113,12 +113,12 @@ static tng_function_status tng_test_read_and_write_file while(stat != TNG_CRITICAL && traj->input_file_pos < traj->input_file_len && traj->current_trajectory_frame_set.next_frame_set_file_pos != -1UL) { - stat = tng_read_next_frame_set(traj, TNG_KEEP_FILE_OPEN, TNG_USE_HASH); + stat = tng_read_next_frame_set(traj, TNG_USE_HASH); if(stat == TNG_CRITICAL) { return(stat); } - stat = tng_write_frame_set(traj, TNG_KEEP_FILE_OPEN, TNG_USE_HASH); + stat = tng_write_frame_set(traj, TNG_USE_HASH); } return(stat); @@ -148,7 +148,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj) return(TNG_CRITICAL); } - if(tng_write_file_headers(traj, TNG_KEEP_FILE_OPEN, TNG_SKIP_HASH) == TNG_CRITICAL) + if(tng_write_file_headers(traj, TNG_SKIP_HASH) == TNG_CRITICAL) { return(TNG_CRITICAL); } @@ -227,7 +227,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj) free(data); return(TNG_CRITICAL); } - if(tng_write_frame_set(traj, TNG_KEEP_FILE_OPEN, TNG_SKIP_HASH) != TNG_SUCCESS) + if(tng_write_frame_set(traj, TNG_SKIP_HASH) != TNG_SUCCESS) { printf("Error writing frame set. %s: %d\n", __FILE__, __LINE__); free(molpos); @@ -248,12 +248,12 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj) tng_destroy_trajectory(traj); tng_set_input_file(traj, "/tmp/tng_test.tng"); - stat = tng_read_file_headers(traj, TNG_KEEP_FILE_OPEN, TNG_SKIP_HASH); + stat = tng_read_file_headers(traj, TNG_SKIP_HASH); while(stat != TNG_CRITICAL && traj->input_file_pos < traj->input_file_len && traj->current_trajectory_frame_set.next_frame_set_file_pos != -1ULL) { - stat = tng_read_next_frame_set(traj, TNG_KEEP_FILE_OPEN, TNG_SKIP_HASH); + stat = tng_read_next_frame_set(traj, TNG_SKIP_HASH); if(stat == TNG_CRITICAL) { return(stat); |