mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-04-16 13:49:19 +02:00
Improved text backend
This commit is contained in:
parent
c502a6166d
commit
8bb2c1e179
@ -1704,12 +1704,12 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
|
||||
if (f == NULL) return TREXIO_FILE_ERROR;
|
||||
|
||||
/* Specify the line length in order to offset properly.
|
||||
Each 64-bit integer takes at most 20 slots and requires one space,
|
||||
Each 64-bit integer takes 20 slots and requires one space,
|
||||
we have int_num integers per up-spin determinant,
|
||||
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]*21UL + 1UL; // 20 digits per int64_t bitfield + 1 space = 11 spots + 1 newline char
|
||||
uint64_t line_length = dims[1]*21UL + 1UL; // 20 digits per int64_t bitfield + 1 space = 21 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);
|
||||
@ -1717,7 +1717,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
|
||||
/* Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF */
|
||||
int rc;
|
||||
/* Declare fixed buffer which will be used to read the determinant string <a1 a2 ... a/\ b1 b2 ... b\/> */
|
||||
char buffer[1024];
|
||||
char buffer[line_length+2];
|
||||
uint32_t buf_size = sizeof(buffer);
|
||||
/* Parameters to post-process the buffer and to get bit fields integers */
|
||||
uint64_t accum = 0UL;
|
||||
@ -1729,7 +1729,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
|
||||
accum = 0UL;
|
||||
memset(buffer, 0, buf_size);
|
||||
|
||||
if (fgets(buffer, buf_size-1, f) == NULL){
|
||||
if (fgets(buffer, line_length+1, f) == NULL){
|
||||
|
||||
fclose(f);
|
||||
,*eof_read_size = count;
|
||||
|
@ -178,7 +178,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
int64_t* det_list_read;
|
||||
double* det_coef_read;
|
||||
double check_diff;
|
||||
uint64_t size_r = SIZE;
|
||||
uint64_t size_r = 2*SIZE;
|
||||
|
||||
det_list_read = (int64_t*) calloc(2*int_num*size_r,sizeof(int64_t));
|
||||
det_coef_read = (double*) calloc(size_r,sizeof(double));
|
||||
@ -274,15 +274,17 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
uint64_t offset_f = 0UL;
|
||||
uint64_t offset_d = 0UL;
|
||||
for(int i=0; i<N_CHUNKS; ++i){
|
||||
/*
|
||||
if (i*chunk_size + chunk_size > SIZE) {
|
||||
chunk_size = SIZE % chunk_size;
|
||||
}
|
||||
*/
|
||||
printf("chunk_size: %ld | %ld\n", chunk_size, offset_f+chunk_size);
|
||||
rc = trexio_read_determinant_list(file, offset_f, &chunk_size, &det_list_read[2*int_num*offset_d]);
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
assert(rc == TREXIO_SUCCESS || rc == TREXIO_END);
|
||||
|
||||
rc = trexio_read_determinant_coefficient(file, offset_f, &chunk_size, &det_coef_read[offset_d]);
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
assert(rc == TREXIO_SUCCESS || rc == TREXIO_END);
|
||||
|
||||
offset_d += chunk_size;
|
||||
offset_f += chunk_size;
|
||||
|
@ -660,11 +660,12 @@ subroutine test_read_void(file_name, back_end)
|
||||
integer, intent(in) :: back_end
|
||||
|
||||
integer(trexio_t) :: trex_file
|
||||
integer :: rc = 1
|
||||
integer :: rc
|
||||
character*(128) :: str
|
||||
|
||||
! ================= START OF TEST ===================== !
|
||||
|
||||
rc = TREXIO_SUCCESS
|
||||
trex_file = trexio_open(file_name, 'r', back_end, rc)
|
||||
if (rc /= TREXIO_OPEN_ERROR) then
|
||||
rc = trexio_close(trex_file)
|
||||
|
Loading…
x
Reference in New Issue
Block a user