From 9494f02e370236d5d86b5e338f3e1f4d7b6cf98d Mon Sep 17 00:00:00 2001 From: q-posev Date: Thu, 4 Mar 2021 09:41:00 +0100 Subject: [PATCH] append on non-existing file should fail --- src/trexio_hdf5.c | 18 +++++++----------- src/trexio_hdf5.org | 16 ++++++---------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/trexio_hdf5.c b/src/trexio_hdf5.c index d99d341..8c46932 100644 --- a/src/trexio_hdf5.c +++ b/src/trexio_hdf5.c @@ -94,11 +94,11 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) { switch (file->mode) { case 'r': - // reading non-existing file -> error - return TREXIO_FAILURE; case 'a': + // reading or appending non-existing file -> error + return TREXIO_FAILURE; case 'w': - // appending or writing non-existing file -> create it + // writing non-existing file -> create it f->file_id = H5Fcreate(file->file_name, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); break; } @@ -107,15 +107,11 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) { /* Create or open groups in the hdf5 file assuming that they exist if file exists */ switch (file->mode) { + // the switch for 'r'/'a' is reached only if file exists case 'r': case 'a': - if (f_exists == 1) { - f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT); - //f->electron_group = H5Gopen(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT); - } else { - f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - //f->electron_group = H5Gcreate(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - } + f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT); + //f->electron_group = H5Gopen(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT); break; case 'w': f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); @@ -375,7 +371,7 @@ trexio_exit_code trexio_hdf5_write_nucleus_num(const trexio_t* file, const uint6 if (nucleus->num != 0) { printf("%ld -> %ld %s \n", num, nucleus->num, - "This variable alreasy exists. Overwriting it is not supported"); + "This variable already exists. Overwriting it is not supported"); trexio_hdf5_free_nucleus(nucleus); return TREXIO_FAILURE; } diff --git a/src/trexio_hdf5.org b/src/trexio_hdf5.org index c37925f..d146d3a 100644 --- a/src/trexio_hdf5.org +++ b/src/trexio_hdf5.org @@ -185,11 +185,11 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) { switch (file->mode) { case 'r': - // reading non-existing file -> error - return TREXIO_FAILURE; case 'a': + // reading or appending non-existing file -> error + return TREXIO_FAILURE; case 'w': - // appending or writing non-existing file -> create it + // writing non-existing file -> create it f->file_id = H5Fcreate(file->file_name, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); break; } @@ -198,15 +198,11 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) { /* Create or open groups in the hdf5 file assuming that they exist if file exists */ switch (file->mode) { + // the switch for 'r'/'a' is reached only if file exists case 'r': case 'a': - if (f_exists == 1) { - f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT); - //f->electron_group = H5Gopen(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT); - } else { - f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - //f->electron_group = H5Gcreate(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - } + f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT); + //f->electron_group = H5Gopen(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT); break; case 'w': f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);