1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-23 04:43:57 +01:00

Add calls to HDF5 back end; overwrite determinant_num

This commit is contained in:
q-posev 2022-04-11 16:32:23 +02:00
parent 7d640b06dd
commit a3f70336d7

View File

@ -4171,7 +4171,7 @@ trexio_read_determinant_list (trexio_t* const file, const int64_t offset_file, i
case TREXIO_HDF5: case TREXIO_HDF5:
#ifdef HAVE_HDF5 #ifdef HAVE_HDF5
rc = -1; //trexio_hdf5_read_determinant_list(file, offset_file, rank, dims, &eof_read_size, dset); rc = trexio_hdf5_read_determinant_list(file, offset_file, rank, dims, &eof_read_size, dset);
break; break;
#else #else
rc = TREXIO_BACK_END_MISSING; rc = TREXIO_BACK_END_MISSING;
@ -4225,12 +4225,12 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
switch (file->back_end) { switch (file->back_end) {
case TREXIO_TEXT: case TREXIO_TEXT:
return trexio_text_write_determinant_list(file, offset_file, rank, dims, dset); rc = trexio_text_write_determinant_list(file, offset_file, rank, dims, dset);
break; break;
case TREXIO_HDF5: case TREXIO_HDF5:
#ifdef HAVE_HDF5 #ifdef HAVE_HDF5
return -1; //trexio_hdf5_write_determinant_list(file, dset, rank, dims); rc = trexio_hdf5_write_determinant_list(file, offset_file, rank, dims, dset);
break; break;
#else #else
return TREXIO_BACK_END_MISSING; return TREXIO_BACK_END_MISSING;
@ -4238,11 +4238,36 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
#endif #endif
/* /*
case TREXIO_JSON: case TREXIO_JSON:
return trexio_json_read_ rc = trexio_json_read_
break; break;
,*/ ,*/
} }
if (rc != TREXIO_SUCCESS) return rc;
/* Update the determinant_num value with the number of determinants written */
int64_t det_num = 0L;
/* Read the determinant_num if it exists already */
if (trexio_has_determinant_num(file) == TREXIO_SUCCESS) {
rc = trexio_read_determinant_num_64(file, &det_num);
if (rc != TREXIO_SUCCESS) return rc;
}
/* Check for the INT64 overflow before writing an updated value */
if (INT64_MAX - det_num > buffer_size) {
det_num += buffer_size;
} else {
return TREXIO_INT_SIZE_OVERFLOW;
}
/* Overwrite previous value. Here we have to temporarily set the file->mode to 'u' to trick the API
in order to overwrite existing determinant_num. Otherwise the API returns TREXIO_NUM_ALREADY_EXISTS.
*/
char mode_tmp = file->mode;
file->mode = 'u';
rc = trexio_write_determinant_num_64(file, det_num);
file->mode = mode_tmp
if (rc != TREXIO_SUCCESS) return rc;
return TREXIO_SUCCESS;
} }
#+end_src #+end_src
@ -4263,7 +4288,7 @@ trexio_has_determinant_list (trexio_t* const file)
case TREXIO_HDF5: case TREXIO_HDF5:
#ifdef HAVE_HDF5 #ifdef HAVE_HDF5
return -1; //trexio_hdf5_has_determinant_list(file); return trexio_hdf5_has_determinant_list(file);
#else #else
return TREXIO_BACK_END_MISSING; return TREXIO_BACK_END_MISSING;
#endif #endif