1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-09 20:48:53 +01:00

Working text back end [to test]

This commit is contained in:
q-posev 2022-04-11 13:13:56 +02:00
parent a2fee3164b
commit aa47ae4c2e

View File

@ -1366,48 +1366,42 @@ trexio_exit_code trexio_text_read_determinant_list(
/* Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF */ /* 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; int rc;
/* Declare fixed buffer which will be used to read the determinant string <a1 a2 ... a/\ b1 b2 ... b\/> */
//char buffer[16]; char buffer[1024];
char* buffer = CALLOC(line_length+1, char); uint32_t buf_size = sizeof(buffer);
/* Parameters to post-process the buffer and to get bit fields integers */
uint64_t count = 0UL;
int shift = 0;
uint64_t accum = 0UL; uint64_t accum = 0UL;
for (uint64_t i=0UL; i < (uint64_t) dims[0]; ++i) { uint32_t shift_int64 = 10U;
/* Counter for number of elements beind processed */
uint64_t count = 0UL;
for (uint64_t i=0UL; i < dims[0]; ++i) {
accum = 0UL; accum = 0UL;
memset(buffer, 0, line_length+1); // sizeof(buffer)); //1024); memset(buffer, 0, buf_size);
if(fgets(buffer, line_length, f) == NULL){ if(fgets(buffer, buf_size-1, f) == NULL){
fclose(f); fclose(f);
FREE(buffer); ,*eof_read_size = count;
*eof_read_size = count;
return TREXIO_END; return TREXIO_END;
} else { } else {
/* The format string is not anymore static but rather dynamic (the number of ints depend on the mo_num) /* The format string is not anymore static but rather dynamic (the number of ints depend on the mo_num)
Thus, we parse the buffer string int_num*2 times to get the bit field determinants. 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) {
for (int32_t j=0; j<dims[1]; ++j) { rc = sscanf(buffer+accum, "%10" SCNd64, list + i + j);
rc = sscanf(buffer, "%10" SCNd64 "%n", list + i + j, &shift);
if(rc <= 0) { if(rc <= 0) {
fclose(f); fclose(f);
FREE(buffer);
return TREXIO_FAILURE; return TREXIO_FAILURE;
} }
buffer += shift; accum += shift_int64 + 1;
accum += shift;
}
count += 1UL; count += 1UL;
buffer -= accum;
}
} }
FREE(buffer); }
}
/* Close the TXT file */ /* Close the TXT file */
rc = fclose(f); rc = fclose(f);