1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00

TEXT back end working

This commit is contained in:
q-posev 2022-04-12 00:41:57 +02:00
parent ac41cd6080
commit 738d8de5ca
2 changed files with 13 additions and 14 deletions

View File

@ -4245,28 +4245,27 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
if (rc != TREXIO_SUCCESS) return rc;
/* Update the determinant_num value with the number of determinants written */
// Update the determinant_num value with the number of determinants written
int64_t det_num = 0L;
/* Read the determinant_num if it exists already */
// 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 */
// 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.
*/
// 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
file->mode = mode_tmp;
if (rc != TREXIO_SUCCESS) return rc;
return TREXIO_SUCCESS;
}

View File

@ -1356,7 +1356,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
then this number is doubled because we have the same number for down-spin electrons,
and then one newline char.
,*/
uint64_t line_length = dims[1]*11UL; /* 10 digits per int64_t bitfield + 1 space = 11 spots + (?) 1 newline char
uint64_t line_length = dims[1]*11UL + 1UL; /* 10 digits per int64_t bitfield + 1 space = 11 spots + 1 newline char
/* Offset in the file according to the provided value of offset_file and optimal line_length */
fseek(f, (long) offset_file * line_length, SEEK_SET);
@ -1368,7 +1368,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
uint32_t buf_size = sizeof(buffer);
/* Parameters to post-process the buffer and to get bit fields integers */
uint64_t accum = 0UL;
uint32_t shift_int64 = 10U;
uint32_t shift_int64 = 11U;
/* Counter for number of elements beind processed */
uint64_t count = 0UL;
for (uint64_t i=0UL; i < dims[0]; ++i) {
@ -1379,7 +1379,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
if(fgets(buffer, buf_size-1, f) == NULL){
fclose(f);
,*eof_read_size = count;
*eof_read_size = count;
return TREXIO_END;
} else {
@ -1388,14 +1388,14 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
Thus, we parse the buffer string int_num*2 times to get the bit field determinants.
,*/
for (uint32_t j=0; j < (uint32_t) dims[1]; ++j) {
rc = sscanf(buffer+accum, "%10" SCNd64, list + i + j);
rc = sscanf(buffer+accum, "%10" SCNd64, list + dims[1]*i + j);
if(rc <= 0) {
fclose(f);
return TREXIO_FAILURE;
}
accum += shift_int64 + 1;
count += 1UL;
accum += shift_int64;
}
count += 1UL;
}
}