mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-11-03 20:54:07 +01:00
Merge pull request #21 from TREX-CoE/correct-append
Correct append on non-existing file
This commit is contained in:
commit
aa5dd6ea83
10
src/test.c
10
src/test.c
@ -120,15 +120,11 @@ int test_h5read() {
|
|||||||
file2 = trexio_open(file_name2, 'r', TREXIO_HDF5);
|
file2 = trexio_open(file_name2, 'r', TREXIO_HDF5);
|
||||||
assert (file2 == NULL);
|
assert (file2 == NULL);
|
||||||
|
|
||||||
// test appending non-existing file, should create it
|
// test appending non-existing file, should fail and return NULL
|
||||||
const char* file_name3 = "test_append.h5";
|
|
||||||
trexio_t* file3 = NULL;
|
trexio_t* file3 = NULL;
|
||||||
|
|
||||||
file3 = trexio_open(file_name3, 'a', TREXIO_HDF5);
|
file3 = trexio_open(file_name2, 'a', TREXIO_HDF5);
|
||||||
assert (file3 != NULL);
|
assert (file3 == NULL);
|
||||||
|
|
||||||
rc = trexio_close(file3);
|
|
||||||
assert (rc == TREXIO_SUCCESS);
|
|
||||||
|
|
||||||
free(coord);
|
free(coord);
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) {
|
|||||||
|
|
||||||
switch (file->mode) {
|
switch (file->mode) {
|
||||||
case 'r':
|
case 'r':
|
||||||
// reading non-existing file -> error
|
|
||||||
return TREXIO_FAILURE;
|
|
||||||
case 'a':
|
case 'a':
|
||||||
|
// reading or appending non-existing file -> error
|
||||||
|
return TREXIO_FAILURE;
|
||||||
case 'w':
|
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);
|
f->file_id = H5Fcreate(file->file_name, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
break;
|
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 */
|
/* Create or open groups in the hdf5 file assuming that they exist if file exists */
|
||||||
switch (file->mode) {
|
switch (file->mode) {
|
||||||
|
// the switch for 'r'/'a' is reached only if file exists
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'a':
|
case 'a':
|
||||||
if (f_exists == 1) {
|
|
||||||
f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, 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);
|
//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);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
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) {
|
if (nucleus->num != 0) {
|
||||||
printf("%ld -> %ld %s \n", num, nucleus->num,
|
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);
|
trexio_hdf5_free_nucleus(nucleus);
|
||||||
return TREXIO_FAILURE;
|
return TREXIO_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -185,11 +185,11 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) {
|
|||||||
|
|
||||||
switch (file->mode) {
|
switch (file->mode) {
|
||||||
case 'r':
|
case 'r':
|
||||||
// reading non-existing file -> error
|
|
||||||
return TREXIO_FAILURE;
|
|
||||||
case 'a':
|
case 'a':
|
||||||
|
// reading or appending non-existing file -> error
|
||||||
|
return TREXIO_FAILURE;
|
||||||
case 'w':
|
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);
|
f->file_id = H5Fcreate(file->file_name, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
break;
|
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 */
|
/* Create or open groups in the hdf5 file assuming that they exist if file exists */
|
||||||
switch (file->mode) {
|
switch (file->mode) {
|
||||||
|
// the switch for 'r'/'a' is reached only if file exists
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'a':
|
case 'a':
|
||||||
if (f_exists == 1) {
|
|
||||||
f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, 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);
|
//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);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
|
Loading…
Reference in New Issue
Block a user