mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-23 04:43:57 +01:00
Working text back end [to test]
This commit is contained in:
parent
a2fee3164b
commit
aa47ae4c2e
@ -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 */
|
||||
int rc;
|
||||
|
||||
//char buffer[16];
|
||||
char* buffer = CALLOC(line_length+1, char);
|
||||
|
||||
uint64_t count = 0UL;
|
||||
int shift = 0;
|
||||
/* Declare fixed buffer which will be used to read the determinant string <a1 a2 ... a/\ b1 b2 ... b\/> */
|
||||
char buffer[1024];
|
||||
uint32_t buf_size = sizeof(buffer);
|
||||
/* Parameters to post-process the buffer and to get bit fields integers */
|
||||
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;
|
||||
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);
|
||||
FREE(buffer);
|
||||
*eof_read_size = count;
|
||||
,*eof_read_size = count;
|
||||
return TREXIO_END;
|
||||
|
||||
} else {
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
for (int32_t j=0; j<dims[1]; ++j) {
|
||||
rc = sscanf(buffer, "%10" SCNd64 "%n", list + i + j, &shift);
|
||||
,*/
|
||||
for (uint32_t j=0; j < (uint32_t) dims[1]; ++j) {
|
||||
rc = sscanf(buffer+accum, "%10" SCNd64, list + i + j);
|
||||
if(rc <= 0) {
|
||||
fclose(f);
|
||||
FREE(buffer);
|
||||
return TREXIO_FAILURE;
|
||||
}
|
||||
buffer += shift;
|
||||
accum += shift;
|
||||
}
|
||||
|
||||
accum += shift_int64 + 1;
|
||||
count += 1UL;
|
||||
buffer -= accum;
|
||||
}
|
||||
}
|
||||
|
||||
FREE(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the TXT file */
|
||||
rc = fclose(f);
|
||||
|
Loading…
Reference in New Issue
Block a user