mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-23 04:43:57 +01:00
append on non-existing file should fail
This commit is contained in:
parent
0328564967
commit
9494f02e37
@ -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