1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-08 20:33:36 +01:00

fix file reopening for writing new variables

This commit is contained in:
q-posev 2021-06-02 20:19:39 +02:00
parent 093692c785
commit 693f8d3846

View File

@ -98,8 +98,8 @@ trexio_hdf5_init (trexio_t* const file)
f->file_id = H5Fopen(file->file_name, H5F_ACC_RDONLY, H5P_DEFAULT); f->file_id = H5Fopen(file->file_name, H5F_ACC_RDONLY, H5P_DEFAULT);
break; break;
case 'w': case 'w':
// writing the existing file -> overwrite it (_TRUNC) [_EXCL | H5F_ACC_DEBUG as an alternative] // writing the existing file -> open as RDWRITE
f->file_id = H5Fcreate(file->file_name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); f->file_id = H5Fopen(file->file_name, H5F_ACC_RDWR, H5P_DEFAULT);
break; break;
} }
@ -123,7 +123,11 @@ trexio_hdf5_init (trexio_t* const file)
f->$group$_group = H5Gopen(f->file_id, $GROUP$_GROUP_NAME, H5P_DEFAULT); f->$group$_group = H5Gopen(f->file_id, $GROUP$_GROUP_NAME, H5P_DEFAULT);
break; break;
case 'w': case 'w':
f->$group$_group = H5Gcreate(f->file_id, $GROUP$_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (f_exists == 1) {
f->$group$_group = H5Gopen(f->file_id, $GROUP$_GROUP_NAME, H5P_DEFAULT);
} else {
f->$group$_group = H5Gcreate(f->file_id, $GROUP$_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}
break; break;
} }
if (f->$group$_group <= 0L) return TREXIO_INVALID_ID; if (f->$group$_group <= 0L) return TREXIO_INVALID_ID;