1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-04-16 13:49:19 +02:00

Removed many warnings + added more checks

This commit is contained in:
Anthony Scemama 2024-11-11 17:26:51 +01:00
parent ff8e44d386
commit cda0ad70a6
4 changed files with 209 additions and 70 deletions

View File

@ -130,7 +130,7 @@ AC_ARG_WITH([hdf5],
AS_HELP_STRING([--with-hdf5=PATH], [Path to HDF5 library and headers]), [
with_hdf5="$withval"], [with_hdf5="yes"])
AS_IF([test "x$with_hdf5" == "xno"], [],
AS_IF([test "x$with_hdf5" == "xno"], [],
[test "x$with_hdf5" != "xyes"], [
HDF5_LIBS="-lhdf5"
HDF5_PATH="$with_hdf5"
@ -311,6 +311,20 @@ AC_CHECK_HEADERS([math.h])
AC_SEARCH_LIBS([pthread_create], [pthread], [], AC_MSG_ERROR([The pthread library is required]))
AC_CHECK_HEADERS([pthread.h])
# Debug flags
AC_ARG_ENABLE(debug, [AS_HELP_STRING([--enable-debug],[enable gcc and gfortran debug flags])], ok=$enableval, ok=no)
if test "$ok" = "yes"; then
CFLAGS="${CFLAGS} -Wall -Wextra -Wpedantic -Werror -Wshadow -Wformat -Wfloat-equal -Wconversion -Wcast-align -Wnull-dereference -Wstrict-aliasing -Winline -Wmissing-prototypes -Wunreachable-code -fstack-protector-strong -fdiagnostics-show-option -Wfloat-conversion -Wcast-qual -fno-inline fno-omit-frame-pointer -Wno-sign-conversion -Wno-cast-qual" # -Wno-unused-variable"
FCFLAGS="${FCFLAGS} -g -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant -Wuninitialized -fbacktrace -ffpe-trap=zero,overflow -finit-real=nan"
fi
AC_ARG_ENABLE(sanitize, [AS_HELP_STRING([--enable-sanitize],[enable sanitizer debug flags])], ok=$enableval, ok=no)
if test "$ok" = "yes"; then
CFLAGS="${CFLAGS} -fsanitize=address -fsanitize=undefined -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=bounds -fsanitize=bounds-strict"
fi
AC_CONFIG_FILES([Makefile
pkgconfig/trexio.pc])

View File

@ -471,6 +471,12 @@ __trexio_path__ = None
| ~TREXIO_VERSION_PARSING_ISSUE~ | 36 | 'Failed to parse package_version' |
| ~TREXIO_PHASE_CHANGE~ | 37 | 'The function succeeded with a change of sign' |
| ~TREXIO_INVALID_MO_INDEX~ | 38 | 'Invalid MO index' |
| ~TREXIO_INVALID_ARG_9~ | 39 | 'Invalid argument 9' |
| ~TREXIO_INVALID_ARG_10~ | 40 | 'Invalid argument 10' |
| ~TREXIO_INVALID_ARG_11~ | 41 | 'Invalid argument 11' |
| ~TREXIO_INVALID_ARG_12~ | 42 | 'Invalid argument 12' |
| ~TREXIO_INVALID_ARG_13~ | 43 | 'Invalid argument 13' |
| ~TREXIO_INVALID_ARG_14~ | 44 | 'Invalid argument 14' |
# We need to force Emacs not to indent the Python code:
# -*- org-src-preserve-indentation: t
@ -556,6 +562,12 @@ return '\n'.join(result)
#define TREXIO_VERSION_PARSING_ISSUE ((trexio_exit_code) 36)
#define TREXIO_PHASE_CHANGE ((trexio_exit_code) 37)
#define TREXIO_INVALID_MO_INDEX ((trexio_exit_code) 38)
#define TREXIO_INVALID_ARG_9 ((trexio_exit_code) 39)
#define TREXIO_INVALID_ARG_10 ((trexio_exit_code) 40)
#define TREXIO_INVALID_ARG_11 ((trexio_exit_code) 41)
#define TREXIO_INVALID_ARG_12 ((trexio_exit_code) 42)
#define TREXIO_INVALID_ARG_13 ((trexio_exit_code) 43)
#define TREXIO_INVALID_ARG_14 ((trexio_exit_code) 44)
#+end_src
#+begin_src f90 :tangle prefix_fortran.f90 :exports none
@ -599,6 +611,12 @@ return '\n'.join(result)
integer(trexio_exit_code), parameter :: TREXIO_VERSION_PARSING_ISSUE = 36
integer(trexio_exit_code), parameter :: TREXIO_PHASE_CHANGE = 37
integer(trexio_exit_code), parameter :: TREXIO_INVALID_MO_INDEX = 38
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_9 = 39
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_10 = 40
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_11 = 41
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_12 = 42
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_13 = 43
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_14 = 44
#+end_src
#+begin_src python :tangle prefix_python.py :exports none
@ -643,6 +661,12 @@ return '\n'.join(result)
TREXIO_VERSION_PARSING_ISSUE = 36
TREXIO_PHASE_CHANGE = 37
TREXIO_INVALID_MO_INDEX = 38
TREXIO_INVALID_ARG_9 = 39
TREXIO_INVALID_ARG_10 = 40
TREXIO_INVALID_ARG_11 = 41
TREXIO_INVALID_ARG_12 = 42
TREXIO_INVALID_ARG_13 = 43
TREXIO_INVALID_ARG_14 = 44
#+end_src
:end:
@ -1285,11 +1309,9 @@ trexio_open(const char* file_name, const char mode,
}
// assert (irc == 0);
trexio_exit_code rc;
/* Back end initialization */
rc = TREXIO_OPEN_ERROR;
trexio_exit_code rc = TREXIO_OPEN_ERROR;
switch (back_end_local) {
@ -2090,8 +2112,6 @@ trexio_pre_close (trexio_t* file)
if (file == NULL) return TREXIO_FILE_ERROR;
trexio_exit_code rc;
/* Check consistency between number of determinants and coefficients stored in the file */
if (file->version_major >= 2 && file->version_minor >= 2) {
@ -2101,6 +2121,8 @@ trexio_pre_close (trexio_t* file)
int64_t ndet, ncoeff;
if (has_det && has_coeff) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_determinant_num_64(file, &ndet);
if (rc != TREXIO_SUCCESS) return rc;
@ -2120,7 +2142,11 @@ trexio_pre_close (trexio_t* file)
bool has_updn = (trexio_has_electron_num(file) == TREXIO_SUCCESS);
if (file->mode != 'r') {
if (has_updn && has_up && has_dn) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc;
@ -2139,7 +2165,11 @@ trexio_pre_close (trexio_t* file)
return TREXIO_INVALID_ELECTRON_NUM;
}
}
} else if (has_up && has_dn) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc;
@ -2149,7 +2179,11 @@ trexio_pre_close (trexio_t* file)
nelec = nup + ndn;
rc = trexio_write_electron_num(file, nelec);
if (rc != TREXIO_SUCCESS) return rc;
} else if (has_up) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc;
@ -2160,7 +2194,11 @@ trexio_pre_close (trexio_t* file)
nelec = nup;
rc = trexio_write_electron_num(file, nelec);
if (rc != TREXIO_SUCCESS) return rc;
} else if (has_dn) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_electron_dn_num(file, &ndn);
if (rc != TREXIO_SUCCESS) return rc;
@ -2171,6 +2209,7 @@ trexio_pre_close (trexio_t* file)
nelec = ndn;
rc = trexio_write_electron_num(file, nelec);
if (rc != TREXIO_SUCCESS) return rc;
}
}
@ -2792,9 +2831,10 @@ trexio_read_$group_dset$_64 (trexio_t* const file, $group_dset_dtype_double$* co
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -2855,10 +2895,9 @@ trexio_write_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_doub
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_DSET_ALREADY_EXISTS;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -2952,9 +2991,10 @@ trexio_read_$group_dset$_32 (trexio_t* const file, $group_dset_dtype_single$* co
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -3026,9 +3066,10 @@ trexio_write_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_sing
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_DSET_ALREADY_EXISTS;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -3092,9 +3133,11 @@ trexio_write_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_sing
#+NAME:dimCheck
#+begin_src c
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
(void) rc; // Avoids unused parameter error for scalar variables
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -3578,6 +3621,12 @@ trexio_exit_code trexio_read_safe_$group_dset$(trexio_t* const file,
const int64_t size_value_read
)
{
/* To be set by generator : number of indices */
const uint32_t rank = $group_dset_rank$;
if (size_index_read < rank * (*buffer_size_read)) return TREXIO_INVALID_ARG_5;
if (size_value_read < (*buffer_size_read)) return TREXIO_INVALID_ARG_7;
return trexio_read_$group_dset$(file, offset_file, buffer_size_read, index_sparse_read, value_sparse_read);
}
@ -3599,10 +3648,9 @@ trexio_read_$group_dset$(trexio_t* const file,
const uint32_t rank = $group_dset_rank$; // To be set by generator : number of indices
int64_t size_max; // Max number of integrals (already in the file)
trexio_exit_code rc;
/* Read the max number of integrals stored in the file */
rc = trexio_read_$group_dset$_size(file, &size_max);
trexio_exit_code rc = trexio_read_$group_dset$_size(file, &size_max);
if (rc != TREXIO_SUCCESS) return rc;
/* To be set by generator : number of unique dimensions
@ -3710,6 +3758,12 @@ trexio_exit_code trexio_write_safe_$group_dset$(trexio_t* const file,
const int64_t size_value_write
)
{
/* To be set by generator : number of indices */
const uint32_t rank = $group_dset_rank$;
if (size_index_write < rank * buffer_size) return TREXIO_INVALID_ARG_5;
if (size_value_write < buffer_size) return TREXIO_INVALID_ARG_7;
return trexio_write_$group_dset$(file, offset_file, buffer_size, index_sparse_write, value_sparse_write);
}
@ -3731,10 +3785,9 @@ trexio_write_$group_dset$(trexio_t* const file,
const uint32_t rank = $group_dset_rank$;
int64_t size_max = 0L; // Max number of integrals (already in the file)
trexio_exit_code rc;
/* Read the max number of integrals stored in the file */
rc = trexio_read_$group_dset$_size(file, &size_max);
trexio_exit_code rc = trexio_read_$group_dset$_size(file, &size_max);
if (rc != TREXIO_SUCCESS && rc != TREXIO_DSET_MISSING) return rc;
if (rc == TREXIO_DSET_MISSING) size_max = 0L;
@ -4182,11 +4235,10 @@ trexio_read_$group_dset$_low (trexio_t* const file, char* dset_out, const int32_
if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
trexio_exit_code rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
@ -4225,11 +4277,10 @@ trexio_read_$group_dset$ (trexio_t* const file, char** dset_out, const int32_t m
assert(file->back_end < TREXIO_INVALID_BACK_END);
trexio_exit_code rc;
int64_t dset_dim = 0;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
trexio_exit_code rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
if (dset_dim == 0L) return TREXIO_INVALID_NUM;
@ -4272,11 +4323,10 @@ trexio_write_$group_dset$_low (trexio_t* const file, char* dset_in, const int32_
if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_DSET_ALREADY_EXISTS;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
trexio_exit_code rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
@ -4358,11 +4408,10 @@ trexio_write_$group_dset$ (trexio_t* const file, const char** dset_in, const int
assert(file->back_end < TREXIO_INVALID_BACK_END);
trexio_exit_code rc;
int64_t dset_dim = 0;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
trexio_exit_code rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
if (dset_dim == 0L) return TREXIO_INVALID_NUM;
@ -4631,7 +4680,7 @@ trexio_read_$group_dset$ (trexio_t* const file, const int64_t offset_file, int64
if (dset == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
trexio_exit_code rc;
trexio_exit_code rc = TREXIO_FAILURE;
uint32_t rank = 1;
uint64_t det_size = (uint64_t) (*buffer_size_read);
@ -4660,8 +4709,8 @@ trexio_read_$group_dset$ (trexio_t* const file, const int64_t offset_file, int64
break;
,*/
default:
rc = TREXIO_FAILURE; /* Impossible case */
break;
rc = TREXIO_FAILURE;
break; /* Impossible case */
}
if (rc != TREXIO_SUCCESS && rc != TREXIO_END) return rc;
@ -4755,6 +4804,9 @@ trexio_write_$group_dset$ (trexio_t* const file, const int64_t offset_file, cons
trexio_exit_code
trexio_write_safe_$group_dset$ (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const double* dset_in, const int64_t dim_in)
{
/* Check that dim_in is large enough */
if (dim_in < buffer_size) return TREXIO_INVALID_ARG_5;
return trexio_write_$group_dset$(file, offset_file, buffer_size, dset_in);
}
#+end_src
@ -5388,7 +5440,7 @@ trexio_get_int64_num(trexio_t* const file, int32_t* const num)
/* Compute how many integer numbers is needed to represent a determinant */
int32_t int_num = 0;
int_num = (mo_num - 1L)/64 + 1;
int_num = (int32_t) (mo_num - 1L)/64 + 1;
*num = int_num;
@ -5456,6 +5508,14 @@ trexio_read_determinant_list (trexio_t* const file, const int64_t offset_file, i
trexio_exit_code
trexio_read_safe_determinant_list (trexio_t* const file, const int64_t offset_file, int64_t* const buffer_size_read, int64_t* const dset_out, const int64_t dim_out)
{
/* Get the number of int bit fields per determinant */
int32_t int_num = 0;
trexio_exit_code rc = trexio_get_int64_num(file, &int_num);
if (rc != TREXIO_SUCCESS) return rc;
/* Check that dset_out is large enough */
if (dim_out < (*buffer_size_read) * int_num * 2) return TREXIO_INVALID_ARG_5;
return trexio_read_determinant_list(file, offset_file, buffer_size_read, dset_out);
}
#+end_src
@ -5504,7 +5564,7 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
int32_t occ_num_up = 0;
int32_t occ_num_dn = 0;
/* list_up contains first the up-spin orbitals, then the down-spin
/* list_up contains first the up-spin orbitals, then the down-spin */
int32_t* list_up = (int32_t*) calloc(nup+ndn,sizeof(int32_t));
if (list_up == NULL) {
@ -5591,6 +5651,14 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
trexio_exit_code
trexio_write_safe_determinant_list (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const int64_t* dset_in, const int64_t dim_in)
{
/* Get the number of int bit fields per determinant */
int32_t int_num = 0;
trexio_exit_code rc = trexio_get_int64_num(file, &int_num);
if (rc != TREXIO_SUCCESS) return rc;
/* Check that dim_in is large enough */
if (dim_in < buffer_size * int_num * 2) return TREXIO_INVALID_ARG_5;
return trexio_write_determinant_list(file, offset_file, buffer_size, dset_in);
}
#+end_src
@ -6052,10 +6120,8 @@ trexio_exit_code trexio_to_orbital_list_up_dn(const int32_t N_int,
if (occ_num_up == NULL) return TREXIO_INVALID_ARG_5;
if (occ_num_dn == NULL) return TREXIO_INVALID_ARG_6;
trexio_exit_code rc;
/* First process up-spin electrons */
rc = trexio_to_orbital_list(N_int, &d1[0], list_up, occ_num_up);
trexio_exit_code rc = trexio_to_orbital_list(N_int, &d1[0], list_up, occ_num_up);
if (rc != TREXIO_SUCCESS) return rc;
/* Now process down-spin electrons */
@ -6075,6 +6141,14 @@ trexio_safe_to_orbital_list (const int32_t N_int,
const int64_t dim_out,
int32_t* const num)
{
if (dim_in < N_int) return TREXIO_INVALID_ARG_3;
/* Count number of up electrons in first bitfield */
int count = 0;
for (int i=0 ; i<N_int; i++) {
count += popcnt(dset_in[i]);
}
if (dim_out < count) return TREXIO_INVALID_ARG_5;
return trexio_to_orbital_list(N_int, dset_in, dset_out, num);
}
@ -6089,6 +6163,21 @@ trexio_safe_to_orbital_list_up_dn (const int32_t N_int,
int32_t* const num_up,
int32_t* const num_dn)
{
if (dim_in < 2*N_int) return TREXIO_INVALID_ARG_3;
/* Count number of up electrons in first bitfield */
int count = 0;
for (int i=0 ; i<N_int; i++) {
count += popcnt(dset_in[i]);
}
if (dim_up_out < count) return TREXIO_INVALID_ARG_5;
/* Count number of up electrons in second bitfield */
count = 0;
for (int i=N_int ; i<2*N_int; i++) {
count += popcnt(dset_in[i]);
}
if (dim_dn_out < count) return TREXIO_INVALID_ARG_7;
return trexio_to_orbital_list_up_dn(N_int, dset_in, dset_up_out, dset_dn_out, num_up, num_dn);
}
#+end_src
@ -6097,23 +6186,22 @@ trexio_safe_to_orbital_list_up_dn (const int32_t N_int,
trexio_exit_code
trexio_convert_nao_radius_32 (const float r, const float* const grid_r, float* const log_r_out)
{
if (r < 0) return TREXIO_INVALID_ARG_1;
if (r <= 0.) return TREXIO_INVALID_ARG_1;
if (grid_r == NULL) return TREXIO_INVALID_ARG_2;
if (log_r_out == NULL) return TREXIO_INVALID_ARG_3;
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
,*log_r_out = (float) log((double) r / grid_r[0]) / log((double) grid_r[1] / grid_r[0]);
return TREXIO_SUCCESS;
}
trexio_exit_code
trexio_convert_nao_radius_64 (const double r, const double* const grid_r, double* const log_r_out)
{
if (r < 0) return TREXIO_INVALID_ARG_1;
if (r <= 0.) return TREXIO_INVALID_ARG_1;
if (grid_r == NULL) return TREXIO_INVALID_ARG_2;
if (log_r_out == NULL) return TREXIO_INVALID_ARG_3;
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
,*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
return TREXIO_SUCCESS;
}
@ -6121,11 +6209,12 @@ trexio_convert_nao_radius_64 (const double r, const double* const grid_r, double
trexio_exit_code
trexio_convert_nao_radius_py (const double r, double* grid_r, int32_t n_grid, double* const log_r_out)
{
if (r < 0) return TREXIO_INVALID_ARG_1;
if (r <= 0.) return TREXIO_INVALID_ARG_1;
if (grid_r == NULL) return TREXIO_INVALID_ARG_2;
if (log_r_out == NULL) return TREXIO_INVALID_ARG_3;
if (n_grid < 2) return TREXIO_INVALID_ARG_3;
if (log_r_out == NULL) return TREXIO_INVALID_ARG_4;
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
,*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
return TREXIO_SUCCESS;
}
@ -6145,12 +6234,12 @@ trexio_evaluate_nao_radial (const int32_t shell_index, const double r, const int
if (interpolator == 0) return TREXIO_INVALID_ARG_6;
if (normalization == 0) return TREXIO_INVALID_ARG_7;
const int32_t i0 = 4*grid_start[shell_index];
const int64_t i0 = 4*grid_start[shell_index];
// Convert radius to logarithmic units
double r_log = 0.0;
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
int32_t i_log = (int32_t) r_log;
int64_t i_log = (int64_t) r_log;
if (i_log < 0)
i_log = 0;
else if (i_log >= grid_size[shell_index])
@ -6162,7 +6251,7 @@ trexio_evaluate_nao_radial (const int32_t shell_index, const double r, const int
val_spline += t * t * interpolator[i0 + 4*i_log + 2];
val_spline += t * t * t * interpolator[i0 + 4*i_log + 3];
*amplitude = val_spline * normalization[shell_index] / r;
,*amplitude = val_spline * normalization[shell_index] / r;
return TREXIO_SUCCESS;
}
@ -6180,8 +6269,6 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
if (interpolator == 0) return TREXIO_INVALID_ARG_7;
if (normalization == 0) return TREXIO_INVALID_ARG_8;
trexio_exit_code rc;
for (int shell_index = 0; shell_index < shell_num; shell_index++) {
const int32_t nuc_index = nucleus_index[shell_index];
const double dx = nucleus_coords[3*nuc_index + 0] - rx;
@ -6190,7 +6277,7 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
const double r = sqrt(dx*dx + dy*dy + dz*dz);
// All possibly reported errors have been caught above
rc = trexio_evaluate_nao_radial(shell_index, r, grid_start,
trexio_exit_code rc = trexio_evaluate_nao_radial(shell_index, r, grid_start,
grid_size, grid_r, interpolator, normalization, &amplitude[shell_index]);
if (rc != TREXIO_SUCCESS)
@ -6203,39 +6290,47 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
const double r, int64_t* grid_start, int n_grid_st,
int64_t* grid_size, int n_grid_si, double* grid_r, int n_grid_r,
double* interpolator, int n_interp, double* normalization, int n_norm, double* const amplitude)
double* interpolator, int n_interp, double* normalization, int n_norm,
double* const amplitude)
{
// Code needs to be copied because of the use of int64_t mandated by Python
// If a 64-bit version is implemented, this can be avoided
if (shell_index < 0) return TREXIO_INVALID_ARG_1;
if (r < 0) return TREXIO_INVALID_ARG_2;
if (grid_start == 0) return TREXIO_INVALID_ARG_3;
if (grid_size == 0) return TREXIO_INVALID_ARG_4;
if (grid_r == NULL) return TREXIO_INVALID_ARG_5;
if (interpolator == 0) return TREXIO_INVALID_ARG_6;
if (normalization == 0) return TREXIO_INVALID_ARG_7;
if (n_grid_st < shell_index) return TREXIO_INVALID_ARG_4;
if (grid_size == 0) return TREXIO_INVALID_ARG_5;
if (n_grid_si < shell_index) return TREXIO_INVALID_ARG_6;
if (grid_r == NULL) return TREXIO_INVALID_ARG_7;
if (n_grid_r < grid_start[shell_index]) return TREXIO_INVALID_ARG_8;
if (interpolator == NULL) return TREXIO_INVALID_ARG_9;
if (normalization == 0) return TREXIO_INVALID_ARG_11;
if (n_norm < shell_index) return TREXIO_INVALID_ARG_12;
const int32_t i0 = 4*grid_start[shell_index];
const int64_t i0 = 4*grid_start[shell_index];
if (n_interp < i0) return TREXIO_INVALID_ARG_10;
// Convert radius to logarithmic units
double r_log = 0.0;
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
int32_t i_log = (int32_t) r_log;
int64_t i_log = (int64_t) r_log;
if (i_log < 0) {
*amplitude = interpolator[i0] * normalization[shell_index] / r;
,*amplitude = interpolator[i0] * normalization[shell_index] / r;
return TREXIO_SUCCESS;
} else if (i_log >= grid_size[shell_index]) {
*amplitude = 0.0;
,*amplitude = 0.0;
return TREXIO_SUCCESS; // NAOs vanish at the boundary by definition
}
double t = r_log - (double) i_log;
if (n_interp < i0+4*i_log+3) return TREXIO_INVALID_ARG_10;
double val_spline = interpolator[i0 + 4*i_log + 0];
val_spline += t * interpolator[i0 + 4*i_log + 1];
val_spline += t * t * interpolator[i0 + 4*i_log + 2];
val_spline += t * t * t * interpolator[i0 + 4*i_log + 3];
*amplitude = val_spline * normalization[shell_index] / r;
,*amplitude = val_spline * normalization[shell_index] / r;
return TREXIO_SUCCESS;
}
@ -6244,29 +6339,37 @@ trexio_exit_code trexio_evaluate_nao_radial_all_py (const int32_t shell_num,
int64_t* grid_start, int n_grid_st, int64_t* grid_size, int n_grid_si,
double* grid_r, int n_grid_r, double* interpolator, int n_interp,
double* normalization, int n_norm,
const double rx, const double ry, const double rz, double* const amplitudes, int amplitude_cnt)
const double rx, const double ry, const double rz,
double* const amplitudes, int amplitude_cnt)
{
if (shell_num < 0) return TREXIO_INVALID_ARG_1;
if (nucleus_index == 0) return TREXIO_INVALID_ARG_2;
if (nucleus_coords == 0) return TREXIO_INVALID_ARG_3;
if (grid_start == 0) return TREXIO_INVALID_ARG_4;
if (grid_size == 0) return TREXIO_INVALID_ARG_5;
if (grid_r == NULL) return TREXIO_INVALID_ARG_6;
if (interpolator == 0) return TREXIO_INVALID_ARG_7;
if (normalization == 0) return TREXIO_INVALID_ARG_8;
if (nucleus_index == NULL) return TREXIO_INVALID_ARG_2;
if (nucleus_coords == NULL) return TREXIO_INVALID_ARG_4;
if (grid_start == NULL) return TREXIO_INVALID_ARG_6;
if (grid_size == NULL) return TREXIO_INVALID_ARG_8;
if (grid_r == NULL) return TREXIO_INVALID_ARG_10;
if (interpolator == NULL) return TREXIO_INVALID_ARG_12;
if (normalization == NULL) return TREXIO_INVALID_ARG_14;
trexio_exit_code rc;
assert (amplitudes != NULL); // 19 arguments!!! Don't want to make TREXIO_INVALID_ARG_19
assert (amplitude_cnt > shell_num);
if (n_nuc_id < shell_num) return TREXIO_INVALID_ARG_3;
if (n_nuc_co < 3*nucleus_index[shell_num-1]+2) return TREXIO_INVALID_ARG_5;
for (int shell_index = 0; shell_index < shell_num; shell_index++) {
const int32_t nuc_index = nucleus_index[shell_index];
const int64_t nuc_index = nucleus_index[shell_index];
const double dx = nucleus_coords[3*nuc_index + 0] - rx;
const double dy = nucleus_coords[3*nuc_index + 1] - ry;
const double dz = nucleus_coords[3*nuc_index + 2] - rz;
const double r = sqrt(dx*dx + dy*dy + dz*dz);
// All possibly reported errors have been caught above
rc = trexio_evaluate_nao_radial_py(shell_index, r, grid_start, n_grid_st,
grid_size, n_grid_si, grid_r, n_grid_r, interpolator, n_interp, normalization, n_norm, &amplitudes[shell_index]);
trexio_exit_code rc =
trexio_evaluate_nao_radial_py(shell_index, r, grid_start, n_grid_st, grid_size,
n_grid_si, grid_r, n_grid_r, interpolator, n_interp,
normalization, n_norm, &amplitudes[shell_index]);
if (rc != TREXIO_SUCCESS)
return rc;
}

View File

@ -703,6 +703,9 @@ trexio_exit_code trexio_hdf5_read_$group_dset$(trexio_t* const file,
double* const dset)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank != 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
if (dset == NULL) return TREXIO_INVALID_ARG_6;
@ -728,6 +731,9 @@ trexio_exit_code trexio_hdf5_write_$group_dset$(trexio_t* const file,
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank != 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (dset == NULL) return TREXIO_INVALID_ARG_5;
const char* dset_name = "$group_dset$";
@ -832,6 +838,9 @@ trexio_hdf5_read_$group_dset$ (trexio_t* const file, char* const $group_dset$, c
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (max_str_len < 1) return TREXIO_INVALID_ARG_5;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
@ -938,6 +947,8 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, const char** $group_dset$,
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (rank != 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -1031,6 +1042,7 @@ trexio_hdf5_read_$group_str$ (trexio_t* const file, char* const str, const uint3
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (str == NULL) return TREXIO_INVALID_ARG_2;
if (max_str_len < 1) return TREXIO_INVALID_ARG_3;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
/* Quit if the string attribute is missing in the file */
@ -1202,6 +1214,9 @@ trexio_exit_code trexio_hdf5_read_determinant_list(trexio_t* const file,
int64_t* const list)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank < 2) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
if (list == NULL) return TREXIO_INVALID_ARG_6;
@ -1227,6 +1242,9 @@ trexio_exit_code trexio_hdf5_write_determinant_list(trexio_t* const file,
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank < 2) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (list == NULL) return TREXIO_INVALID_ARG_5;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;

View File

@ -332,8 +332,8 @@ trexio_text_flush (trexio_t* const file)
trexio_exit_code rc;
trexio_text_t* f = (trexio_text_t*) file;
/* Error handling for this call is added by the generator */
rc = trexio_text_flush_$group$(f);
/* TODO: Error handling for this call is NOT added by the generator */
rc = trexio_text_flush_$group$(f); if (rc != TREXIO_SUCCESS) return rc;
return TREXIO_SUCCESS;
@ -1121,6 +1121,8 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
the line_length is 69 because 10 per index + 4 spaces + 24 for floating point value + 1 for the new line char.
CURRENTLY NO OFFSET IS USED WHEN WRITING !
,*/
(void) offset_file; // Avoid unused variable error
int64_t line_length = 0L;
char format_str[256];
@ -1495,6 +1497,8 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
const double* dset)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (rank != 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (dset == NULL) return TREXIO_INVALID_ARG_5;
const char file_name[256] = "/$group_dset$.txt";