mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-04-29 03:44:45 +02:00
implement shift of sparse indices to be one-based in Fortran
This commit is contained in:
parent
02a1350893
commit
7afb53be49
@ -2424,11 +2424,11 @@ trexio_exit_code trexio_write_$group_dset$(trexio_t* const file, const int64_t o
|
|||||||
#+begin_src c :tangle read_dset_sparse_front.c
|
#+begin_src c :tangle read_dset_sparse_front.c
|
||||||
trexio_exit_code
|
trexio_exit_code
|
||||||
trexio_read_$group_dset$(trexio_t* const file,
|
trexio_read_$group_dset$(trexio_t* const file,
|
||||||
const int64_t offset_file,
|
const int64_t offset_file,
|
||||||
const int64_t buffer_size,
|
const int64_t buffer_size,
|
||||||
int32_t* const index_sparse,
|
int32_t* const index_sparse,
|
||||||
double* const value_sparse
|
double* const value_sparse
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||||
if (offset_file < 0L) return TREXIO_INVALID_ARG_2;
|
if (offset_file < 0L) return TREXIO_INVALID_ARG_2;
|
||||||
@ -2446,20 +2446,21 @@ trexio_read_$group_dset$(trexio_t* const file,
|
|||||||
rc = trexio_read_$group_dset$_size(file, &size_max);
|
rc = trexio_read_$group_dset$_size(file, &size_max);
|
||||||
if (rc != TREXIO_SUCCESS) return rc;
|
if (rc != TREXIO_SUCCESS) return rc;
|
||||||
/* Cannot read more data points than there is already in the file */
|
/* Cannot read more data points than there is already in the file */
|
||||||
|
// TODO: YOU CAN AND WILL REACH EOF SO NO PROBLEM
|
||||||
if (buffer_size > size_max) return TREXIO_INVALID_ARG_3;
|
if (buffer_size > size_max) return TREXIO_INVALID_ARG_3;
|
||||||
|
|
||||||
switch (file->back_end) {
|
switch (file->back_end) {
|
||||||
|
|
||||||
case TREXIO_TEXT:
|
case TREXIO_TEXT:
|
||||||
return trexio_text_read_$group_dset$(file, offset_file, buffer_size, size_max, index_sparse, value_sparse);
|
rc = trexio_text_read_$group_dset$(file, offset_file, buffer_size, size_max, index_sparse, value_sparse);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREXIO_HDF5:
|
case TREXIO_HDF5:
|
||||||
#ifdef HAVE_HDF5
|
#ifdef HAVE_HDF5
|
||||||
return trexio_hdf5_read_$group_dset$(file, offset_file, buffer_size, size_max, index_sparse, value_sparse);
|
rc = trexio_hdf5_read_$group_dset$(file, offset_file, buffer_size, size_max, index_sparse, value_sparse);
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
return TREXIO_BACK_END_MISSING;
|
rc = TREXIO_BACK_END_MISSING;
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
case TREXIO_JSON:
|
case TREXIO_JSON:
|
||||||
@ -2467,8 +2468,24 @@ trexio_read_$group_dset$(trexio_t* const file,
|
|||||||
break;
|
break;
|
||||||
,*/
|
,*/
|
||||||
default:
|
default:
|
||||||
return TREXIO_FAILURE; /* Impossible case */
|
rc = TREXIO_FAILURE; /* Impossible case */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rc != TREXIO_SUCCESS) return rc;
|
||||||
|
|
||||||
|
// shift indices to be one-based if Fortran API is used
|
||||||
|
// TODO :
|
||||||
|
// THIS WILL SHIFT ALL INDICES, HOWEVER IF EOF IS ENCOUNTERED THIS IS NOT DESIRABLE
|
||||||
|
// WE CAN MODIFY BY ADDRESS AND INT VALUE INDICATING THE NUMBER OF INTEGRALS READ BEFORE EOF
|
||||||
|
// AND ONLY SHIFT THEM !
|
||||||
|
if (file->one_based) {
|
||||||
|
uint64_t index_size = 4L*buffer_size;
|
||||||
|
for (uint64_t i=0; i<index_size; ++i){
|
||||||
|
index_sparse[i] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TREXIO_SUCCESS;
|
||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
@ -2530,27 +2547,46 @@ trexio_write_$group_dset$(trexio_t* const file,
|
|||||||
if (rc != TREXIO_SUCCESS && rc != TREXIO_DSET_MISSING) return rc;
|
if (rc != TREXIO_SUCCESS && rc != TREXIO_DSET_MISSING) return rc;
|
||||||
if (rc == TREXIO_DSET_MISSING) size_max = 0L;
|
if (rc == TREXIO_DSET_MISSING) size_max = 0L;
|
||||||
|
|
||||||
|
int32_t* index_sparse_p = (int32_t*) index_sparse;
|
||||||
|
// shift indices to be zero-based if Fortran API is used
|
||||||
|
if (file->one_based) {
|
||||||
|
|
||||||
|
uint64_t index_size = 4L*buffer_size;
|
||||||
|
index_sparse_p = CALLOC(index_size, int32_t);
|
||||||
|
if (index_sparse_p == NULL) return TREXIO_ALLOCATION_FAILED;
|
||||||
|
|
||||||
|
for (uint64_t i=0; i<index_size; ++i){
|
||||||
|
index_sparse_p[i] = index_sparse[i] - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
switch (file->back_end) {
|
switch (file->back_end) {
|
||||||
|
|
||||||
case TREXIO_TEXT:
|
case TREXIO_TEXT:
|
||||||
return trexio_text_write_$group_dset$(file, offset_file, buffer_size, size_max, index_sparse, value_sparse);
|
rc = trexio_text_write_$group_dset$(file, offset_file, buffer_size, size_max, index_sparse_p, value_sparse);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREXIO_HDF5:
|
case TREXIO_HDF5:
|
||||||
#ifdef HAVE_HDF5
|
#ifdef HAVE_HDF5
|
||||||
return trexio_hdf5_write_$group_dset$(file, offset_file, buffer_size, size_max, index_sparse, value_sparse);
|
rc = trexio_hdf5_write_$group_dset$(file, offset_file, buffer_size, size_max, index_sparse_p, value_sparse);
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
return TREXIO_BACK_END_MISSING;
|
rc = TREXIO_BACK_END_MISSING;
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
case TREXIO_JSON:
|
case TREXIO_JSON:
|
||||||
return trexio_json_write_$group_dset$(...);
|
rc = trexio_json_write_$group_dset$(...);
|
||||||
break;
|
break;
|
||||||
*/
|
,*/
|
||||||
default:
|
default:
|
||||||
return TREXIO_FAILURE; /* Impossible case */
|
rc = TREXIO_FAILURE; /* Impossible case */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// free the memory allocated to shift indices to be zero-based
|
||||||
|
if (file->one_based) FREE(index_sparse_p);
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
@ -125,8 +125,8 @@ subroutine test_write(file_name, back_end)
|
|||||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE COORD')
|
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE COORD')
|
||||||
|
|
||||||
rc = trexio_write_nucleus_label(trex_file, label, 5)
|
rc = trexio_write_nucleus_label(trex_file, label, 5)
|
||||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE LABEL')
|
|
||||||
deallocate(label)
|
deallocate(label)
|
||||||
|
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE LABEL')
|
||||||
|
|
||||||
rc = trexio_write_nucleus_point_group(trex_file, sym_str, 32)
|
rc = trexio_write_nucleus_point_group(trex_file, sym_str, 32)
|
||||||
deallocate(sym_str)
|
deallocate(sym_str)
|
||||||
@ -139,7 +139,7 @@ subroutine test_write(file_name, back_end)
|
|||||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX')
|
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX')
|
||||||
|
|
||||||
offset = 0
|
offset = 0
|
||||||
do i = 1, n_buffers
|
do i = 1,n_buffers
|
||||||
rc = trexio_write_mo_2e_int_eri(trex_file, offset, buf_size, &
|
rc = trexio_write_mo_2e_int_eri(trex_file, offset, buf_size, &
|
||||||
index_sparse_mo_2e_int_eri(1,offset+1), &
|
index_sparse_mo_2e_int_eri(1,offset+1), &
|
||||||
value_sparse_mo_2e_int_eri(offset+1))
|
value_sparse_mo_2e_int_eri(offset+1))
|
||||||
@ -287,7 +287,7 @@ subroutine test_read(file_name, back_end)
|
|||||||
if (size_toread == 100) then
|
if (size_toread == 100) then
|
||||||
write(*,*) 'SUCCESS READ SPARSE SIZE'
|
write(*,*) 'SUCCESS READ SPARSE SIZE'
|
||||||
else
|
else
|
||||||
print *, 'FAILURE SPARSE DATA CHECK'
|
print *, 'FAILURE SPARSE SIZE CHECK'
|
||||||
call exit(-1)
|
call exit(-1)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user