From 7c8bcef271493cd677ec69a8b7863bb4377e05fe Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 24 Mar 2023 12:16:21 +0100 Subject: [PATCH 01/20] fixed possible char overflow in filename --- src/templates_front/templator_front.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index ba9f242..227be36 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -740,7 +740,6 @@ typedef struct trexio_s trexio_t; #+begin_src c :tangle prefix_s_front.h struct trexio_s { - char file_name[TREXIO_MAX_FILENAME_LENGTH]; pthread_mutex_t thread_lock; back_end_t back_end; char mode; @@ -750,6 +749,7 @@ struct trexio_s { int16_t version_minor; int16_t version_patch; char version[16]; + char file_name[TREXIO_MAX_FILENAME_LENGTH]; }; #+end_src From 42592c44547a576d04171d7d67a6e2f54d1d6b84 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 24 Mar 2023 12:16:57 +0100 Subject: [PATCH 02/20] Fixed style: Use pointers to const when referring to string literals [cert-STR05-C] --- src/templates_hdf5/templator_hdf5.org | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/templates_hdf5/templator_hdf5.org b/src/templates_hdf5/templator_hdf5.org index ac68475..725f773 100644 --- a/src/templates_hdf5/templator_hdf5.org +++ b/src/templates_hdf5/templator_hdf5.org @@ -694,7 +694,7 @@ trexio_exit_code trexio_hdf5_read_$group_dset$(trexio_t* const file, if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5; if (dset == NULL) return TREXIO_INVALID_ARG_6; - const char dset_name[256] = "$group_dset$"; + const char* dset_name = "$group_dset$"; const trexio_hdf5_t* f = (const trexio_hdf5_t*) file; @@ -718,7 +718,7 @@ trexio_exit_code trexio_hdf5_write_$group_dset$(trexio_t* const file, if (file == NULL) return TREXIO_INVALID_ARG_1; if (dset == NULL) return TREXIO_INVALID_ARG_5; - const char dset_name[256] = "$group_dset$"; + const char* dset_name = "$group_dset$"; trexio_hdf5_t* f = (trexio_hdf5_t*) file; @@ -756,7 +756,7 @@ trexio_hdf5_read_$group_dset$_size (trexio_t* const file, int64_t* const size_ma if (file == NULL) return TREXIO_INVALID_ARG_1; if (size_max == NULL) return TREXIO_INVALID_ARG_2; - const char dset_name[256] = "$group_dset$"; + const char* dset_name = "$group_dset$"; const trexio_hdf5_t* f = (const trexio_hdf5_t*) file; @@ -792,7 +792,7 @@ trexio_exit_code trexio_hdf5_has_$group_dset$(trexio_t* const file) trexio_hdf5_t* f = (trexio_hdf5_t*) file; if (f->$group$_group == (hsize_t) 0) return TREXIO_HAS_NOT; - const char dset_name[256] = "$group_dset$"; + const char* dset_name = "$group_dset$"; htri_t exists = H5Lexists(f->$group$_group, dset_name, H5P_DEFAULT); if (exists > 0) { From 1d9b58cf21fddb33170595684b8fa04e2194665b Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 24 Mar 2023 12:17:22 +0100 Subject: [PATCH 03/20] Fixed const cast-away with index_p --- src/templates_hdf5/templator_hdf5.org | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/templates_hdf5/templator_hdf5.org b/src/templates_hdf5/templator_hdf5.org index 725f773..f67817f 100644 --- a/src/templates_hdf5/templator_hdf5.org +++ b/src/templates_hdf5/templator_hdf5.org @@ -497,7 +497,8 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, trexio_hdf5_t* f = (trexio_hdf5_t*) file; hid_t index_dtype; - void* index_p = NULL; + const void* index_p = NULL; + void* index_p_non_const = NULL; uint64_t size_ranked = (uint64_t) size * $group_dset_rank$; /* Determine the optimal type for storing indices depending on the size_max (usually mo_num or ao_num) */ if (size_max < UINT8_MAX) { @@ -507,6 +508,7 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, index[i] = (uint8_t) index_sparse[i]; } index_p = index; + index_p_non_const = index; index_dtype = H5T_NATIVE_UINT8; } else if (size_max < UINT16_MAX) { uint16_t* index = CALLOC(size_ranked, uint16_t); @@ -515,9 +517,10 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, index[i] = (uint16_t) index_sparse[i]; } index_p = index; + index_p_non_const = index; index_dtype = H5T_NATIVE_UINT16; } else { - index_p = (int32_t*) index_sparse; + index_p = index_sparse; index_dtype = H5T_NATIVE_INT32; } @@ -541,7 +544,7 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, /* Create chunked dataset with index_dtype datatype and write indices into it */ rc_write = trexio_hdf5_create_write_dset_sparse(f->$group$_group, dset_index_name, index_dtype, chunk_i_dims, index_p); - if (index_p != index_sparse) FREE(index_p); + if (index_p != index_sparse) FREE(index_p_non_const); if (rc_write != TREXIO_SUCCESS) return rc_write; /* Create chunked dataset with value_dtype datatype and write values into it */ @@ -555,7 +558,7 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, /* Create chunked dataset with index_dtype datatype and write indices into it */ rc_write = trexio_hdf5_open_write_dset_sparse(f->$group$_group, dset_index_name, index_dtype, chunk_i_dims, offset_i, index_p); - if (index_p != index_sparse) FREE(index_p); + if (index_p != index_sparse) FREE(index_p_non_const); if (rc_write != TREXIO_SUCCESS) return rc_write; /* Create chunked dataset with value_dtype datatype and write values into it */ @@ -1465,8 +1468,6 @@ trexio_hdf5_open_read_dset_sparse (const hid_t group_id, uint16_t* index = CALLOC(size_ranked, uint16_t); if (index == NULL) return TREXIO_ALLOCATION_FAILED; index_p = index; - } else { - index_p = data_sparse; } } @@ -1474,7 +1475,7 @@ trexio_hdf5_open_read_dset_sparse (const hid_t group_id, if (status < 0) { H5Sclose(fspace_id); H5Dclose(dset_id); - if (index_p != data_sparse) FREE(index_p); + if (index_p != NULL) FREE(index_p); return TREXIO_INVALID_ID; } @@ -1482,7 +1483,7 @@ trexio_hdf5_open_read_dset_sparse (const hid_t group_id, if (memspace_id < 0) { H5Sclose(fspace_id); H5Dclose(dset_id); - if (index_p != data_sparse) FREE(index_p); + if (index_p != NULL) FREE(index_p); return TREXIO_INVALID_ID; } @@ -1502,7 +1503,7 @@ trexio_hdf5_open_read_dset_sparse (const hid_t group_id, H5Sclose(memspace_id); H5Dclose(dset_id); if (status < 0) { - if (index_p != data_sparse) FREE(index_p); + if (index_p != NULL) FREE(index_p); return TREXIO_FAILURE; } From e17e2bece02dbce152381c3bba6ecd34d688008e Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 27 Mar 2023 18:14:17 +0200 Subject: [PATCH 04/20] Check different mo_num for io_determinant_hdf5 --- tests/io_determinant_hdf5.c | 80 +++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/tests/io_determinant_hdf5.c b/tests/io_determinant_hdf5.c index 5538680..5a4fcca 100644 --- a/tests/io_determinant_hdf5.c +++ b/tests/io_determinant_hdf5.c @@ -10,9 +10,8 @@ #define SIZE 100 #define N_CHUNKS 5 #define STATE_TEST 2 -#define MO_NUM 150 -static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset) { +static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset, const int mo_num) { /* Try to write an array of sparse data into the TREXIO file */ @@ -30,8 +29,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe int64_t* det_list; double* det_coef; - int mo_num = MO_NUM; - // write mo_num which will be used to determine the optimal size of int indices if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) { rc = trexio_write_mo_num(file, mo_num); @@ -42,19 +39,20 @@ static int test_write_determinant (const char* file_name, const back_end_t backe int int_num; rc = trexio_get_int64_num(file, &int_num); assert(rc == TREXIO_SUCCESS); - assert(int_num == (MO_NUM-1)/64 + 1); + assert(int_num == (mo_num-1)/64 + 1); // allocate memory and fill with values to be written det_list = (int64_t*) calloc(2 * int_num * SIZE, sizeof(int64_t)); det_coef = (double*) calloc(SIZE, sizeof(double)); + int64_t size_list = TREXIO_NORB_PER_INT * int_num; + const int32_t orb_list_up[4] = {0,1,2,3}; + const int32_t orb_list_dn[3] = {0,1,2}; + + for(int i=0; i Date: Tue, 2 May 2023 10:22:53 +0200 Subject: [PATCH 05/20] Fixed 32bit case for indices --- src/templates_hdf5/templator_hdf5.org | 15 ++++-- tests/io_determinant_hdf5.c | 3 -- tests/io_determinant_text.c | 77 +++++++++++++-------------- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/templates_hdf5/templator_hdf5.org b/src/templates_hdf5/templator_hdf5.org index f67817f..3b63aba 100644 --- a/src/templates_hdf5/templator_hdf5.org +++ b/src/templates_hdf5/templator_hdf5.org @@ -1488,10 +1488,17 @@ trexio_hdf5_open_read_dset_sparse (const hid_t group_id, } if (is_index == 1) { - status = H5Dread(dset_id, - dtype, - memspace_id, fspace_id, H5P_DEFAULT, - index_p); + if (index_p != NULL) { + status = H5Dread(dset_id, + dtype, + memspace_id, fspace_id, H5P_DEFAULT, + index_p); + } else { + status = H5Dread(dset_id, + dtype, + memspace_id, fspace_id, H5P_DEFAULT, + data_sparse); + } } else { status = H5Dread(dset_id, dtype, diff --git a/tests/io_determinant_hdf5.c b/tests/io_determinant_hdf5.c index 5a4fcca..3109dfc 100644 --- a/tests/io_determinant_hdf5.c +++ b/tests/io_determinant_hdf5.c @@ -159,7 +159,6 @@ static int test_read_determinant (const char* file_name, const back_end_t backen int64_t mo_num; rc = trexio_read_mo_num_64(file, &mo_num); assert (rc == TREXIO_SUCCESS); - assert (mo_num == mo_num); int int_num; rc = trexio_get_int64_num(file, &int_num); @@ -227,8 +226,6 @@ static int test_read_determinant (const char* file_name, const back_end_t backen */ assert(rc == TREXIO_END); assert(chunk_read == eof_read_size_check); -// assert(det_list_read[2*int_num*size_r-1] == 0); -// assert(det_list_read[2*int_num*offset_data_read] == 2 * int_num * (int64_t) (offset_file_read-offset)); chunk_read = read_size_check; rc = trexio_read_determinant_coefficient(file, offset_file_read, &chunk_read, &det_coef_read[offset_data_read]); diff --git a/tests/io_determinant_text.c b/tests/io_determinant_text.c index b3e6e92..e5b342b 100644 --- a/tests/io_determinant_text.c +++ b/tests/io_determinant_text.c @@ -10,9 +10,8 @@ #define SIZE 100 #define N_CHUNKS 5 #define STATE_TEST 2 -#define MO_NUM 150 -static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset) { +static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset, const int mo_num) { /* Try to write an array of sparse data into the TREXIO file */ @@ -30,8 +29,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe int64_t* det_list; double* det_coef; - int mo_num = MO_NUM; - // write mo_num which will be used to determine the optimal size of int indices if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) { rc = trexio_write_mo_num(file, mo_num); @@ -42,19 +39,20 @@ static int test_write_determinant (const char* file_name, const back_end_t backe int int_num; rc = trexio_get_int64_num(file, &int_num); assert(rc == TREXIO_SUCCESS); - assert(int_num == (MO_NUM-1)/64 + 1); + assert(int_num == (mo_num-1)/64 + 1); // allocate memory and fill with values to be written det_list = (int64_t*) calloc(2 * int_num * SIZE, sizeof(int64_t)); det_coef = (double*) calloc(SIZE, sizeof(double)); + int64_t size_list = TREXIO_NORB_PER_INT * int_num; + const int32_t orb_list_up[4] = {0,1,2,3}; + const int32_t orb_list_dn[3] = {0,1,2}; + + for(int i=0; i Date: Tue, 2 May 2023 14:45:51 +0200 Subject: [PATCH 06/20] Refactored tests --- tests/delete_group.c | 85 +++++++++ tests/delete_group_hdf5.c | 93 +-------- tests/delete_group_text.c | 93 +-------- tests/io_determinant.c | 322 +++++++++++++++++++++++++++++++ tests/io_determinant_hdf5.c | 328 +------------------------------- tests/io_determinant_text.c | 328 +------------------------------- tests/io_dset_float.c | 142 ++++++++++++++ tests/io_dset_float_hdf5.c | 151 +-------------- tests/io_dset_float_text.c | 149 +-------------- tests/io_dset_int.c | 136 +++++++++++++ tests/io_dset_int_hdf5.c | 143 +------------- tests/io_dset_int_text.c | 143 +------------- tests/io_dset_sparse.c | 235 +++++++++++++++++++++++ tests/io_dset_sparse_hdf5.c | 242 +---------------------- tests/io_dset_sparse_text.c | 242 +---------------------- tests/io_dset_str.c | 153 +++++++++++++++ tests/io_dset_str_hdf5.c | 160 +--------------- tests/io_dset_str_text.c | 159 +--------------- tests/io_jastrow.c | 194 +++++++++++++++++++ tests/io_jastrow_hdf5.c | 201 +------------------ tests/io_jastrow_text.c | 201 +------------------ tests/io_num.c | 150 +++++++++++++++ tests/io_num_hdf5.c | 157 +-------------- tests/io_num_text.c | 157 +-------------- tests/io_safe_dset_float.c | 161 ++++++++++++++++ tests/io_safe_dset_float_hdf5.c | 168 +--------------- tests/io_safe_dset_float_text.c | 166 +--------------- tests/io_str.c | 129 +++++++++++++ tests/io_str_hdf5.c | 136 +------------ tests/io_str_text.c | 134 +------------ tests/open.c | 160 ++++++++++++++++ tests/open_hdf5.c | 166 +--------------- tests/open_text.c | 166 +--------------- tests/overwrite_all.c | 262 +++++++++++++++++++++++++ tests/overwrite_all_hdf5.c | 269 +------------------------- tests/overwrite_all_text.c | 269 +------------------------- tests/template_hdf5.c | 5 + tests/template_text.c | 5 + tests/test_macros.h | 20 ++ 39 files changed, 2255 insertions(+), 4325 deletions(-) create mode 100644 tests/delete_group.c create mode 100644 tests/io_determinant.c create mode 100644 tests/io_dset_float.c create mode 100644 tests/io_dset_int.c create mode 100644 tests/io_dset_sparse.c create mode 100644 tests/io_dset_str.c create mode 100644 tests/io_jastrow.c create mode 100644 tests/io_num.c create mode 100644 tests/io_safe_dset_float.c create mode 100644 tests/io_str.c create mode 100644 tests/open.c create mode 100644 tests/overwrite_all.c create mode 100644 tests/template_hdf5.c create mode 100644 tests/template_text.c create mode 100644 tests/test_macros.h diff --git a/tests/delete_group.c b/tests/delete_group.c new file mode 100644 index 0000000..8836fe1 --- /dev/null +++ b/tests/delete_group.c @@ -0,0 +1,85 @@ +#include "trexio.h" +#include +#include +#include + +static int test_write_delete_group (const char* file_name, const back_end_t backend) { + +/* Try to write a dimensioning attribute (num variable) into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 12; + double coord[36] = { + 0.00000000 , 1.39250319 , 0.00000000 , + -1.20594314 , 0.69625160 , 0.00000000 , + -1.20594314 , -0.69625160 , 0.00000000 , + 0.00000000 , -1.39250319 , 0.00000000 , + 1.20594314 , -0.69625160 , 0.00000000 , + 1.20594314 , 0.69625160 , 0.00000000 , + -2.14171677 , 1.23652075 , 0.00000000 , + -2.14171677 , -1.23652075 , 0.00000000 , + 0.00000000 , -2.47304151 , 0.00000000 , + 2.14171677 , -1.23652075 , 0.00000000 , + 2.14171677 , 1.23652075 , 0.00000000 , + 0.00000000 , 2.47304151 , 0.00000000 , + }; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // write numerical attribute in an empty file + rc = trexio_write_nucleus_num(file, num); + assert (rc == TREXIO_SUCCESS); + + // write numerical dataset in a file + rc = trexio_write_nucleus_coord(file, coord); + assert (rc == TREXIO_SUCCESS); + + // write numerical attribute ao_cartesian as 0 + rc = trexio_write_ao_cartesian(file, 0); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + + // open file in 'unsafe' mode + file = trexio_open(file_name, 'u', backend, &rc); + assert (file != NULL); + + // delete a previously written group + rc = trexio_delete_nucleus(file); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + + +/*================= END OF TEST ==================*/ + + return 0; +} + + +int main(void) { + +/*============== Test launcher ================*/ + + int rc; + rc = system(RM_COMMAND); + assert (rc == 0); + + test_write_delete_group (TREXIO_FILE, TEST_BACKEND); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} diff --git a/tests/delete_group_hdf5.c b/tests/delete_group_hdf5.c index 151a73a..db03b5e 100644 --- a/tests/delete_group_hdf5.c +++ b/tests/delete_group_hdf5.c @@ -1,89 +1,4 @@ -#include "trexio.h" -#include -#include -#include - -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_del.h5" -#define RM_COMMAND "rm -f -- " TREXIO_FILE - -static int test_write_delete_group (const char* file_name, const back_end_t backend) { - -/* Try to write a dimensioning attribute (num variable) into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - double coord[36] = { - 0.00000000 , 1.39250319 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 , - 1.20594314 , 0.69625160 , 0.00000000 , - -2.14171677 , 1.23652075 , 0.00000000 , - -2.14171677 , -1.23652075 , 0.00000000 , - 0.00000000 , -2.47304151 , 0.00000000 , - 2.14171677 , -1.23652075 , 0.00000000 , - 2.14171677 , 1.23652075 , 0.00000000 , - 0.00000000 , 2.47304151 , 0.00000000 , - }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - // write numerical dataset in a file - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - // write numerical attribute ao_cartesian as 0 - rc = trexio_write_ao_cartesian(file, 0); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - - // open file in 'unsafe' mode - file = trexio_open(file_name, 'u', backend, &rc); - assert (file != NULL); - - // delete a previously written group - rc = trexio_delete_nucleus(file); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_delete_group (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "delete_group" +#include "test_macros.h" +#include "delete_group.c" diff --git a/tests/delete_group_text.c b/tests/delete_group_text.c index 37f338b..db03b5e 100644 --- a/tests/delete_group_text.c +++ b/tests/delete_group_text.c @@ -1,89 +1,4 @@ -#include "trexio.h" -#include -#include -#include - -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_del.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write_delete_group (const char* file_name, const back_end_t backend) { - -/* Try to write a dimensioning attribute (num variable) into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - double coord[36] = { - 0.00000000 , 1.39250319 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 , - 1.20594314 , 0.69625160 , 0.00000000 , - -2.14171677 , 1.23652075 , 0.00000000 , - -2.14171677 , -1.23652075 , 0.00000000 , - 0.00000000 , -2.47304151 , 0.00000000 , - 2.14171677 , -1.23652075 , 0.00000000 , - 2.14171677 , 1.23652075 , 0.00000000 , - 0.00000000 , 2.47304151 , 0.00000000 , - }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - // write numerical dataset in a file - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - // write numerical attribute ao_cartesian as 0 - rc = trexio_write_ao_cartesian(file, 0); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - - // open file in 'unsafe' mode - file = trexio_open(file_name, 'u', backend, &rc); - assert (file != NULL); - - // delete a previously written group - rc = trexio_delete_nucleus(file); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_delete_group (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "delete_group" +#include "test_macros.h" +#include "delete_group.c" diff --git a/tests/io_determinant.c b/tests/io_determinant.c new file mode 100644 index 0000000..bd861d2 --- /dev/null +++ b/tests/io_determinant.c @@ -0,0 +1,322 @@ +#include "trexio.h" +#include +#include +#include +#include + +#define SIZE 100 +#define N_CHUNKS 5 +#define STATE_TEST 2 + +static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset, const int mo_num) { + +/* Try to write an array of sparse data into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + // parameters to be written + int64_t* det_list; + double* det_coef; + + // write mo_num which will be used to determine the optimal size of int indices + if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) { + rc = trexio_write_mo_num(file, mo_num); + assert(rc == TREXIO_SUCCESS); + } + + // get the number of int64 bit fields per determinant + int int_num; + rc = trexio_get_int64_num(file, &int_num); + assert(rc == TREXIO_SUCCESS); + assert(int_num == (mo_num-1)/64 + 1); + + // allocate memory and fill with values to be written + det_list = (int64_t*) calloc(2 * int_num * SIZE, sizeof(int64_t)); + det_coef = (double*) calloc(SIZE, sizeof(double)); + + int64_t size_list = TREXIO_NORB_PER_INT * int_num; + const int32_t orb_list_up[4] = {0,1,2,3}; + const int32_t orb_list_dn[3] = {0,1,2}; + + + for(int i=0; i size_max) + offset_file_read = 97L; + offset_data_read = 1; + int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 + + if (offset != 0L) offset_file_read += offset; + + chunk_read = read_size_check; + // read one chunk that will reach EOF and return TREXIO_END code + rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[2*int_num*offset_data_read]); + /* + printf("%s\n", trexio_string_of_error(rc)); + for (int i=0; i -#include -#include -#include +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "io_determinant" +#include "test_macros.h" +#include "io_determinant.c" -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_determinant.h5" -#define RM_COMMAND "rm -f -- " TREXIO_FILE -#define SIZE 100 -#define N_CHUNKS 5 -#define STATE_TEST 2 - -static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset, const int mo_num) { - -/* Try to write an array of sparse data into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // parameters to be written - int64_t* det_list; - double* det_coef; - - // write mo_num which will be used to determine the optimal size of int indices - if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) { - rc = trexio_write_mo_num(file, mo_num); - assert(rc == TREXIO_SUCCESS); - } - - // get the number of int64 bit fields per determinant - int int_num; - rc = trexio_get_int64_num(file, &int_num); - assert(rc == TREXIO_SUCCESS); - assert(int_num == (mo_num-1)/64 + 1); - - // allocate memory and fill with values to be written - det_list = (int64_t*) calloc(2 * int_num * SIZE, sizeof(int64_t)); - det_coef = (double*) calloc(SIZE, sizeof(double)); - - int64_t size_list = TREXIO_NORB_PER_INT * int_num; - const int32_t orb_list_up[4] = {0,1,2,3}; - const int32_t orb_list_dn[3] = {0,1,2}; - - - for(int i=0; i size_max) - offset_file_read = 97L; - offset_data_read = 1; - int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 - - if (offset != 0L) offset_file_read += offset; - - chunk_read = read_size_check; - // read one chunk that will reach EOF and return TREXIO_END code - rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[2*int_num*offset_data_read]); - /* - printf("%s\n", trexio_string_of_error(rc)); - for (int i=0; i -#include -#include -#include +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "io_determinant" +#include "test_macros.h" +#include "io_determinant.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_determinant.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE -#define SIZE 100 -#define N_CHUNKS 5 -#define STATE_TEST 2 - -static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset, const int mo_num) { - -/* Try to write an array of sparse data into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // parameters to be written - int64_t* det_list; - double* det_coef; - - // write mo_num which will be used to determine the optimal size of int indices - if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) { - rc = trexio_write_mo_num(file, mo_num); - assert(rc == TREXIO_SUCCESS); - } - - // get the number of int64 bit fields per determinant - int int_num; - rc = trexio_get_int64_num(file, &int_num); - assert(rc == TREXIO_SUCCESS); - assert(int_num == (mo_num-1)/64 + 1); - - // allocate memory and fill with values to be written - det_list = (int64_t*) calloc(2 * int_num * SIZE, sizeof(int64_t)); - det_coef = (double*) calloc(SIZE, sizeof(double)); - - int64_t size_list = TREXIO_NORB_PER_INT * int_num; - const int32_t orb_list_up[4] = {0,1,2,3}; - const int32_t orb_list_dn[3] = {0,1,2}; - - - for(int i=0; i size_max) - offset_file_read = 97L; - offset_data_read = 1; - int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 - - if (offset != 0L) offset_file_read += offset; - - chunk_read = read_size_check; - // read one chunk that will reach EOF and return TREXIO_END code - rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[2*int_num*offset_data_read]); - /* - printf("%s\n", trexio_string_of_error(rc)); - for (int i=0; i +#include +#include + +static int test_write_dset (const char* file_name, const back_end_t backend) { + +/* Try to write a dataset with numerical (floating point) values into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 12; + double coord[36] = { + 0.00000000 , 1.39250319 , 0.00000000 , + -1.20594314 , 0.69625160 , 0.00000000 , + -1.20594314 , -0.69625160 , 0.00000000 , + 0.00000000 , -1.39250319 , 0.00000000 , + 1.20594314 , -0.69625160 , 0.00000000 , + 1.20594314 , 0.69625160 , 0.00000000 , + -2.14171677 , 1.23652075 , 0.00000000 , + -2.14171677 , -1.23652075 , 0.00000000 , + 0.00000000 , -2.47304151 , 0.00000000 , + 2.14171677 , -1.23652075 , 0.00000000 , + 2.14171677 , 1.23652075 , 0.00000000 , + 0.00000000 , 2.47304151 , 0.00000000 , + }; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // write numerical attribute in an empty file + rc = trexio_write_nucleus_num(file, num); + assert (rc == TREXIO_SUCCESS); + + // write numerical dataset in a file + rc = trexio_write_nucleus_coord(file, coord); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_has_dset (const char* file_name, const back_end_t backend) { + +/* Try to check the existence of a dataset in the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // check that the previously written dataset exists + rc = trexio_has_nucleus_coord(file); + assert (rc == TREXIO_SUCCESS); + + // check that another dataset does not exist + rc = trexio_has_mo_coefficient(file); + assert (rc == TREXIO_HAS_NOT); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_read_dset (const char* file_name, const back_end_t backend) { + +/* Try to read a dataset with numerical (floating point) values from the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be read + int num; + double* coord; + +/*================= START OF TEST ==================*/ + + // open file in 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // read numerical attribute from the file + rc = trexio_read_nucleus_num(file, &num); + assert (rc == TREXIO_SUCCESS); + assert (num == 12); + + // read numerical (floating point) dataset from the file + coord = (double*) calloc(3*num, sizeof(double)); + rc = trexio_read_nucleus_coord(file, coord); + assert (rc == TREXIO_SUCCESS); + + double x = coord[30] - 2.14171677; + assert( x*x < 1.e-14 ); + free(coord); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +int main(void) { + +/*============== Test launcher ================*/ + + int rc; + rc = system(RM_COMMAND); + assert (rc == 0); + + test_write_dset (TREXIO_FILE, TEST_BACKEND); + test_has_dset (TREXIO_FILE, TEST_BACKEND); + test_read_dset (TREXIO_FILE, TEST_BACKEND); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} diff --git a/tests/io_dset_float_hdf5.c b/tests/io_dset_float_hdf5.c index 90174cd..84eb58a 100644 --- a/tests/io_dset_float_hdf5.c +++ b/tests/io_dset_float_hdf5.c @@ -1,148 +1,5 @@ -#include "trexio.h" -#include -#include -#include - -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_dset_f.h5" -#define RM_COMMAND "rm -rf " TREXIO_FILE - -static int test_write_dset (const char* file_name, const back_end_t backend) { - -/* Try to write a dataset with numerical (floating point) values into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - double coord[36] = { - 0.00000000 , 1.39250319 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 , - 1.20594314 , 0.69625160 , 0.00000000 , - -2.14171677 , 1.23652075 , 0.00000000 , - -2.14171677 , -1.23652075 , 0.00000000 , - 0.00000000 , -2.47304151 , 0.00000000 , - 2.14171677 , -1.23652075 , 0.00000000 , - 2.14171677 , 1.23652075 , 0.00000000 , - 0.00000000 , 2.47304151 , 0.00000000 , - }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - // write numerical dataset in a file - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_dset (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dataset in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written dataset exists - rc = trexio_has_nucleus_coord(file); - assert (rc == TREXIO_SUCCESS); - - // check that another dataset does not exist - rc = trexio_has_mo_coefficient(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_dset (const char* file_name, const back_end_t backend) { - -/* Try to read a dataset with numerical (floating point) values from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - double* coord; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_nucleus_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - // read numerical (floating point) dataset from the file - coord = (double*) calloc(3*num, sizeof(double)); - rc = trexio_read_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - double x = coord[30] - 2.14171677; - assert( x*x < 1.e-14 ); - free(coord); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_dset (TREXIO_FILE, TEST_BACKEND); - test_has_dset (TREXIO_FILE, TEST_BACKEND); - test_read_dset (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} - +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "io_dset_float" +#include "test_macros.h" +#include "io_dset_float.c" diff --git a/tests/io_dset_float_text.c b/tests/io_dset_float_text.c index 3d31185..69392e8 100644 --- a/tests/io_dset_float_text.c +++ b/tests/io_dset_float_text.c @@ -1,146 +1,5 @@ -#include "trexio.h" -#include -#include -#include +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "io_dset_float" +#include "test_macros.h" +#include "io_dset_float.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_dset_f.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write_dset (const char* file_name, const back_end_t backend) { - -/* Try to write a dataset with numerical (floating point) values into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - double coord[36] = { - 0.00000000 , 1.39250319 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 , - 1.20594314 , 0.69625160 , 0.00000000 , - -2.14171677 , 1.23652075 , 0.00000000 , - -2.14171677 , -1.23652075 , 0.00000000 , - 0.00000000 , -2.47304151 , 0.00000000 , - 2.14171677 , -1.23652075 , 0.00000000 , - 2.14171677 , 1.23652075 , 0.00000000 , - 0.00000000 , 2.47304151 , 0.00000000 , - }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - // write numerical dataset in a file - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_dset (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dataset in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written dataset exists - rc = trexio_has_nucleus_coord(file); - assert (rc == TREXIO_SUCCESS); - - // check that another dataset does not exist - rc = trexio_has_mo_coefficient(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_dset (const char* file_name, const back_end_t backend) { - -/* Try to read a dataset with numerical (floating point) values from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - double* coord; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_nucleus_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - // read numerical (floating point) dataset from the file - coord = (double*) calloc(3*num, sizeof(double)); - rc = trexio_read_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - double x = coord[30] - 2.14171677; - assert( x*x < 1.e-14 ); - free(coord); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_dset (TREXIO_FILE, TEST_BACKEND); - test_has_dset (TREXIO_FILE, TEST_BACKEND); - test_read_dset (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/io_dset_int.c b/tests/io_dset_int.c new file mode 100644 index 0000000..a349248 --- /dev/null +++ b/tests/io_dset_int.c @@ -0,0 +1,136 @@ +#include "trexio.h" +#include +#include +#include + +static int test_write_dset (const char* file_name, const back_end_t backend) { + +/* Try to write a dataset with numerical (int) values into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 12; + int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // write numerical attribute in an empty file + rc = trexio_write_basis_shell_num(file, num); + assert (rc == TREXIO_SUCCESS); + + // write numerical (integer) dataset in a file + rc = trexio_write_basis_nucleus_index(file, nucl_index); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_has_dset (const char* file_name, const back_end_t backend) { + +/* Try to check the existence of a dataset in the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // check that the group exists + rc = trexio_has_basis(file); + assert(rc==TREXIO_SUCCESS); + + // check that the group does not exist + rc = trexio_has_mo(file); + assert(rc==TREXIO_HAS_NOT); + + // check that the previously written dataset exists + rc = trexio_has_basis_nucleus_index(file); + assert (rc == TREXIO_SUCCESS); + + // check that another dataset does not exist + rc = trexio_has_mo_coefficient(file); + assert (rc == TREXIO_HAS_NOT); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_read_dset (const char* file_name, const back_end_t backend) { + +/* Try to read a dataset with numericali (int) values from the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be read + int num; + int* nucl_index; + +/*================= START OF TEST ==================*/ + + // open file in 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // read numerical attribute from the file + rc = trexio_read_basis_shell_num(file, &num); + assert (rc == TREXIO_SUCCESS); + assert (num == 12); + + // read numerical dataset from the file + nucl_index = (int*) calloc(num, sizeof(int)); + rc = trexio_read_basis_nucleus_index(file, nucl_index); + assert (rc == TREXIO_SUCCESS); + assert (nucl_index[num-1] == num-1); + + free(nucl_index); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +int main(void) { + +/*============== Test launcher ================*/ + + int rc; + rc = system(RM_COMMAND); + assert (rc == 0); + + test_write_dset (TREXIO_FILE, TEST_BACKEND); + test_has_dset (TREXIO_FILE, TEST_BACKEND); + test_read_dset (TREXIO_FILE, TEST_BACKEND); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} diff --git a/tests/io_dset_int_hdf5.c b/tests/io_dset_int_hdf5.c index 42db22b..81f4592 100644 --- a/tests/io_dset_int_hdf5.c +++ b/tests/io_dset_int_hdf5.c @@ -1,140 +1,5 @@ -#include "trexio.h" -#include -#include -#include +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "io_dset_int" +#include "test_macros.h" +#include "io_dset_int.c" -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_dset_i.h5" -#define RM_COMMAND "rm -rf " TREXIO_FILE - -static int test_write_dset (const char* file_name, const back_end_t backend) { - -/* Try to write a dataset with numerical (int) values into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_basis_shell_num(file, num); - assert (rc == TREXIO_SUCCESS); - - // write numerical (integer) dataset in a file - rc = trexio_write_basis_nucleus_index(file, nucl_index); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_dset (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dataset in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the group exists - rc = trexio_has_basis(file); - assert(rc==TREXIO_SUCCESS); - - // check that the group does not exist - rc = trexio_has_mo(file); - assert(rc==TREXIO_HAS_NOT); - - // check that the previously written dataset exists - rc = trexio_has_basis_nucleus_index(file); - assert (rc == TREXIO_SUCCESS); - - // check that another dataset does not exist - rc = trexio_has_mo_coefficient(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_dset (const char* file_name, const back_end_t backend) { - -/* Try to read a dataset with numericali (int) values from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - int* nucl_index; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_basis_shell_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - // read numerical dataset from the file - nucl_index = (int*) calloc(num, sizeof(int)); - rc = trexio_read_basis_nucleus_index(file, nucl_index); - assert (rc == TREXIO_SUCCESS); - assert (nucl_index[num-1] == num-1); - - free(nucl_index); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_dset (TREXIO_FILE, TEST_BACKEND); - test_has_dset (TREXIO_FILE, TEST_BACKEND); - test_read_dset (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/io_dset_int_text.c b/tests/io_dset_int_text.c index c1f5a1e..0f7bbee 100644 --- a/tests/io_dset_int_text.c +++ b/tests/io_dset_int_text.c @@ -1,140 +1,5 @@ -#include "trexio.h" -#include -#include -#include +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "io_dset_int" +#include "test_macros.h" +#include "io_dset_int.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_dset_i.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write_dset (const char* file_name, const back_end_t backend) { - -/* Try to write a dataset with numerical (int) values into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_basis_shell_num(file, num); - assert (rc == TREXIO_SUCCESS); - - // write numerical (integer) dataset in a file - rc = trexio_write_basis_nucleus_index(file, nucl_index); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_dset (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dataset in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the group exists - rc = trexio_has_basis(file); - assert(rc==TREXIO_SUCCESS); - - // check that the group does not exist - rc = trexio_has_mo(file); - assert(rc==TREXIO_HAS_NOT); - - // check that the previously written dataset exists - rc = trexio_has_basis_nucleus_index(file); - assert (rc == TREXIO_SUCCESS); - - // check that another dataset does not exist - rc = trexio_has_mo_coefficient(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_dset (const char* file_name, const back_end_t backend) { - -/* Try to read a dataset with numericali (int) values from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - int* nucl_index; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_basis_shell_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - // read numerical dataset from the file - nucl_index = (int*) calloc(num, sizeof(int)); - rc = trexio_read_basis_nucleus_index(file, nucl_index); - assert (rc == TREXIO_SUCCESS); - assert (nucl_index[num-1] == num-1); - - free(nucl_index); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_dset (TREXIO_FILE, TEST_BACKEND); - test_has_dset (TREXIO_FILE, TEST_BACKEND); - test_read_dset (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/io_dset_sparse.c b/tests/io_dset_sparse.c new file mode 100644 index 0000000..3a20174 --- /dev/null +++ b/tests/io_dset_sparse.c @@ -0,0 +1,235 @@ +#include "trexio.h" +#include +#include +#include +#include + +#define SIZE 100 +#define N_CHUNKS 5 + +static int test_write_dset_sparse (const char* file_name, const back_end_t backend, const int64_t offset) { + +/* Try to write an array of sparse data into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + // parameters to be written + int32_t* index; + double* value; + + index = calloc(4L*SIZE, sizeof(int32_t)); + value = calloc(SIZE, sizeof(double)); + + for(int i=0; i size_max) + offset_file_read = 97L; + offset_data_read = 1; + int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 + + if (offset != 0L) offset_file_read += offset; + + // read one chunk that will reach EOF and return TREXIO_END code + rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]); + assert(rc == TREXIO_END); + assert(chunk_read == eof_read_size_check); + assert(index_read[4*size_r-1] == 0); + assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + + // free the memory + free(index_read); + free(value_read); + +/*================= END OF TEST ==================*/ + + return 0; +} + +static int test_read_dset_sparse_size (const char* file_name, const back_end_t backend, const int64_t size_check) { + +/* Try to read a size of the dataset of sparse data in the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + // define the variable to read into + int64_t size_written; + + // read one chunk using the aforementioned parameters + rc = trexio_read_mo_2e_int_eri_size(file, &size_written); + assert(rc == TREXIO_SUCCESS); + assert(size_written == size_check); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + +int main(){ + +/*============== Test launcher ================*/ + + int rc; + rc = system(RM_COMMAND); + assert (rc == 0); + + // check the first write attempt (SIZE elements written in N_CHUNKS chunks) + test_write_dset_sparse (TREXIO_FILE, TEST_BACKEND, 0); + test_has_dset_sparse (TREXIO_FILE, TEST_BACKEND); + test_read_dset_sparse (TREXIO_FILE, TEST_BACKEND, 0); + test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, SIZE); + + // check the second write attempt (SIZE elements written in N_CHUNKS chunks) + test_write_dset_sparse (TREXIO_FILE, TEST_BACKEND, SIZE); + test_read_dset_sparse (TREXIO_FILE, TEST_BACKEND, SIZE); + test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, SIZE*2); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} diff --git a/tests/io_dset_sparse_hdf5.c b/tests/io_dset_sparse_hdf5.c index 7e57ec6..ec691bc 100644 --- a/tests/io_dset_sparse_hdf5.c +++ b/tests/io_dset_sparse_hdf5.c @@ -1,238 +1,4 @@ -#include "trexio.h" -#include -#include -#include -#include - -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_dset_sparse.h5" -#define RM_COMMAND "rm -f -- " TREXIO_FILE -#define SIZE 100 -#define N_CHUNKS 5 - -static int test_write_dset_sparse (const char* file_name, const back_end_t backend, const int64_t offset) { - -/* Try to write an array of sparse data into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // parameters to be written - int32_t* index; - double* value; - - index = calloc(4L*SIZE, sizeof(int32_t)); - value = calloc(SIZE, sizeof(double)); - - for(int i=0; i size_max) - offset_file_read = 97L; - offset_data_read = 1; - int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 - - if (offset != 0L) offset_file_read += offset; - - // read one chunk that will reach EOF and return TREXIO_END code - rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]); - assert(rc == TREXIO_END); - assert(chunk_read == eof_read_size_check); - assert(index_read[4*size_r-1] == 0); - assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - - // free the memory - free(index_read); - free(value_read); - -/*================= END OF TEST ==================*/ - - return 0; -} - -static int test_read_dset_sparse_size (const char* file_name, const back_end_t backend, const int64_t size_check) { - -/* Try to read a size of the dataset of sparse data in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // define the variable to read into - int64_t size_written; - - // read one chunk using the aforementioned parameters - rc = trexio_read_mo_2e_int_eri_size(file, &size_written); - assert(rc == TREXIO_SUCCESS); - assert(size_written == size_check); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - -int main(){ - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - // check the first write attempt (SIZE elements written in N_CHUNKS chunks) - test_write_dset_sparse (TREXIO_FILE, TEST_BACKEND, 0); - test_has_dset_sparse (TREXIO_FILE, TEST_BACKEND); - test_read_dset_sparse (TREXIO_FILE, TEST_BACKEND, 0); - test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, SIZE); - - // check the second write attempt (SIZE elements written in N_CHUNKS chunks) - test_write_dset_sparse (TREXIO_FILE, TEST_BACKEND, SIZE); - test_read_dset_sparse (TREXIO_FILE, TEST_BACKEND, SIZE); - test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, SIZE*2); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "io_dset_sparse" +#include "test_macros.h" +#include "io_dset_sparse.c" diff --git a/tests/io_dset_sparse_text.c b/tests/io_dset_sparse_text.c index caddb9a..4215f96 100644 --- a/tests/io_dset_sparse_text.c +++ b/tests/io_dset_sparse_text.c @@ -1,238 +1,4 @@ -#include "trexio.h" -#include -#include -#include -#include - -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_dset_sparse.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE -#define SIZE 100 -#define N_CHUNKS 5 - -static int test_write_dset_sparse (const char* file_name, const back_end_t backend, const int64_t offset) { - -/* Try to write an array of sparse data into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // parameters to be written - int32_t* index; - double* value; - - index = calloc(4L*SIZE, sizeof(int32_t)); - value = calloc(SIZE, sizeof(double)); - - for(int i=0; i size_max) - offset_file_read = 97L; - offset_data_read = 1; - int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 - - if (offset != 0L) offset_file_read += offset; - - // read one chunk that will reach EOF and return TREXIO_END code - rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]); - assert(rc == TREXIO_END); - assert(chunk_read == eof_read_size_check); - assert(index_read[4*size_r-1] == 0); - assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - - // free the memory - free(index_read); - free(value_read); - -/*================= END OF TEST ==================*/ - - return 0; -} - -static int test_read_dset_sparse_size (const char* file_name, const back_end_t backend, const int64_t size_check) { - -/* Try to read a size of the dataset of sparse data in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // define the variable to read into - int64_t size_written; - - // read one chunk using the aforementioned parameters - rc = trexio_read_mo_2e_int_eri_size(file, &size_written); - assert(rc == TREXIO_SUCCESS); - assert(size_written == size_check); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - -int main(){ - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - // check the first write attempt (SIZE elements written in N_CHUNKS chunks) - test_write_dset_sparse (TREXIO_FILE, TEST_BACKEND, 0); - test_has_dset_sparse (TREXIO_FILE, TEST_BACKEND); - test_read_dset_sparse (TREXIO_FILE, TEST_BACKEND, 0); - test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, SIZE); - - // check the second write attempt (SIZE elements written in N_CHUNKS chunks) - test_write_dset_sparse (TREXIO_FILE, TEST_BACKEND, SIZE); - test_read_dset_sparse (TREXIO_FILE, TEST_BACKEND, SIZE); - test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, SIZE*2); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "io_dset_sparse" +#include "test_macros.h" +#include "io_dset_sparse.c" diff --git a/tests/io_dset_str.c b/tests/io_dset_str.c new file mode 100644 index 0000000..90735b5 --- /dev/null +++ b/tests/io_dset_str.c @@ -0,0 +1,153 @@ +#include "trexio.h" +#include +#include +#include +#include + +static int test_write_dset_str (const char* file_name, const back_end_t backend) { + +/* Try to write an array of strings into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 12; + const char* labels[] = {"C" , + "Na FAKE" , + "C" , + "C" , + "C" , + "C" , + "H" , + "H" , + "H" , + "H" , + "H" , + "H FAKE" }; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // write numerical attribute in an empty file + rc = trexio_write_nucleus_num(file, num); + assert (rc == TREXIO_SUCCESS); + + // write dataset of string in the file (including FAKE statements) + int max_str_len = 16; + rc = trexio_write_nucleus_label(file, labels, max_str_len); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_has_dset_str (const char* file_name, const back_end_t backend) { + +/* Try to check the existence of a dataset of strings in the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // check that the previously written dataset of strings exists + rc = trexio_has_nucleus_label(file); + assert (rc == TREXIO_SUCCESS); + + // check that the dataset of strings does not exist + rc = trexio_has_mo_symmetry(file); + assert (rc == TREXIO_HAS_NOT); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_read_dset_str (const char* file_name, const back_end_t backend) { + +/* Try to read a dataset with strings from the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be read + int num; + char** labels; + +/*================= START OF TEST ==================*/ + + // open file in 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // read numerical attribute from the file + rc = trexio_read_nucleus_num(file, &num); + assert (rc == TREXIO_SUCCESS); + assert (num == 12); + + // read the arrays of strings truncated to max_str_len=2 symbols + int max_str_len = 2; + + labels = (char**) malloc(num*sizeof(char*)); + for (int i=0; i -#include -#include -#include - -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_dset_s.h5" -#define RM_COMMAND "rm -rf " TREXIO_FILE - -static int test_write_dset_str (const char* file_name, const back_end_t backend) { - -/* Try to write an array of strings into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - const char* labels[] = {"C" , - "Na FAKE" , - "C" , - "C" , - "C" , - "C" , - "H" , - "H" , - "H" , - "H" , - "H" , - "H FAKE" }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - // write dataset of string in the file (including FAKE statements) - int max_str_len = 16; - rc = trexio_write_nucleus_label(file, labels, max_str_len); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_dset_str (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dataset of strings in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written dataset of strings exists - rc = trexio_has_nucleus_label(file); - assert (rc == TREXIO_SUCCESS); - - // check that the dataset of strings does not exist - rc = trexio_has_mo_symmetry(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_dset_str (const char* file_name, const back_end_t backend) { - -/* Try to read a dataset with strings from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - char** labels; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_nucleus_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - // read the arrays of strings truncated to max_str_len=2 symbols - int max_str_len = 2; - - labels = (char**) malloc(num*sizeof(char*)); - for (int i=0; i -#include -#include -#include - -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_dset_s.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write_dset_str (const char* file_name, const back_end_t backend) { - -/* Try to write an array of strings into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - const char* labels[] = {"C" , - "Na FAKE" , - "C" , - "C" , - "C" , - "C" , - "H" , - "H" , - "H" , - "H" , - "H" , - "H FAKE" }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - // write dataset of string in the file (including FAKE statements) - int max_str_len = 16; - rc = trexio_write_nucleus_label(file, labels, max_str_len); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_dset_str (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dataset of strings in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written dataset of strings exists - rc = trexio_has_nucleus_label(file); - assert (rc == TREXIO_SUCCESS); - - // check that the dataset of strings does not exist - rc = trexio_has_mo_symmetry(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_dset_str (const char* file_name, const back_end_t backend) { - -/* Try to read a dataset with strings from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - char **labels; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_nucleus_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - // read the arrays of strings truncated to max_str_len=2 symbols - int max_str_len = 2; - - labels = (char**) malloc(num*sizeof(char*)); - for (int i=0; i +#include +#include +#include +#include + +static int test_write_jastrow (const char* file_name, const back_end_t backend) { + +/* Try to write an array of sparse data into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + +#define nucleus_num 3 +#define ee_num 2 +#define en_num 3 +#define een_num 6 + + rc = trexio_write_nucleus_num(file, nucleus_num); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_jastrow_type(file, "CHAMP", 6); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_jastrow_ee_num(file, ee_num); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_jastrow_en_num(file, en_num); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_jastrow_een_num(file, een_num); + assert (rc == TREXIO_SUCCESS); + + double ee [2] = { 0.5, 2. }; + rc = trexio_write_jastrow_ee(file, ee); + assert (rc == TREXIO_SUCCESS); + + double en [3] = { 1., 2., 3. }; + rc = trexio_write_jastrow_en(file, en); + assert (rc == TREXIO_SUCCESS); + + double een [6] = { 11., 12., 13., 14., 15., 16. }; + rc = trexio_write_jastrow_een(file, een); + assert (rc == TREXIO_SUCCESS); + + int en_nucleus [3] = { 0, 1, 2 }; + rc = trexio_write_jastrow_en_nucleus(file, en_nucleus); + assert (rc == TREXIO_SUCCESS); + + int een_nucleus [6] = { 0, 0, 1, 1, 2, 2 }; + rc = trexio_write_jastrow_een_nucleus(file, een_nucleus); + assert (rc == TREXIO_SUCCESS); + + double ee_scaling = 1.0; + rc = trexio_write_jastrow_ee_scaling(file, ee_scaling); + assert (rc == TREXIO_SUCCESS); + + double en_scaling[3] = { 0.5, 1.0, 0.5 }; + rc = trexio_write_jastrow_en_scaling(file, en_scaling); + assert (rc == TREXIO_SUCCESS); + +#undef nucleus_num +#undef ee_num +#undef en_num +#undef een_num + + rc = trexio_close(file); +/*================= END OF TEST ==================*/ + + return 0; +} + +static int test_read_jastrow (const char* file_name, const back_end_t backend) { + +/* Try to read one chunk of dataset of sparse data in the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + int nucleus_num = 0; + rc = trexio_read_nucleus_num(file, &nucleus_num); + assert (rc == TREXIO_SUCCESS); + assert (nucleus_num == 3); + + char type[16] = ""; + rc = trexio_read_jastrow_type(file, type, 16); + assert (rc == TREXIO_SUCCESS); + assert (strcmp("CHAMP",type) == 0); + + int ee_num = 0; + rc = trexio_read_jastrow_ee_num(file, &ee_num); + assert (rc == TREXIO_SUCCESS); + assert (ee_num == 2); + + int en_num = 0; + rc = trexio_read_jastrow_en_num(file, &en_num); + assert (rc == TREXIO_SUCCESS); + assert (en_num == nucleus_num); + + int een_num = 0; + rc = trexio_read_jastrow_een_num(file, &een_num); + assert (rc == TREXIO_SUCCESS); + assert (een_num == 2*nucleus_num); + + double ee [2] = { 0., 0. }; + rc = trexio_read_jastrow_ee(file, ee); + assert (rc == TREXIO_SUCCESS); + assert (ee[0] == 0.5); + assert (ee[1] == 2.0); + + double en [3] = { 0., 0., 0. }; + rc = trexio_read_jastrow_en(file, en); + assert (rc == TREXIO_SUCCESS); + assert (en[0] == 1.0); + assert (en[1] == 2.0); + assert (en[2] == 3.0); + + double een [6]; + rc = trexio_read_jastrow_een(file, een); + assert (rc == TREXIO_SUCCESS); + assert (een[0] == 11.0); + assert (een[1] == 12.0); + assert (een[2] == 13.0); + assert (een[3] == 14.0); + assert (een[4] == 15.0); + assert (een[5] == 16.0); + + int en_nucleus [3] = { 0, 0, 0 }; + rc = trexio_read_jastrow_en_nucleus(file, en_nucleus); + assert (rc == TREXIO_SUCCESS); + assert (en_nucleus[0] == 0); + assert (en_nucleus[1] == 1); + assert (en_nucleus[2] == 2); + + int een_nucleus [6] = { 0, 0, 0, 0, 0, 0 }; + rc = trexio_read_jastrow_een_nucleus(file, een_nucleus); + assert (rc == TREXIO_SUCCESS); + assert (een_nucleus[0] == 0); + assert (een_nucleus[1] == 0); + assert (een_nucleus[2] == 1); + assert (een_nucleus[3] == 1); + assert (een_nucleus[4] == 2); + assert (een_nucleus[5] == 2); + + double ee_scaling = 0.0; + rc = trexio_read_jastrow_ee_scaling(file, &ee_scaling); + assert (rc == TREXIO_SUCCESS); + assert (ee_scaling == 1.0); + + double en_scaling[3] = { 0.5, 1.0, 0.5 }; + rc = trexio_read_jastrow_en_scaling(file, en_scaling); + assert (rc == TREXIO_SUCCESS); + assert (en_scaling[0] == 0.5); + assert (en_scaling[1] == 1.0); + assert (en_scaling[2] == 0.5); + + rc = trexio_close(file); +/*================= END OF TEST ==================*/ + + return 0; +} + + +int main(){ + +/*============== Test launcher ================*/ + + int rc; + + rc = system(RM_COMMAND); + assert (rc == 0); + + test_write_jastrow (TREXIO_FILE, TEST_BACKEND); + test_read_jastrow (TREXIO_FILE, TEST_BACKEND); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} diff --git a/tests/io_jastrow_hdf5.c b/tests/io_jastrow_hdf5.c index 4dfb9a0..8804096 100644 --- a/tests/io_jastrow_hdf5.c +++ b/tests/io_jastrow_hdf5.c @@ -1,198 +1,5 @@ -#include "trexio.h" -#include -#include -#include -#include -#include +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "io_jastrow" +#include "test_macros.h" +#include "io_jastrow.c" -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_jastrow.h5" -#define RM_COMMAND "rm -f -- " TREXIO_FILE - -static int test_write_jastrow (const char* file_name, const back_end_t backend) { - -/* Try to write an array of sparse data into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - -#define nucleus_num 3 -#define ee_num 2 -#define en_num 3 -#define een_num 6 - - rc = trexio_write_nucleus_num(file, nucleus_num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_jastrow_type(file, "CHAMP", 6); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_jastrow_ee_num(file, ee_num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_jastrow_en_num(file, en_num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_jastrow_een_num(file, een_num); - assert (rc == TREXIO_SUCCESS); - - double ee [2] = { 0.5, 2. }; - rc = trexio_write_jastrow_ee(file, ee); - assert (rc == TREXIO_SUCCESS); - - double en [3] = { 1., 2., 3. }; - rc = trexio_write_jastrow_en(file, en); - assert (rc == TREXIO_SUCCESS); - - double een [6] = { 11., 12., 13., 14., 15., 16. }; - rc = trexio_write_jastrow_een(file, een); - assert (rc == TREXIO_SUCCESS); - - int en_nucleus [3] = { 0, 1, 2 }; - rc = trexio_write_jastrow_en_nucleus(file, en_nucleus); - assert (rc == TREXIO_SUCCESS); - - int een_nucleus [6] = { 0, 0, 1, 1, 2, 2 }; - rc = trexio_write_jastrow_een_nucleus(file, een_nucleus); - assert (rc == TREXIO_SUCCESS); - - double ee_scaling = 1.0; - rc = trexio_write_jastrow_ee_scaling(file, ee_scaling); - assert (rc == TREXIO_SUCCESS); - - double en_scaling[3] = { 0.5, 1.0, 0.5 }; - rc = trexio_write_jastrow_en_scaling(file, en_scaling); - assert (rc == TREXIO_SUCCESS); - -#undef nucleus_num -#undef ee_num -#undef en_num -#undef een_num - - rc = trexio_close(file); -/*================= END OF TEST ==================*/ - - return 0; -} - -static int test_read_jastrow (const char* file_name, const back_end_t backend) { - -/* Try to read one chunk of dataset of sparse data in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - int nucleus_num = 0; - rc = trexio_read_nucleus_num(file, &nucleus_num); - assert (rc == TREXIO_SUCCESS); - assert (nucleus_num == 3); - - char type[16] = ""; - rc = trexio_read_jastrow_type(file, type, 16); - assert (rc == TREXIO_SUCCESS); - assert (strcmp("CHAMP",type) == 0); - - int ee_num = 0; - rc = trexio_read_jastrow_ee_num(file, &ee_num); - assert (rc == TREXIO_SUCCESS); - assert (ee_num == 2); - - int en_num = 0; - rc = trexio_read_jastrow_en_num(file, &en_num); - assert (rc == TREXIO_SUCCESS); - assert (en_num == nucleus_num); - - int een_num = 0; - rc = trexio_read_jastrow_een_num(file, &een_num); - assert (rc == TREXIO_SUCCESS); - assert (een_num == 2*nucleus_num); - - double ee [2] = { 0., 0. }; - rc = trexio_read_jastrow_ee(file, ee); - assert (rc == TREXIO_SUCCESS); - assert (ee[0] == 0.5); - assert (ee[1] == 2.0); - - double en [3] = { 0., 0., 0. }; - rc = trexio_read_jastrow_en(file, en); - assert (rc == TREXIO_SUCCESS); - assert (en[0] == 1.0); - assert (en[1] == 2.0); - assert (en[2] == 3.0); - - double een [6]; - rc = trexio_read_jastrow_een(file, een); - assert (rc == TREXIO_SUCCESS); - assert (een[0] == 11.0); - assert (een[1] == 12.0); - assert (een[2] == 13.0); - assert (een[3] == 14.0); - assert (een[4] == 15.0); - assert (een[5] == 16.0); - - int en_nucleus [3] = { 0, 0, 0 }; - rc = trexio_read_jastrow_en_nucleus(file, en_nucleus); - assert (rc == TREXIO_SUCCESS); - assert (en_nucleus[0] == 0); - assert (en_nucleus[1] == 1); - assert (en_nucleus[2] == 2); - - int een_nucleus [6] = { 0, 0, 0, 0, 0, 0 }; - rc = trexio_read_jastrow_een_nucleus(file, een_nucleus); - assert (rc == TREXIO_SUCCESS); - assert (een_nucleus[0] == 0); - assert (een_nucleus[1] == 0); - assert (een_nucleus[2] == 1); - assert (een_nucleus[3] == 1); - assert (een_nucleus[4] == 2); - assert (een_nucleus[5] == 2); - - double ee_scaling = 0.0; - rc = trexio_read_jastrow_ee_scaling(file, &ee_scaling); - assert (rc == TREXIO_SUCCESS); - assert (ee_scaling == 1.0); - - double en_scaling[3] = { 0.5, 1.0, 0.5 }; - rc = trexio_read_jastrow_en_scaling(file, en_scaling); - assert (rc == TREXIO_SUCCESS); - assert (en_scaling[0] == 0.5); - assert (en_scaling[1] == 1.0); - assert (en_scaling[2] == 0.5); - - rc = trexio_close(file); -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(){ - -/*============== Test launcher ================*/ - - int rc; - - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_jastrow (TREXIO_FILE, TEST_BACKEND); - test_read_jastrow (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/io_jastrow_text.c b/tests/io_jastrow_text.c index 80c81ea..40f4b08 100644 --- a/tests/io_jastrow_text.c +++ b/tests/io_jastrow_text.c @@ -1,198 +1,5 @@ -#include "trexio.h" -#include -#include -#include -#include -#include +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "io_jastrow" +#include "test_macros.h" +#include "io_jastrow.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_jastrow.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write_jastrow (const char* file_name, const back_end_t backend) { - -/* Try to write an array of sparse data into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - -#define nucleus_num 3 -#define ee_num 2 -#define en_num 3 -#define een_num 6 - - rc = trexio_write_nucleus_num(file, nucleus_num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_jastrow_type(file, "CHAMP", 6); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_jastrow_ee_num(file, ee_num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_jastrow_en_num(file, en_num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_jastrow_een_num(file, een_num); - assert (rc == TREXIO_SUCCESS); - - double ee [2] = { 0.5, 2. }; - rc = trexio_write_jastrow_ee(file, ee); - assert (rc == TREXIO_SUCCESS); - - double en [3] = { 1., 2., 3. }; - rc = trexio_write_jastrow_en(file, en); - assert (rc == TREXIO_SUCCESS); - - double een [6] = { 11., 12., 13., 14., 15., 16. }; - rc = trexio_write_jastrow_een(file, een); - assert (rc == TREXIO_SUCCESS); - - int en_nucleus [3] = { 0, 1, 2 }; - rc = trexio_write_jastrow_en_nucleus(file, en_nucleus); - assert (rc == TREXIO_SUCCESS); - - int een_nucleus [6] = { 0, 0, 1, 1, 2, 2 }; - rc = trexio_write_jastrow_een_nucleus(file, een_nucleus); - assert (rc == TREXIO_SUCCESS); - - double ee_scaling = 1.0; - rc = trexio_write_jastrow_ee_scaling(file, ee_scaling); - assert (rc == TREXIO_SUCCESS); - - double en_scaling[3] = { 0.5, 1.0, 0.5 }; - rc = trexio_write_jastrow_en_scaling(file, en_scaling); - assert (rc == TREXIO_SUCCESS); - -#undef nucleus_num -#undef ee_num -#undef en_num -#undef een_num - - rc = trexio_close(file); -/*================= END OF TEST ==================*/ - - return 0; -} - -static int test_read_jastrow (const char* file_name, const back_end_t backend) { - -/* Try to read one chunk of dataset of sparse data in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - int nucleus_num = 0; - rc = trexio_read_nucleus_num(file, &nucleus_num); - assert (rc == TREXIO_SUCCESS); - assert (nucleus_num == 3); - - char type[16] = ""; - rc = trexio_read_jastrow_type(file, type, 16); - assert (rc == TREXIO_SUCCESS); - assert (strcmp("CHAMP",type) == 0); - - int ee_num = 0; - rc = trexio_read_jastrow_ee_num(file, &ee_num); - assert (rc == TREXIO_SUCCESS); - assert (ee_num == 2); - - int en_num = 0; - rc = trexio_read_jastrow_en_num(file, &en_num); - assert (rc == TREXIO_SUCCESS); - assert (en_num == nucleus_num); - - int een_num = 0; - rc = trexio_read_jastrow_een_num(file, &een_num); - assert (rc == TREXIO_SUCCESS); - assert (een_num == 2*nucleus_num); - - double ee [2] = { 0., 0. }; - rc = trexio_read_jastrow_ee(file, ee); - assert (rc == TREXIO_SUCCESS); - assert (ee[0] == 0.5); - assert (ee[1] == 2.0); - - double en [3] = { 0., 0., 0. }; - rc = trexio_read_jastrow_en(file, en); - assert (rc == TREXIO_SUCCESS); - assert (en[0] == 1.0); - assert (en[1] == 2.0); - assert (en[2] == 3.0); - - double een [6]; - rc = trexio_read_jastrow_een(file, een); - assert (rc == TREXIO_SUCCESS); - assert (een[0] == 11.0); - assert (een[1] == 12.0); - assert (een[2] == 13.0); - assert (een[3] == 14.0); - assert (een[4] == 15.0); - assert (een[5] == 16.0); - - int en_nucleus [3] = { 0, 0, 0 }; - rc = trexio_read_jastrow_en_nucleus(file, en_nucleus); - assert (rc == TREXIO_SUCCESS); - assert (en_nucleus[0] == 0); - assert (en_nucleus[1] == 1); - assert (en_nucleus[2] == 2); - - int een_nucleus [6] = { 0, 0, 0, 0, 0, 0 }; - rc = trexio_read_jastrow_een_nucleus(file, een_nucleus); - assert (rc == TREXIO_SUCCESS); - assert (een_nucleus[0] == 0); - assert (een_nucleus[1] == 0); - assert (een_nucleus[2] == 1); - assert (een_nucleus[3] == 1); - assert (een_nucleus[4] == 2); - assert (een_nucleus[5] == 2); - - double ee_scaling = 0.0; - rc = trexio_read_jastrow_ee_scaling(file, &ee_scaling); - assert (rc == TREXIO_SUCCESS); - assert (ee_scaling == 1.0); - - double en_scaling[3] = { 0.5, 1.0, 0.5 }; - rc = trexio_read_jastrow_en_scaling(file, en_scaling); - assert (rc == TREXIO_SUCCESS); - assert (en_scaling[0] == 0.5); - assert (en_scaling[1] == 1.0); - assert (en_scaling[2] == 0.5); - - rc = trexio_close(file); -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(){ - -/*============== Test launcher ================*/ - - int rc; - - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_jastrow (TREXIO_FILE, TEST_BACKEND); - test_read_jastrow (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/io_num.c b/tests/io_num.c new file mode 100644 index 0000000..fe55f83 --- /dev/null +++ b/tests/io_num.c @@ -0,0 +1,150 @@ +#include "trexio.h" +#include +#include +#include + +static int test_write_num (const char* file_name, const back_end_t backend) { + +/* Try to write a dimensioning attribute (num variable) into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 12; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // write numerical attribute in an empty file + rc = trexio_write_nucleus_num(file, num); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_nucleus_repulsion(file, 2.14171677); + assert (rc == TREXIO_SUCCESS); + + // attempt to write 0 as dimensioning variable in an empty file; should FAIL and return TREXIO_INVALID_ARG_2 + rc = trexio_write_mo_num(file, 0); + assert (rc == TREXIO_INVALID_NUM); + + // write numerical attribute ao_cartesian as 0 + rc = trexio_write_ao_cartesian(file, 0); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_has_num (const char* file_name, const back_end_t backend) { + +/* Try to check the existence of a dimensioning attribute (num variable) in the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // check that the previously written num variable exists + rc = trexio_has_nucleus_num(file); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_has_nucleus_repulsion(file); + assert (rc == TREXIO_SUCCESS); + + // check that the num variable does not exist + rc = trexio_has_mo_num(file); + assert (rc == TREXIO_HAS_NOT); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_read_num (const char* file_name, const back_end_t backend) { + +/* Try to read a dimensioning attribute (num variable) from the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be read + int num; + int cartesian; + float repulsion_32; + double repulsion_64, d; + +/*================= START OF TEST ==================*/ + + // open file in 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // read numerical attribute from the file + rc = trexio_read_nucleus_num(file, &num); + assert (rc == TREXIO_SUCCESS); + assert (num == 12); + + rc = trexio_read_nucleus_repulsion_32(file, &repulsion_32); + assert (rc == TREXIO_SUCCESS); + d = repulsion_32 - 2.14171677; + assert( d*d < 1.e-8 ); + + rc = trexio_read_nucleus_repulsion_64(file, &repulsion_64); + assert (rc == TREXIO_SUCCESS); + d = repulsion_64 - 2.14171677; + assert( d*d < 1.e-14 ); + + // read non-existing numerical attribute from the file + rc = trexio_read_mo_num(file, &num); + assert (rc == TREXIO_ATTR_MISSING); + + // read ao_cartesian (zero) value from the file + rc = trexio_read_ao_cartesian(file, &cartesian); + assert (rc == TREXIO_SUCCESS); + assert (cartesian == 0); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +int main(void) { + +/*============== Test launcher ================*/ + + int rc; + rc = system(RM_COMMAND); + assert (rc == 0); + + test_write_num (TREXIO_FILE, TEST_BACKEND); + test_has_num (TREXIO_FILE, TEST_BACKEND); + test_read_num (TREXIO_FILE, TEST_BACKEND); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} diff --git a/tests/io_num_hdf5.c b/tests/io_num_hdf5.c index 32de679..6c6f16b 100644 --- a/tests/io_num_hdf5.c +++ b/tests/io_num_hdf5.c @@ -1,154 +1,5 @@ -#include "trexio.h" -#include -#include -#include +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "io_num" +#include "test_macros.h" +#include "io_num.c" -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_num.h5" -#define RM_COMMAND "rm -rf " TREXIO_FILE - -static int test_write_num (const char* file_name, const back_end_t backend) { - -/* Try to write a dimensioning attribute (num variable) into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_repulsion(file, 2.14171677); - assert (rc == TREXIO_SUCCESS); - - // attempt to write 0 as dimensioning variable in an empty file; should FAIL and return TREXIO_INVALID_ARG_2 - rc = trexio_write_mo_num(file, 0); - assert (rc == TREXIO_INVALID_NUM); - - // write numerical attribute ao_cartesian as 0 - rc = trexio_write_ao_cartesian(file, 0); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_num (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dimensioning attribute (num variable) in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written num variable exists - rc = trexio_has_nucleus_num(file); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_has_nucleus_repulsion(file); - assert (rc == TREXIO_SUCCESS); - - // check that the num variable does not exist - rc = trexio_has_mo_num(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_num (const char* file_name, const back_end_t backend) { - -/* Try to read a dimensioning attribute (num variable) from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - int cartesian; - float repulsion_32; - double repulsion_64, d; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_nucleus_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - rc = trexio_read_nucleus_repulsion_32(file, &repulsion_32); - assert (rc == TREXIO_SUCCESS); - d = repulsion_32 - 2.14171677; - assert( d*d < 1.e-8 ); - - rc = trexio_read_nucleus_repulsion_64(file, &repulsion_64); - assert (rc == TREXIO_SUCCESS); - d = repulsion_64 - 2.14171677; - assert( d*d < 1.e-14 ); - - // read non-existing numerical attribute from the file - rc = trexio_read_mo_num(file, &num); - assert (rc == TREXIO_ATTR_MISSING); - - // read ao_cartesian (zero) value from the file - rc = trexio_read_ao_cartesian(file, &cartesian); - assert (rc == TREXIO_SUCCESS); - assert (cartesian == 0); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_num (TREXIO_FILE, TEST_BACKEND); - test_has_num (TREXIO_FILE, TEST_BACKEND); - test_read_num (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/io_num_text.c b/tests/io_num_text.c index 94fd488..3102d6d 100644 --- a/tests/io_num_text.c +++ b/tests/io_num_text.c @@ -1,154 +1,5 @@ -#include "trexio.h" -#include -#include -#include +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "io_num" +#include "test_macros.h" +#include "io_num.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_num.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write_num (const char* file_name, const back_end_t backend) { - -/* Try to write a dimensioning attribute (num variable) into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_repulsion(file, 2.14171677); - assert (rc == TREXIO_SUCCESS); - - // attempt to write 0 as dimensioning variable in an empty file; should FAIL and return TREXIO_INVALID_ARG_2 - rc = trexio_write_mo_num(file, 0); - assert (rc == TREXIO_INVALID_NUM); - - // write numerical attribute ao_cartesian as 0 - rc = trexio_write_ao_cartesian(file, 0); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_num (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dimensioning attribute (num variable) in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written num variable exists - rc = trexio_has_nucleus_num(file); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_has_nucleus_repulsion(file); - assert (rc == TREXIO_SUCCESS); - - // check that the num variable does not exist - rc = trexio_has_mo_num(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_num (const char* file_name, const back_end_t backend) { - -/* Try to read a dimensioning attribute (num variable) from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - int cartesian; - float repulsion_32; - double repulsion_64, d; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_nucleus_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - rc = trexio_read_nucleus_repulsion_32(file, &repulsion_32); - assert (rc == TREXIO_SUCCESS); - d = repulsion_32 - 2.14171677; - assert( d*d < 1.e-8 ); - - rc = trexio_read_nucleus_repulsion_64(file, &repulsion_64); - assert (rc == TREXIO_SUCCESS); - d = repulsion_64 - 2.14171677; - assert( d*d < 1.e-14 ); - - // read non-existing numerical attribute from the file - rc = trexio_read_mo_num(file, &num); - assert (rc == TREXIO_ATTR_MISSING); - - // read ao_cartesian (zero) value from the file - rc = trexio_read_ao_cartesian(file, &cartesian); - assert (rc == TREXIO_SUCCESS); - assert (cartesian == 0); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_num (TREXIO_FILE, TEST_BACKEND); - test_has_num (TREXIO_FILE, TEST_BACKEND); - test_read_num (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/io_safe_dset_float.c b/tests/io_safe_dset_float.c new file mode 100644 index 0000000..c4434b9 --- /dev/null +++ b/tests/io_safe_dset_float.c @@ -0,0 +1,161 @@ +#include "trexio.h" +#include +#include +#include +#include + +static int test_write_dset (const char* file_name, const back_end_t backend) { + +/* Try to write a dataset with floating point values into the TREXIO file using safe API */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 12; + double coord[36] = { + 0.00000000 , 1.39250319 , 0.00000000 , + -1.20594314 , 0.69625160 , 0.00000000 , + -1.20594314 , -0.69625160 , 0.00000000 , + 0.00000000 , -1.39250319 , 0.00000000 , + 1.20594314 , -0.69625160 , 0.00000000 , + 1.20594314 , 0.69625160 , 0.00000000 , + -2.14171677 , 1.23652075 , 0.00000000 , + -2.14171677 , -1.23652075 , 0.00000000 , + 0.00000000 , -2.47304151 , 0.00000000 , + 2.14171677 , -1.23652075 , 0.00000000 , + 2.14171677 , 1.23652075 , 0.00000000 , + 0.00000000 , 2.47304151 , 0.00000000 , + }; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // write numerical attribute in an empty file + rc = trexio_write_nucleus_num(file, num); + assert (rc == TREXIO_SUCCESS); + + /* write numerical dataset with an unsafe dimension + * this should return TREXIO_UNSAFE_ARRAY_DIM indicating + * that access beyong allocated memory is likely to occur */ + uint64_t dim_unsafe = num * 12; + rc = trexio_write_safe_nucleus_coord(file, coord, dim_unsafe); + assert (rc == TREXIO_UNSAFE_ARRAY_DIM); + + /* write numerical dataset with a safe dimension + * this should return TREXIO_SUCCESS */ + uint64_t dim_safe = num * 3; + rc = trexio_write_safe_nucleus_coord(file, coord, dim_safe); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_has_dset (const char* file_name, const back_end_t backend) { + +/* Try to check the existence of a dataset in the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // check that the previously written dataset exists + rc = trexio_has_nucleus_coord(file); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_read_dset (const char* file_name, const back_end_t backend) { + +/* Try to read a dataset with floating point values from the TREXIO file using safe API */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be read + int num; + double* coord; + +/*================= START OF TEST ==================*/ + + // open file in 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // read numerical attribute from the file + rc = trexio_read_nucleus_num(file, &num); + assert (rc == TREXIO_SUCCESS); + assert (num == 12); + + // read numerical (floating point) dataset from the file + coord = (double*) calloc(3*num, sizeof(double)); + + /* write numerical dataset with an unsafe dimension + * this should return TREXIO_UNSAFE_ARRAY_DIM indicating + * that access beyong allocated memory is likely to occur */ + uint64_t dim_unsafe = num * 12; + rc = trexio_read_safe_nucleus_coord(file, coord, dim_unsafe); + assert (rc == TREXIO_UNSAFE_ARRAY_DIM); + + /* write numerical dataset with a safe dimension + * this should return TREXIO_SUCCESS */ + uint64_t dim_safe = num * 3; + rc = trexio_read_safe_nucleus_coord(file, coord, dim_safe); + assert (rc == TREXIO_SUCCESS); + + double x = coord[30] - 2.14171677; + assert( x*x < 1.e-14 ); + free(coord); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +int main(void) { + +/*============== Test launcher ================*/ + + int rc; + rc = system(RM_COMMAND); + assert (rc == 0); + + test_write_dset (TREXIO_FILE, TEST_BACKEND); + test_has_dset (TREXIO_FILE, TEST_BACKEND); + test_read_dset (TREXIO_FILE, TEST_BACKEND); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} + + diff --git a/tests/io_safe_dset_float_hdf5.c b/tests/io_safe_dset_float_hdf5.c index 318ed4a..da8afe1 100644 --- a/tests/io_safe_dset_float_hdf5.c +++ b/tests/io_safe_dset_float_hdf5.c @@ -1,165 +1,5 @@ -#include "trexio.h" -#include -#include -#include -#include - -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_safe_dset_f.h5" -#define RM_COMMAND "rm -rf " TREXIO_FILE - -static int test_write_dset (const char* file_name, const back_end_t backend) { - -/* Try to write a dataset with floating point values into the TREXIO file using safe API */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - double coord[36] = { - 0.00000000 , 1.39250319 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 , - 1.20594314 , 0.69625160 , 0.00000000 , - -2.14171677 , 1.23652075 , 0.00000000 , - -2.14171677 , -1.23652075 , 0.00000000 , - 0.00000000 , -2.47304151 , 0.00000000 , - 2.14171677 , -1.23652075 , 0.00000000 , - 2.14171677 , 1.23652075 , 0.00000000 , - 0.00000000 , 2.47304151 , 0.00000000 , - }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - /* write numerical dataset with an unsafe dimension - * this should return TREXIO_UNSAFE_ARRAY_DIM indicating - * that access beyong allocated memory is likely to occur */ - uint64_t dim_unsafe = num * 12; - rc = trexio_write_safe_nucleus_coord(file, coord, dim_unsafe); - assert (rc == TREXIO_UNSAFE_ARRAY_DIM); - - /* write numerical dataset with a safe dimension - * this should return TREXIO_SUCCESS */ - uint64_t dim_safe = num * 3; - rc = trexio_write_safe_nucleus_coord(file, coord, dim_safe); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_dset (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dataset in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written dataset exists - rc = trexio_has_nucleus_coord(file); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_dset (const char* file_name, const back_end_t backend) { - -/* Try to read a dataset with floating point values from the TREXIO file using safe API */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - double* coord; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_nucleus_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - // read numerical (floating point) dataset from the file - coord = (double*) calloc(3*num, sizeof(double)); - - /* write numerical dataset with an unsafe dimension - * this should return TREXIO_UNSAFE_ARRAY_DIM indicating - * that access beyong allocated memory is likely to occur */ - uint64_t dim_unsafe = num * 12; - rc = trexio_read_safe_nucleus_coord(file, coord, dim_unsafe); - assert (rc == TREXIO_UNSAFE_ARRAY_DIM); - - /* write numerical dataset with a safe dimension - * this should return TREXIO_SUCCESS */ - uint64_t dim_safe = num * 3; - rc = trexio_read_safe_nucleus_coord(file, coord, dim_safe); - assert (rc == TREXIO_SUCCESS); - - double x = coord[30] - 2.14171677; - assert( x*x < 1.e-14 ); - free(coord); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_dset (TREXIO_FILE, TEST_BACKEND); - test_has_dset (TREXIO_FILE, TEST_BACKEND); - test_read_dset (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} - +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "io_safe_dset_float" +#include "test_macros.h" +#include "io_safe_dset_float.c" diff --git a/tests/io_safe_dset_float_text.c b/tests/io_safe_dset_float_text.c index bbd9b6b..7b5cc6e 100644 --- a/tests/io_safe_dset_float_text.c +++ b/tests/io_safe_dset_float_text.c @@ -1,163 +1,5 @@ -#include "trexio.h" -#include -#include -#include -#include +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "io_safe_dset_float" +#include "test_macros.h" +#include "io_safe_dset_float.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_safe_dset_f.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write_dset (const char* file_name, const back_end_t backend) { - -/* Try to write a dataset with floating point values into the TREXIO file using safe API */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - double coord[36] = { - 0.00000000 , 1.39250319 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 , - 1.20594314 , 0.69625160 , 0.00000000 , - -2.14171677 , 1.23652075 , 0.00000000 , - -2.14171677 , -1.23652075 , 0.00000000 , - 0.00000000 , -2.47304151 , 0.00000000 , - 2.14171677 , -1.23652075 , 0.00000000 , - 2.14171677 , 1.23652075 , 0.00000000 , - 0.00000000 , 2.47304151 , 0.00000000 , - }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write numerical attribute in an empty file - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - /* write numerical dataset with an unsafe dimension - * this should return TREXIO_UNSAFE_ARRAY_DIM indicating - * that access beyong allocated memory is likely to occur */ - uint64_t dim_unsafe = num * 12; - rc = trexio_write_safe_nucleus_coord(file, coord, dim_unsafe); - assert (rc == TREXIO_UNSAFE_ARRAY_DIM); - - /* write numerical dataset with a safe dimension - * this should return TREXIO_SUCCESS */ - uint64_t dim_safe = num * 3; - rc = trexio_write_safe_nucleus_coord(file, coord, dim_safe); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_dset (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a dataset in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written dataset exists - rc = trexio_has_nucleus_coord(file); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_dset (const char* file_name, const back_end_t backend) { - -/* Try to read a dataset with floating point values from the TREXIO file using safe API */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - int num; - double* coord; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read numerical attribute from the file - rc = trexio_read_nucleus_num(file, &num); - assert (rc == TREXIO_SUCCESS); - assert (num == 12); - - // read numerical (floating point) dataset from the file - coord = (double*) calloc(3*num, sizeof(double)); - - /* write numerical dataset with an unsafe dimension - * this should return TREXIO_UNSAFE_ARRAY_DIM indicating - * that access beyong allocated memory is likely to occur */ - uint64_t dim_unsafe = num * 12; - rc = trexio_read_safe_nucleus_coord(file, coord, dim_unsafe); - assert (rc == TREXIO_UNSAFE_ARRAY_DIM); - - /* write numerical dataset with a safe dimension - * this should return TREXIO_SUCCESS */ - uint64_t dim_safe = num * 3; - rc = trexio_read_safe_nucleus_coord(file, coord, dim_safe); - assert (rc == TREXIO_SUCCESS); - - double x = coord[30] - 2.14171677; - assert( x*x < 1.e-14 ); - free(coord); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_dset (TREXIO_FILE, TEST_BACKEND); - test_has_dset (TREXIO_FILE, TEST_BACKEND); - test_read_dset (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/io_str.c b/tests/io_str.c new file mode 100644 index 0000000..a0fdfab --- /dev/null +++ b/tests/io_str.c @@ -0,0 +1,129 @@ +#include "trexio.h" +#include +#include +#include +#include + +static int test_write_str (const char* file_name, const back_end_t backend) { + +/* Try to write a string attribute (single variable-length string) into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + const char* sym = "B3U with some comments"; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // write string attribute in an empty file + int max_str_len = 32; + rc = trexio_write_nucleus_point_group(file, sym, max_str_len); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_has_str (const char* file_name, const back_end_t backend) { + +/* Try to check the existence of a string attribute in the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // check that the previously written string attribute exists + rc = trexio_has_nucleus_point_group(file); + assert (rc == TREXIO_SUCCESS); + + // check that another string attribute does not exist + rc = trexio_has_mo_type(file); + assert (rc == TREXIO_HAS_NOT); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_read_str (const char* file_name, const back_end_t backend) { + +/* Try to read a string attribute from the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be read + char* sym; + +/*================= START OF TEST ==================*/ + + // open file in 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // read string attribute from the file + int max_str_len = 32; + sym = (char*) malloc(max_str_len*sizeof(char)); + + rc = trexio_read_nucleus_point_group(file, sym, max_str_len); + assert (rc == TREXIO_SUCCESS); + + char * pch; + pch = strtok(sym, " "); + assert (strcmp(pch, "B3U") == 0); + /* alternative test when 3 symbols are read from the file to sym */ + /*rc = trexio_read_nucleus_point_group(file, sym, 3); + assert (rc == TREXIO_SUCCESS); + assert (strcmp(sym, "B3U") == 0 );*/ + free(sym); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +int main(void) { + +/*============== Test launcher ================*/ + + int rc; + rc = system(RM_COMMAND); + assert (rc == 0); + + test_write_str (TREXIO_FILE, TEST_BACKEND); + test_has_str (TREXIO_FILE, TEST_BACKEND); + test_read_str (TREXIO_FILE, TEST_BACKEND); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} + + diff --git a/tests/io_str_hdf5.c b/tests/io_str_hdf5.c index eaafff0..58f0695 100644 --- a/tests/io_str_hdf5.c +++ b/tests/io_str_hdf5.c @@ -1,133 +1,5 @@ -#include "trexio.h" -#include -#include -#include -#include - -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_str.h5" -#define RM_COMMAND "rm -rf " TREXIO_FILE - -static int test_write_str (const char* file_name, const back_end_t backend) { - -/* Try to write a string attribute (single variable-length string) into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - const char* sym = "B3U with some comments"; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write string attribute in an empty file - int max_str_len = 32; - rc = trexio_write_nucleus_point_group(file, sym, max_str_len); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_str (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a string attribute in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written string attribute exists - rc = trexio_has_nucleus_point_group(file); - assert (rc == TREXIO_SUCCESS); - - // check that another string attribute does not exist - rc = trexio_has_mo_type(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_str (const char* file_name, const back_end_t backend) { - -/* Try to read a string attribute from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - char* sym; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read string attribute from the file - int max_str_len = 32; - sym = (char*) malloc(max_str_len*sizeof(char)); - - rc = trexio_read_nucleus_point_group(file, sym, max_str_len); - assert (rc == TREXIO_SUCCESS); - - char * pch; - pch = strtok(sym, " "); - assert (strcmp(pch, "B3U") == 0); - /* alternative test when 3 symbols are read from the file to sym */ - /*rc = trexio_read_nucleus_point_group(file, sym, 3); - assert (rc == TREXIO_SUCCESS); - assert (strcmp(sym, "B3U") == 0 );*/ - free(sym); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_str (TREXIO_FILE, TEST_BACKEND); - test_has_str (TREXIO_FILE, TEST_BACKEND); - test_read_str (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} - +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "io_str" +#include "test_macros.h" +#include "io_str.c" diff --git a/tests/io_str_text.c b/tests/io_str_text.c index 4aad28f..888d35b 100644 --- a/tests/io_str_text.c +++ b/tests/io_str_text.c @@ -1,131 +1,5 @@ -#include "trexio.h" -#include -#include -#include -#include +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "io_str" +#include "test_macros.h" +#include "io_str.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_str.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write_str (const char* file_name, const back_end_t backend) { - -/* Try to write a string attribute (single variable-length string) into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - const char* sym = "B3U with some comments"; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write string attribute in an empty file - int max_str_len = 32; - rc = trexio_write_nucleus_point_group(file, sym, max_str_len); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_has_str (const char* file_name, const back_end_t backend) { - -/* Try to check the existence of a string attribute in the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // check that the previously written string attribute exists - rc = trexio_has_nucleus_point_group(file); - assert (rc == TREXIO_SUCCESS); - - // check that another string attribute does not exist - rc = trexio_has_mo_type(file); - assert (rc == TREXIO_HAS_NOT); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_read_str (const char* file_name, const back_end_t backend) { - -/* Try to read a string attribute from the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be read - char* sym; - -/*================= START OF TEST ==================*/ - - // open file in 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read string attribute from the file - int max_str_len = 32; - sym = (char*) malloc(max_str_len*sizeof(char)); - - rc = trexio_read_nucleus_point_group(file, sym, max_str_len); - assert (rc == TREXIO_SUCCESS); - - char * pch; - pch = strtok(sym, " "); - assert (strcmp(pch, "B3U") == 0); - /* alternative test when 3 symbols are read from the file to sym */ - /*rc = trexio_read_nucleus_point_group(file, sym, 3); - assert (rc == TREXIO_SUCCESS); - assert (strcmp(sym, "B3U") == 0 );*/ - free(sym); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_write_str (TREXIO_FILE, TEST_BACKEND); - test_has_str (TREXIO_FILE, TEST_BACKEND); - test_read_str (TREXIO_FILE, TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/open.c b/tests/open.c new file mode 100644 index 0000000..db0bba7 --- /dev/null +++ b/tests/open.c @@ -0,0 +1,160 @@ +#include "trexio.h" +#include +#include +#include + +#define TREXIO_VOID "non_existing_" TREXIO_FILE + + +static int test_open_w (const char* file_name, const back_end_t backend) { + +/* Try to open the TREXIO file in 'write' mode */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_open_r (const char* file_name, const back_end_t backend) { + +/* Try to open the TREXIO file in 'read' mode */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_open_auto (const char* file_name) { + +/* Try to open the TREXIO file in 'read' mode */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'r', TREXIO_AUTO, &rc); + assert (file != NULL); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_open_errors (const back_end_t backend) { + +/* Try to call trexio_open with bad arguments */ + + trexio_t* file = NULL; + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // open non-existing file in 'r' (read) mode, should return TREXIO_OPEN_ERROR + file = trexio_open(TREXIO_VOID, 'r', backend, &rc); + assert (file == NULL); + assert (rc == TREXIO_OPEN_ERROR); + fprintf(stderr, "%s \n", trexio_string_of_error(rc)); + + // open file with empty file name, should return TREXIO_INVALID_ARG_1 + file = trexio_open("", 'w', backend, &rc); + assert (file == NULL); + assert (rc == TREXIO_INVALID_ARG_1); + fprintf(stderr, "%s \n", trexio_string_of_error(rc)); + + // open existing file in non-supported I/O mode, should return TREXIO_INVALID_ARG_2 + file = trexio_open(TREXIO_FILE, 'k', backend, &rc); + assert (file == NULL); + assert (rc == TREXIO_INVALID_ARG_2); + fprintf(stderr, "%s \n", trexio_string_of_error(rc)); + + // open existing file with non-supported back end, should return TREXIO_INVALID_ARG_3 + file = trexio_open(TREXIO_FILE, 'w', 666, &rc); + assert (file == NULL); + assert (rc == TREXIO_INVALID_ARG_3); + fprintf(stderr, "%s \n", trexio_string_of_error(rc)); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_inquire (const back_end_t backend) { + +/* Try to call trexio_inquire function */ + + trexio_exit_code rc; + +/*================= START OF TEST ==================*/ + + // inquire non-existing file + rc = trexio_inquire(TREXIO_VOID); + assert (rc == TREXIO_FAILURE); + + // inquire existing file + rc = trexio_inquire(TREXIO_FILE); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +int main(void) { + +/*============== Test launcher ================*/ + + int rc; + rc = system(RM_COMMAND); + assert (rc == 0); + + test_open_w (TREXIO_FILE, TEST_BACKEND); + test_open_r (TREXIO_FILE, TEST_BACKEND); + test_open_auto (TREXIO_FILE); + test_open_errors(TEST_BACKEND); + test_inquire (TEST_BACKEND); + + rc = system(RM_COMMAND); + assert (rc == 0); + + return 0; +} diff --git a/tests/open_hdf5.c b/tests/open_hdf5.c index d0a6581..029347d 100644 --- a/tests/open_hdf5.c +++ b/tests/open_hdf5.c @@ -1,163 +1,5 @@ -#include "trexio.h" -#include -#include -#include +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "open" +#include "test_macros.h" +#include "open.c" -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_open.h5" -#define TREXIO_VOID "non_existing_" TREXIO_FILE -#define RM_COMMAND "rm -rf " TREXIO_FILE - - -static int test_open_w (const char* file_name, const back_end_t backend) { - -/* Try to open the TREXIO file in 'write' mode */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_open_r (const char* file_name, const back_end_t backend) { - -/* Try to open the TREXIO file in 'read' mode */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_open_auto (const char* file_name) { - -/* Try to open the TREXIO file in 'read' mode */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'r', TREXIO_AUTO, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_open_errors (const back_end_t backend) { - -/* Try to call trexio_open with bad arguments */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open non-existing file in 'r' (read) mode, should return TREXIO_OPEN_ERROR - file = trexio_open(TREXIO_VOID, 'r', backend, &rc); - assert (file == NULL); - assert (rc == TREXIO_OPEN_ERROR); - fprintf(stderr, "%s \n", trexio_string_of_error(rc)); - - // open file with empty file name, should return TREXIO_INVALID_ARG_1 - file = trexio_open("", 'w', backend, &rc); - assert (file == NULL); - assert (rc == TREXIO_INVALID_ARG_1); - fprintf(stderr, "%s \n", trexio_string_of_error(rc)); - - // open existing file in non-supported I/O mode, should return TREXIO_INVALID_ARG_2 - file = trexio_open(TREXIO_FILE, 'k', backend, &rc); - assert (file == NULL); - assert (rc == TREXIO_INVALID_ARG_2); - fprintf(stderr, "%s \n", trexio_string_of_error(rc)); - - // open existing file with non-supported back end, should return TREXIO_INVALID_ARG_3 - file = trexio_open(TREXIO_FILE, 'w', 666, &rc); - assert (file == NULL); - assert (rc == TREXIO_INVALID_ARG_3); - fprintf(stderr, "%s \n", trexio_string_of_error(rc)); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_inquire (const back_end_t backend) { - -/* Try to call trexio_inquire function */ - - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // inquire non-existing file - rc = trexio_inquire(TREXIO_VOID); - assert (rc == TREXIO_FAILURE); - - // inquire existing file - rc = trexio_inquire(TREXIO_FILE); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_open_w (TREXIO_FILE, TEST_BACKEND); - test_open_r (TREXIO_FILE, TEST_BACKEND); - test_open_auto (TREXIO_FILE); - test_open_errors(TEST_BACKEND); - test_inquire (TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/open_text.c b/tests/open_text.c index 4e43501..a4f3cd9 100644 --- a/tests/open_text.c +++ b/tests/open_text.c @@ -1,163 +1,5 @@ -#include "trexio.h" -#include -#include -#include +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "open" +#include "test_macros.h" +#include "open.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_open.dir" -#define TREXIO_VOID "non_existing_" TREXIO_FILE -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - - -static int test_open_w (const char* file_name, const back_end_t backend) { - -/* Try to open the TREXIO file in 'write' mode */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_open_r (const char* file_name, const back_end_t backend) { - -/* Try to open the TREXIO file in 'read' mode */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_open_auto (const char* file_name) { - -/* Try to open the TREXIO file in 'read' mode */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'r', TREXIO_AUTO, &rc); - assert (file != NULL); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_open_errors (const back_end_t backend) { - -/* Try to call trexio_open with bad arguments */ - - trexio_t* file = NULL; - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // open non-existing file in 'r' (read) mode, should return TREXIO_OPEN_ERROR - file = trexio_open(TREXIO_VOID, 'r', backend, &rc); - assert (file == NULL); - assert (rc == TREXIO_OPEN_ERROR); - fprintf(stderr, "%s \n", trexio_string_of_error(rc)); - - // open file with empty file name, should return TREXIO_INVALID_ARG_1 - file = trexio_open("", 'w', backend, &rc); - assert (file == NULL); - assert (rc == TREXIO_INVALID_ARG_1); - fprintf(stderr, "%s \n", trexio_string_of_error(rc)); - - // open existing file in non-supported I/O mode, should return TREXIO_INVALID_ARG_2 - file = trexio_open(TREXIO_FILE, 'k', backend, &rc); - assert (file == NULL); - assert (rc == TREXIO_INVALID_ARG_2); - fprintf(stderr, "%s \n", trexio_string_of_error(rc)); - - // open existing file with non-supported back end, should return TREXIO_INVALID_ARG_3 - file = trexio_open(TREXIO_FILE, 'w', 666, &rc); - assert (file == NULL); - assert (rc == TREXIO_INVALID_ARG_3); - fprintf(stderr, "%s \n", trexio_string_of_error(rc)); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_inquire (const back_end_t backend) { - -/* Try to call trexio_inquire function */ - - trexio_exit_code rc; - -/*================= START OF TEST ==================*/ - - // inquire non-existing file - rc = trexio_inquire(TREXIO_VOID); - assert (rc == TREXIO_FAILURE); - - // inquire existing file - rc = trexio_inquire(TREXIO_FILE); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int main(void) { - -/*============== Test launcher ================*/ - - int rc; - rc = system(RM_COMMAND); - assert (rc == 0); - - test_open_w (TREXIO_FILE, TEST_BACKEND); - test_open_r (TREXIO_FILE, TEST_BACKEND); - test_open_auto (TREXIO_FILE); - test_open_errors(TEST_BACKEND); - test_inquire (TEST_BACKEND); - - rc = system(RM_COMMAND); - assert (rc == 0); - - return 0; -} diff --git a/tests/overwrite_all.c b/tests/overwrite_all.c new file mode 100644 index 0000000..b2236d7 --- /dev/null +++ b/tests/overwrite_all.c @@ -0,0 +1,262 @@ +#include "trexio.h" +#include +#include +#include +#include + +static int test_write (const char* file_name, const back_end_t backend) { + +/* Try to write a full set of data (num+dset_num+str+dset_str) related to benzene molecule into the TREXIO file */ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 12; + double coord[36] = { + 0.00000000 , 1.39250319 , 0.00000000 , + -1.20594314 , 0.69625160 , 0.00000000 , + -1.20594314 , -0.69625160 , 0.00000000 , + 0.00000000 , -1.39250319 , 0.00000000 , + 1.20594314 , -0.69625160 , 0.00000000 , + 1.20594314 , 0.69625160 , 0.00000000 , + -2.14171677 , 1.23652075 , 0.00000000 , + -2.14171677 , -1.23652075 , 0.00000000 , + 0.00000000 , -2.47304151 , 0.00000000 , + 2.14171677 , -1.23652075 , 0.00000000 , + 2.14171677 , 1.23652075 , 0.00000000 , + 0.00000000 , 2.47304151 , 0.00000000 , + }; + const char* sym = "D6h"; + const char* labels[] = {"C" , + "C" , + "C" , + "C" , + "C" , + "C" , + "H" , + "H" , + "H" , + "H" , + "H" , + "H" }; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // write the data + rc = trexio_write_nucleus_num(file, num); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_nucleus_coord(file, coord); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_nucleus_point_group(file, sym, 4); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_nucleus_label(file, labels, 2); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_overwrite_unsafe (const char* file_name, const back_end_t backend) { + +/* Try to overwrite the data that already exists in the TREXIO file which is open in UNSAFE mode*/ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 5; + double coord[15] = { + 0.00000000 , 666.666 , 0.00000000 , + -1.20594314 , 0.69625160 , 0.00000000 , + -1.20594314 , -0.69625160 , 0.00000000 , + 0.00000000 , -1.39250319 , 0.00000000 , + 1.20594314 , -0.69625160 , 0.00000000 + }; + const char* sym = "Unknown"; + const char* labels[] = {"Ru" , + "U" , + "Cl" , + "Na" , + "H" }; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'u', backend, &rc); + assert (file != NULL); + + // check that the previously written data cannot be overwritten + rc = trexio_write_nucleus_num(file, num); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_nucleus_coord(file, coord); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_nucleus_point_group(file, sym, 16); + assert (rc == TREXIO_SUCCESS); + + rc = trexio_write_nucleus_label(file, labels, 4); + assert (rc == TREXIO_SUCCESS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +static int test_overwrite_safe (const char* file_name, const back_end_t backend) { + +/* Try to overwrite the data that already exists in the TREXIO file which is open in SAFE mode*/ + + trexio_t* file = NULL; + trexio_exit_code rc; + + // parameters to be written + int num = 24; + double coord[3] = { + 0.00000000 , 666.666, 0.00000000 , + }; + const char* sym = "Unknown"; + const char* labels[] = {"Ru" , + "U" , + "Cl" , + "Na" , + "H" }; + +/*================= START OF TEST ==================*/ + + // open file in 'write' mode + file = trexio_open(file_name, 'w', backend, &rc); + assert (file != NULL); + + // check that the previously written data cannot be overwritten + rc = trexio_write_nucleus_num(file, num); + assert (rc == TREXIO_ATTR_ALREADY_EXISTS); + + rc = trexio_write_nucleus_coord(file, coord); + assert (rc == TREXIO_DSET_ALREADY_EXISTS); + + rc = trexio_write_nucleus_point_group(file, sym, 16); + assert (rc == TREXIO_ATTR_ALREADY_EXISTS); + + rc = trexio_write_nucleus_label(file, labels, 4); + assert (rc == TREXIO_DSET_ALREADY_EXISTS); + + // close current session + rc = trexio_close(file); + assert (rc == TREXIO_SUCCESS); + +/*================= END OF TEST ==================*/ + + return 0; +} + + +int test_read(const char* file_name, const back_end_t backend) { + +/*========= Test read ===========*/ + + trexio_t* file = NULL; + trexio_exit_code rc; + + int num; + double* coord; + char** label; + char* point_group; + +/*================= START OF TEST ==================*/ + + // open existing file on 'read' mode + file = trexio_open(file_name, 'r', backend, &rc); + assert (file != NULL); + + // read nucleus_num + rc = trexio_read_nucleus_num(file,&num); + assert (rc == TREXIO_SUCCESS); + assert (num == 5); + + // read nucleus_coord + coord = (double*) calloc(3*num, sizeof(double)); + rc = trexio_read_nucleus_coord(file,coord); + assert (rc == TREXIO_SUCCESS); + + double x = coord[1] - 666.666; + assert( x*x < 1.e-14); + free(coord); + + // read nucleus_label + label = (char**) malloc(num*sizeof(char*)); + for (int i=0; i -#include -#include -#include +#define TEST_BACKEND_HDF5 +#define TREXIO_FILE_PREFIX "overwrite_all" +#include "test_macros.h" +#include "overwrite_all.c" -#define TEST_BACKEND TREXIO_HDF5 -#define TREXIO_FILE "test_over.h5" -#define RM_COMMAND "rm -f -- " TREXIO_FILE - -static int test_write (const char* file_name, const back_end_t backend) { - -/* Try to write a full set of data (num+dset_num+str+dset_str) related to benzene molecule into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - double coord[36] = { - 0.00000000 , 1.39250319 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 , - 1.20594314 , 0.69625160 , 0.00000000 , - -2.14171677 , 1.23652075 , 0.00000000 , - -2.14171677 , -1.23652075 , 0.00000000 , - 0.00000000 , -2.47304151 , 0.00000000 , - 2.14171677 , -1.23652075 , 0.00000000 , - 2.14171677 , 1.23652075 , 0.00000000 , - 0.00000000 , 2.47304151 , 0.00000000 , - }; - const char* sym = "D6h"; - const char* labels[] = {"C" , - "C" , - "C" , - "C" , - "C" , - "C" , - "H" , - "H" , - "H" , - "H" , - "H" , - "H" }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write the data - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_point_group(file, sym, 4); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_label(file, labels, 2); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_overwrite_unsafe (const char* file_name, const back_end_t backend) { - -/* Try to overwrite the data that already exists in the TREXIO file which is open in UNSAFE mode*/ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 5; - double coord[15] = { - 0.00000000 , 666.666 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 - }; - const char* sym = "Unknown"; - const char* labels[] = {"Ru" , - "U" , - "Cl" , - "Na" , - "H" }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'u', backend, &rc); - assert (file != NULL); - - // check that the previously written data cannot be overwritten - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_point_group(file, sym, 16); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_label(file, labels, 4); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_overwrite_safe (const char* file_name, const back_end_t backend) { - -/* Try to overwrite the data that already exists in the TREXIO file which is open in SAFE mode*/ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 24; - double coord[3] = { - 0.00000000 , 666.666, 0.00000000 , - }; - const char* sym = "Unknown"; - const char* labels[] = {"Ru" , - "U" , - "Cl" , - "Na" , - "H" }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // check that the previously written data cannot be overwritten - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_ATTR_ALREADY_EXISTS); - - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_DSET_ALREADY_EXISTS); - - rc = trexio_write_nucleus_point_group(file, sym, 16); - assert (rc == TREXIO_ATTR_ALREADY_EXISTS); - - rc = trexio_write_nucleus_label(file, labels, 4); - assert (rc == TREXIO_DSET_ALREADY_EXISTS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int test_read(const char* file_name, const back_end_t backend) { - -/*========= Test read ===========*/ - - trexio_t* file = NULL; - trexio_exit_code rc; - - int num; - double* coord; - char** label; - char* point_group; - -/*================= START OF TEST ==================*/ - - // open existing file on 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read nucleus_num - rc = trexio_read_nucleus_num(file,&num); - assert (rc == TREXIO_SUCCESS); - assert (num == 5); - - // read nucleus_coord - coord = (double*) calloc(3*num, sizeof(double)); - rc = trexio_read_nucleus_coord(file,coord); - assert (rc == TREXIO_SUCCESS); - - double x = coord[1] - 666.666; - assert( x*x < 1.e-14); - free(coord); - - // read nucleus_label - label = (char**) malloc(num*sizeof(char*)); - for (int i=0; i -#include -#include -#include +#define TEST_BACKEND_TEXT +#define TREXIO_FILE_PREFIX "overwrite_all" +#include "test_macros.h" +#include "overwrite_all.c" -#define TEST_BACKEND TREXIO_TEXT -#define TREXIO_FILE "test_over.dir" -#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE - -static int test_write (const char* file_name, const back_end_t backend) { - -/* Try to write a full set of data (num+dset_num+str+dset_str) related to benzene molecule into the TREXIO file */ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 12; - double coord[36] = { - 0.00000000 , 1.39250319 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 , - 1.20594314 , 0.69625160 , 0.00000000 , - -2.14171677 , 1.23652075 , 0.00000000 , - -2.14171677 , -1.23652075 , 0.00000000 , - 0.00000000 , -2.47304151 , 0.00000000 , - 2.14171677 , -1.23652075 , 0.00000000 , - 2.14171677 , 1.23652075 , 0.00000000 , - 0.00000000 , 2.47304151 , 0.00000000 , - }; - const char* sym = "D6h"; - const char* labels[] = {"C" , - "C" , - "C" , - "C" , - "C" , - "C" , - "H" , - "H" , - "H" , - "H" , - "H" , - "H" }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // write the data - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_point_group(file, sym, 4); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_label(file, labels, 2); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_overwrite_unsafe (const char* file_name, const back_end_t backend) { - -/* Try to overwrite the data that already exists in the TREXIO file which is open in UNSAFE mode*/ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 5; - double coord[15] = { - 0.00000000 , 666.666 , 0.00000000 , - -1.20594314 , 0.69625160 , 0.00000000 , - -1.20594314 , -0.69625160 , 0.00000000 , - 0.00000000 , -1.39250319 , 0.00000000 , - 1.20594314 , -0.69625160 , 0.00000000 - }; - const char* sym = "Unknown"; - const char* labels[] = {"Ru" , - "U" , - "Cl" , - "Na" , - "H" }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'u', backend, &rc); - assert (file != NULL); - - // check that the previously written data cannot be overwritten - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_point_group(file, sym, 16); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_write_nucleus_label(file, labels, 4); - assert (rc == TREXIO_SUCCESS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -static int test_overwrite_safe (const char* file_name, const back_end_t backend) { - -/* Try to overwrite the data that already exists in the TREXIO file which is open in SAFE mode*/ - - trexio_t* file = NULL; - trexio_exit_code rc; - - // parameters to be written - int num = 24; - double coord[3] = { - 0.00000000 , 666.666, 0.00000000 , - }; - const char* sym = "Unknown"; - const char* labels[] = {"Ru" , - "U" , - "Cl" , - "Na" , - "H" }; - -/*================= START OF TEST ==================*/ - - // open file in 'write' mode - file = trexio_open(file_name, 'w', backend, &rc); - assert (file != NULL); - - // check that the previously written data cannot be overwritten - rc = trexio_write_nucleus_num(file, num); - assert (rc == TREXIO_ATTR_ALREADY_EXISTS); - - rc = trexio_write_nucleus_coord(file, coord); - assert (rc == TREXIO_DSET_ALREADY_EXISTS); - - rc = trexio_write_nucleus_point_group(file, sym, 16); - assert (rc == TREXIO_ATTR_ALREADY_EXISTS); - - rc = trexio_write_nucleus_label(file, labels, 4); - assert (rc == TREXIO_DSET_ALREADY_EXISTS); - - // close current session - rc = trexio_close(file); - assert (rc == TREXIO_SUCCESS); - -/*================= END OF TEST ==================*/ - - return 0; -} - - -int test_read(const char* file_name, const back_end_t backend) { - -/*========= Test read ===========*/ - - trexio_t* file = NULL; - trexio_exit_code rc; - - int num; - double* coord; - char** label; - char* point_group; - -/*================= START OF TEST ==================*/ - - // open existing file on 'read' mode - file = trexio_open(file_name, 'r', backend, &rc); - assert (file != NULL); - - // read nucleus_num - rc = trexio_read_nucleus_num(file,&num); - assert (rc == TREXIO_SUCCESS); - assert (num == 5); - - // read nucleus_coord - coord = (double*) calloc(3*num, sizeof(double)); - rc = trexio_read_nucleus_coord(file,coord); - assert (rc == TREXIO_SUCCESS); - - double x = coord[1] - 666.666; - assert( x*x < 1.e-14); - free(coord); - - // read nucleus_label - label = (char**) malloc(num*sizeof(char*)); - for (int i=0; i +#include +#include +#include + +#ifdef TEST_BACKEND_HDF5 +#define TEST_BACKEND TREXIO_HDF5 +#define TREXIO_FILE TREXIO_FILE_PREFIX ".h5" +#define RM_COMMAND "rm -f -- " TREXIO_FILE +#endif + + +#ifdef TEST_BACKEND_TEXT +#define TEST_BACKEND TREXIO_TEXT +#define TREXIO_FILE TREXIO_FILE_PREFIX ".dir" +#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE +#endif + + From 0d37dcd97b7a511df96b67fe68fb7e55499b7841 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 5 May 2023 12:30:32 +0200 Subject: [PATCH 07/20] Fixes #116 --- src/pytrexio.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytrexio.i b/src/pytrexio.i index b6e5485..c7eea59 100644 --- a/src/pytrexio.i +++ b/src/pytrexio.i @@ -41,7 +41,7 @@ %apply int *OUTPUT { int64_t* const num_up}; %apply int *OUTPUT { int64_t* const num_dn}; %apply float *OUTPUT { float* const num}; -%apply float *OUTPUT { double* const num}; +%apply double *OUTPUT { double* const num}; /* Return TREXIO exit code from trexio_open as part of the output tuple */ %apply int *OUTPUT { trexio_exit_code* const rc_open}; /* Return number of sparse data points stored in the file as part of the output tuple */ From 8f5220b0ea60f57c20aac2ac4d9db5426f047286 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 5 May 2023 12:44:08 +0200 Subject: [PATCH 08/20] [wheel build] Fix single-precision in float scalars --- python/pytrexio/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pytrexio/_version.py b/python/pytrexio/_version.py index 9c73af2..f708a9b 100644 --- a/python/pytrexio/_version.py +++ b/python/pytrexio/_version.py @@ -1 +1 @@ -__version__ = "1.3.1" +__version__ = "1.3.2" From db7311e16a9217ba82677327bf992b0b3872ee73 Mon Sep 17 00:00:00 2001 From: Evgeny Posenitskiy <45995097+q-posev@users.noreply.github.com> Date: Mon, 8 May 2023 16:38:07 +0200 Subject: [PATCH 09/20] [skip ci] Add citations --- CITATION.cff | 28 ++++++++++++++++++++++++++++ README.md | 24 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 CITATION.cff diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..65bd022 --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,28 @@ +cff-version: 1.2.0 +message: "If you use this software, please cite it as below." +authors: +- family-names: "Scemama" + given-names: "Anthony" + orcid: "https://orcid.org/0000-0003-4955-7136" +- family-names: "Posenitskiy" + given-names: "Evgeny" + orcid: "https://orcid.org/0000-0002-1623-0594" +title: "TREX I/O library " +version: 2.3.1 +date-released: 2023-04-26 +url: "https://github.com/TREX-CoE/trexio" +preferred-citation: + type: article + authors: + - family-names: "Posenitskiy" + given-names: "Evgeny" + - family-names: "et al." + given-names: "" + doi: "10.1063/5.0148161" + journal: "The Journal of Chemical Physics" + month: 5 + start: 174801 # First page number + title: "TREXIO: A file format and library for quantum chemistry" + issue: 17 + volume: 158 + year: 2023 \ No newline at end of file diff --git a/README.md b/README.md index a313092..a430805 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,30 @@ For example, the tutorial covering TREXIO basics using benzene molecule as an ex [Documentation generated from TREXIO org-mode files.](https://trex-coe.github.io/trexio/) +## Citation + +The journal article reference describing TREXIO can be cited as follows: + +``` +@article{10.1063/5.0148161, + author = {Posenitskiy, Evgeny and Chilkuri, Vijay Gopal and Ammar, Abdallah and Hapka, Michał and Pernal, Katarzyna and Shinde, Ravindra and Landinez Borda, Edgar Josué and Filippi, Claudia and Nakano, Kosuke and Kohulák, Otto and Sorella, Sandro and de Oliveira Castro, Pablo and Jalby, William and Ríos, Pablo López and Alavi, Ali and Scemama, Anthony}, + title = "{TREXIO: A file format and library for quantum chemistry}", + journal = {The Journal of Chemical Physics}, + volume = {158}, + number = {17}, + year = {2023}, + month = {05}, + issn = {0021-9606}, + doi = {10.1063/5.0148161}, + url = {https://doi.org/10.1063/5.0148161}, + note = {174801}, + eprint = {https://pubs.aip.org/aip/jcp/article-pdf/doi/10.1063/5.0148161/17355866/174801\_1\_5.0148161.pdf}, +} +``` + +Journal paper: [![doi](https://img.shields.io/badge/doi-10.1063/5.0148161-5077AB.svg)](https://doi.org/10.1063/5.0148161) +ArXiv paper: [![arXiv](https://img.shields.io/badge/arXiv-2302.14793-b31b1b.svg)](https://arxiv.org/abs/2302.14793) + ### Miscellaneous Note: The code should be compliant with the C99 From 1bd70ed0023854eb2251f97aa2db8bf9fbfcacaf Mon Sep 17 00:00:00 2001 From: Evgeny Posenitskiy <45995097+q-posev@users.noreply.github.com> Date: Mon, 8 May 2023 16:41:40 +0200 Subject: [PATCH 10/20] [skip ci] Formatting --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a430805..2d76146 100644 --- a/README.md +++ b/README.md @@ -230,11 +230,12 @@ The journal article reference describing TREXIO can be cited as follows: ``` Journal paper: [![doi](https://img.shields.io/badge/doi-10.1063/5.0148161-5077AB.svg)](https://doi.org/10.1063/5.0148161) + ArXiv paper: [![arXiv](https://img.shields.io/badge/arXiv-2302.14793-b31b1b.svg)](https://arxiv.org/abs/2302.14793) ### Miscellaneous -Note: The code should be compliant with the C99 +The code should be compliant with the C99 [CERT C coding standard](https://resources.sei.cmu.edu/downloads/secure-coding/assets/sei-cert-c-coding-standard-2016-v01.pdf). This can be checked with the `cppcheck` tool. From 8b3d237c1fb3f1420e3eef4e9479e2176498cd31 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 10 May 2023 15:52:50 +0200 Subject: [PATCH 11/20] Working on io_dset_sparse.c. Not finished --- tests/io_dset_sparse.c | 95 ++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/tests/io_dset_sparse.c b/tests/io_dset_sparse.c index 3a20174..4f0259b 100644 --- a/tests/io_dset_sparse.c +++ b/tests/io_dset_sparse.c @@ -4,10 +4,9 @@ #include #include -#define SIZE 100 -#define N_CHUNKS 5 +#define N_CHUNKS 4 -static int test_write_dset_sparse (const char* file_name, const back_end_t backend, const int64_t offset) { +static int test_write_dset_sparse (const char* file_name, const back_end_t backend, const int64_t offset, const int64_t mo_num) { /* Try to write an array of sparse data into the TREXIO file */ @@ -24,26 +23,25 @@ static int test_write_dset_sparse (const char* file_name, const back_end_t backe // parameters to be written int32_t* index; double* value; + int64_t size = mo_num/2; - index = calloc(4L*SIZE, sizeof(int32_t)); - value = calloc(SIZE, sizeof(double)); + index = calloc(4L*size, sizeof(int32_t)); + value = calloc(size, sizeof(double)); - for(int i=0; i size_max) - offset_file_read = 97L; - offset_data_read = 1; - int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 + int64_t size_max; + rc = trexio_read_mo_2e_int_eri_size(file, &size_max); + assert(rc == TREXIO_SUCCESS); + offset_file_read = size_max-chunk_read+1L; + offset_data_read = 1L; + int64_t eof_read_size_check = size_max - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 if (offset != 0L) offset_file_read += offset; // read one chunk that will reach EOF and return TREXIO_END code rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]); assert(rc == TREXIO_END); + for (int i=0 ; i Date: Wed, 10 May 2023 15:53:38 +0200 Subject: [PATCH 12/20] Improve Makefile.am --- Makefile.am | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 2209dad..5b5f2e9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,9 +77,11 @@ endif ORG_FILES = \ src/templates_front/templator_front.org \ src/templates_text/templator_text.org \ - src/templates_hdf5/templator_hdf5.org \ trex.org +if HAVE_HDF5 +ORG_FILES += src/templates_hdf5/templator_hdf5.org +endif src_libtrexio_la_SOURCES = $(trexio_h) $(SOURCES) @@ -160,11 +162,13 @@ EXTRA_DIST += $(trexio_scm) HTML_TANGLED = docs/index.html \ docs/examples.html \ - docs/templator_hdf5.html \ docs/trex.html \ docs/README.html \ docs/templator_front.html \ docs/templator_text.html +if HAVE_HDF5 +HTML_TANGLED += docs/templator_hdf5.html +endif htmldir = $(docdir) # This $(htmlizer) file and the corresponding target rule allow to avoid circular dependency, From d4d6da98507a86baa9a3e323a66630ee5acbde84 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 10 May 2023 16:02:57 +0200 Subject: [PATCH 13/20] Fix no-HDF5 --- configure.ac | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index dede482..376f6c7 100644 --- a/configure.ac +++ b/configure.ac @@ -130,8 +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"], [ - AC_DEFINE([HAVE_HDF5], 0, [Define to 1 if HDF5 is available]) ], +AS_IF([test "x$with_hdf5" == "xno"], [], [test "x$with_hdf5" != "xyes"], [ HDF5_LIBS="-lhdf5" HDF5_PATH="$with_hdf5" From 7edde4f1fb61605e00a76729dd8f90eacfee70ee Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 11 May 2023 23:08:37 +0200 Subject: [PATCH 14/20] Bump to version 2.3.2 with #118 --- CMakeLists.txt | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bda21c..d30e54a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.16) # Initialize the CMake project. project(Trexio - VERSION 2.3.1 + VERSION 2.3.2 DESCRIPTION "TREX I/O library" LANGUAGES C Fortran ) diff --git a/configure.ac b/configure.ac index 376f6c7..5228d29 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([trexio],[2.3.1],[https://github.com/TREX-CoE/trexio/issues]) +AC_INIT([trexio],[2.3.2],[https://github.com/TREX-CoE/trexio/issues]) AC_CONFIG_SRCDIR([Makefile.in]) AC_CONFIG_HEADERS([include/config.h]) From 8e48c75348fda686ca3713b87a65ceb2d92d4a4b Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 11 May 2023 23:11:52 +0200 Subject: [PATCH 15/20] Fixing MacOS builds --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 70f0b28..40fa30e 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -121,7 +121,7 @@ jobs: - name: install dependencies run: | brew install emacs - brew install hdf5@1.12 + brew install hdf5 brew install automake brew --prefix hdf5 From efd7fab7ed23e6fe850e079488b264034262978b Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 12 May 2023 01:33:57 +0200 Subject: [PATCH 16/20] state_id is an index+added energy --- CMakeLists.txt | 2 +- ChangeLog | 6 ++++++ configure.ac | 2 +- trex.org | 26 ++++++++++++++------------ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d30e54a..d680079 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.16) # Initialize the CMake project. project(Trexio - VERSION 2.3.2 + VERSION 2.4.0 DESCRIPTION "TREX I/O library" LANGUAGES C Fortran ) diff --git a/ChangeLog b/ChangeLog index 56c8f04..c5b9e36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ CHANGES ======= +2.4 +--- + +- Added state/energy +- Made state/id an index instead of an int + 2.3 --- diff --git a/configure.ac b/configure.ac index 5228d29..b8f26a7 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([trexio],[2.3.2],[https://github.com/TREX-CoE/trexio/issues]) +AC_INIT([trexio],[2.4.0],[https://github.com/TREX-CoE/trexio/issues]) AC_CONFIG_SRCDIR([Makefile.in]) AC_CONFIG_HEADERS([include/config.h]) diff --git a/trex.org b/trex.org index ba901a0..101040c 100644 --- a/trex.org +++ b/trex.org @@ -190,13 +190,14 @@ The ~id~ and ~current_label~ attributes need to be specified for each file. #+NAME: state - | Variable | Type | Dimensions | Description | - |-----------------+-------+---------------+---------------------------------------------------------------------------------------------| - | ~num~ | ~dim~ | | Number of states (including the ground state) | - | ~id~ | ~int~ | | Index of the current state (0 is ground state) | - | ~current_label~ | ~str~ | | Label of the current state | - | ~label~ | ~str~ | ~(state.num)~ | Labels of all states | - | ~file_name~ | ~str~ | ~(state.num)~ | Names of the TREXIO files linked to the current one (i.e. containing data for other states) | + | Variable | Type | Dimensions | Description | + |-----------------+---------+---------------+---------------------------------------------------------------------------------------------| + | ~num~ | ~dim~ | | Number of states (including the ground state) | + | ~id~ | ~index~ | | Index of the current state (0 is ground state) | + | ~energy~ | ~float~ | | Energy of the current state | + | ~current_label~ | ~str~ | | Label of the current state | + | ~label~ | ~str~ | ~(state.num)~ | Labels of all states | + | ~file_name~ | ~str~ | ~(state.num)~ | Names of the TREXIO files linked to the current one (i.e. containing data for other states) | #+CALL: json(data=state, title="state") @@ -204,11 +205,12 @@ :results: #+begin_src python :tangle trex.json "state": { - "num" : [ "dim", [] ] - , "id" : [ "int", [] ] - , "current_label" : [ "str", [] ] - , "label" : [ "str", [ "state.num" ] ] - , "file_name" : [ "str", [ "state.num" ] ] + "num" : [ "dim" , [] ] + , "id" : [ "index", [] ] + , "energy" : [ "float", [] ] + , "current_label" : [ "str" , [] ] + , "label" : [ "str" , [ "state.num" ] ] + , "file_name" : [ "str" , [ "state.num" ] ] } , #+end_src :end: From a1ed253dc4debba009dc4a9351e5b95d5841728a Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 12 May 2023 12:30:00 +0200 Subject: [PATCH 17/20] Implemented index for scalar values --- python/pytrexio/_version.py | 2 +- src/templates_front/templator_front.org | 57 ++++++++++++++++++++----- tests/io_dset_int_hdf5.c | 15 ++++++- tests/io_dset_int_text.c | 15 ++++++- tests/test_f.f90 | 16 +++++++ tools/generator_tools.py | 5 +++ 6 files changed, 94 insertions(+), 16 deletions(-) diff --git a/python/pytrexio/_version.py b/python/pytrexio/_version.py index f708a9b..3d67cd6 100644 --- a/python/pytrexio/_version.py +++ b/python/pytrexio/_version.py @@ -1 +1 @@ -__version__ = "1.3.2" +__version__ = "2.4.0" diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 91bfdf8..5db927f 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -1732,6 +1732,12 @@ def _cp(source: str, destination: str): and write it as ~state_id~ attribute. ~trexio_get_state~ returns current state of the ~trexio_t~ file handle. + **Warning:** The ~trexio_set_state~ and ~trexio_get_state~ functions still + use the old convention where the ground state was state ~0~. From version 2.4.0, + the ~state_id~ variable has changed to ~index~ type, so using the more recent + ~trexio_write_state_id~ and ~trexio_read_state_id~ will give different results + in Fortran. + input parameters: ~file~ -- TREXIO file handle. ~state~ -- ~int32_t~ ID of a state (0 for ground state). @@ -2132,24 +2138,35 @@ trexio_read_$group_num$_64 (trexio_t* const file, $group_num_dtype_double$* cons if (num == NULL) return TREXIO_INVALID_ARG_2; if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING; + trexio_exit_code rc = TREXIO_GROUP_READ_ERROR; + switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_read_$group_num$(file, num); + rc = trexio_text_read_$group_num$(file, num); + break; case TREXIO_HDF5: #ifdef HAVE_HDF5 - return trexio_hdf5_read_$group_num$(file, num); + rc = trexio_hdf5_read_$group_num$(file, num); #else - return TREXIO_BACK_END_MISSING; + rc = TREXIO_BACK_END_MISSING; #endif + break; /* case TREXIO_JSON: - return trexio_json_read_$group_num$(file, num); + rc = trexio_json_read_$group_num$(file, num); + break; ,*/ } - return TREXIO_FAILURE; + if (rc != TREXIO_SUCCESS) return rc; + + /* Handle index type */ + if ($is_index$) { + ,*num += ($group_num_dtype_double$) 1; + } + return rc; } #+end_src @@ -2161,20 +2178,26 @@ trexio_write_$group_num$_64 (trexio_t* const file, const $group_num_dtype_double //if (num <= 0L) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */ if (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_ATTR_ALREADY_EXISTS; + /* Handle index type */ + $group_num_dtype_double$ num_write = num; + if ($is_index$) { + num_write -= ($group_num_dtype_double$) 1; + } + switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_write_$group_num$(file, num); + return trexio_text_write_$group_num$(file, num_write); case TREXIO_HDF5: #ifdef HAVE_HDF5 - return trexio_hdf5_write_$group_num$(file, num); + return trexio_hdf5_write_$group_num$(file, num_write); #else return TREXIO_BACK_END_MISSING; #endif /* case TREXIO_JSON: - return trexio_json_write_$group_num$(file, num); + return trexio_json_write_$group_num$(file, num_write); ,*/ } @@ -2219,6 +2242,12 @@ trexio_read_$group_num$_32 (trexio_t* const file, $group_num_dtype_single$* cons if (rc != TREXIO_SUCCESS) return rc; ,*num = ($group_num_dtype_single$) num_64; + + /* Handle index type */ + if ($is_index$) { + ,*num += ($group_num_dtype_single$) 1; + } + return TREXIO_SUCCESS; } #+end_src @@ -2232,20 +2261,26 @@ trexio_write_$group_num$_32 (trexio_t* const file, const $group_num_dtype_single //if (num <= 0) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */ if (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_ATTR_ALREADY_EXISTS; + /* Handle index type */ + $group_num_dtype_single$ num_write = num; + if ($is_index$) { + num_write -= ($group_num_dtype_single$) 1; + } + switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_write_$group_num$(file, ($group_num_dtype_double$) num); + return trexio_text_write_$group_num$(file, ($group_num_dtype_double$) num_write); case TREXIO_HDF5: #ifdef HAVE_HDF5 - return trexio_hdf5_write_$group_num$(file, ($group_num_dtype_double$) num); + return trexio_hdf5_write_$group_num$(file, ($group_num_dtype_double$) num_write); #else return TREXIO_BACK_END_MISSING; #endif /* case TREXIO_JSON: - return trexio_json_write_$group_num$(file, ($group_num_dtype_double$) num); + return trexio_json_write_$group_num$(file, ($group_num_dtype_double$) num_write); break; ,*/ } diff --git a/tests/io_dset_int_hdf5.c b/tests/io_dset_int_hdf5.c index 42db22b..d307cba 100644 --- a/tests/io_dset_int_hdf5.c +++ b/tests/io_dset_int_hdf5.c @@ -17,6 +17,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { // parameters to be written int num = 12; int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + int state_id = 2; /*================= START OF TEST ==================*/ @@ -32,6 +33,10 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { rc = trexio_write_basis_nucleus_index(file, nucl_index); assert (rc == TREXIO_SUCCESS); + // write index attribute in a file + rc = trexio_write_state_id(file, state_id); + assert (rc == TREXIO_SUCCESS); + // close current session rc = trexio_close(file); assert (rc == TREXIO_SUCCESS); @@ -89,8 +94,9 @@ static int test_read_dset (const char* file_name, const back_end_t backend) { trexio_exit_code rc; // parameters to be read - int num; - int* nucl_index; + int num = 0; + int* nucl_index = NULL; + int state_id = 0; /*================= START OF TEST ==================*/ @@ -103,6 +109,11 @@ static int test_read_dset (const char* file_name, const back_end_t backend) { assert (rc == TREXIO_SUCCESS); assert (num == 12); + // read index attribute from the file + rc = trexio_read_state_id(file, &state_id); + assert (rc == TREXIO_SUCCESS); + assert (state_id == 2); + // read numerical dataset from the file nucl_index = (int*) calloc(num, sizeof(int)); rc = trexio_read_basis_nucleus_index(file, nucl_index); diff --git a/tests/io_dset_int_text.c b/tests/io_dset_int_text.c index c1f5a1e..09c536b 100644 --- a/tests/io_dset_int_text.c +++ b/tests/io_dset_int_text.c @@ -17,6 +17,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { // parameters to be written int num = 12; int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + int state_id = 2; /*================= START OF TEST ==================*/ @@ -32,6 +33,10 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { rc = trexio_write_basis_nucleus_index(file, nucl_index); assert (rc == TREXIO_SUCCESS); + // write index attribute in a file + rc = trexio_write_state_id(file, state_id); + assert (rc == TREXIO_SUCCESS); + // close current session rc = trexio_close(file); assert (rc == TREXIO_SUCCESS); @@ -89,8 +94,9 @@ static int test_read_dset (const char* file_name, const back_end_t backend) { trexio_exit_code rc; // parameters to be read - int num; - int* nucl_index; + int num = 0; + int* nucl_index = NULL; + int state_id = 0; /*================= START OF TEST ==================*/ @@ -103,6 +109,11 @@ static int test_read_dset (const char* file_name, const back_end_t backend) { assert (rc == TREXIO_SUCCESS); assert (num == 12); + // read index attribute from the file + rc = trexio_read_state_id(file, &state_id); + assert (rc == TREXIO_SUCCESS); + assert (state_id == 2); + // read numerical dataset from the file nucl_index = (int*) calloc(num, sizeof(int)); rc = trexio_read_basis_nucleus_index(file, nucl_index); diff --git a/tests/test_f.f90 b/tests/test_f.f90 index c4fff33..523558c 100644 --- a/tests/test_f.f90 +++ b/tests/test_f.f90 @@ -85,6 +85,7 @@ subroutine test_write(file_name, back_end) integer :: i, j, n_buffers = 5 integer(8) :: buf_size_sparse, buf_size_det, offset + integer :: state_id buf_size_sparse = 100/n_buffers buf_size_det = 50/n_buffers @@ -107,6 +108,7 @@ subroutine test_write(file_name, back_end) ! parameters to be written nucleus_num = 12 + state_id = 2 charge = (/ 6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /) coord = reshape( (/ 0.00000000d0, 1.39250319d0 , 0.00000000d0 , & -1.20594314d0, 0.69625160d0 , 0.00000000d0 , & @@ -182,6 +184,9 @@ subroutine test_write(file_name, back_end) rc = trexio_write_basis_nucleus_index(trex_file, basis_nucleus_index) call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX') + rc = trexio_write_state_id(trex_file, state_id) + call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX TYPE') + ! write ao_num which will be used to determine the optimal size of int indices if (trexio_has_ao_num(trex_file) == TREXIO_HAS_NOT) then rc = trexio_write_ao_num(trex_file, ao_num) @@ -302,6 +307,7 @@ subroutine test_read(file_name, back_end) integer*8 :: offset_det_data_read = 5 integer*8 :: determinant_num integer :: int_num + integer :: state_id ! orbital lists integer*4 :: orb_list_up(150) @@ -312,6 +318,7 @@ subroutine test_read(file_name, back_end) num = 12 basis_shell_num = 24 + state_id = 0 index_sparse_ao_2e_int_eri = 0 value_sparse_ao_2e_int_eri = 0.0d0 @@ -379,6 +386,15 @@ subroutine test_read(file_name, back_end) call exit(-1) endif + rc = trexio_read_state_id(trex_file, state_id) + call trexio_assert(rc, TREXIO_SUCCESS) + if (state_id == 2) then + write(*,*) 'SUCCESS READ INDEX TYPE' + else + print *, 'FAILURE INDEX TYPE CHECK' + call exit(-1) + endif + rc = trexio_read_nucleus_point_group(trex_file, sym_str, 10) call trexio_assert(rc, TREXIO_SUCCESS) diff --git a/tools/generator_tools.py b/tools/generator_tools.py index 2cde76f..f8e25db 100644 --- a/tools/generator_tools.py +++ b/tools/generator_tools.py @@ -611,8 +611,13 @@ def get_detailed_num_dict (configuration: dict) -> dict: tmp_dict.update(get_dtype_dict(v2[0], 'num')) if v2[0] in ['int', 'dim', 'dim readonly']: tmp_dict['trex_json_int_type'] = v2[0] + tmp_dict['is_index'] = 'false' + elif v2[0] in ['index']: + tmp_dict['trex_json_int_type'] = v2[0] + tmp_dict['is_index'] = 'file->one_based' else: tmp_dict['trex_json_int_type'] = '' + tmp_dict['is_index'] = 'false' num_dict[tmp_num] = tmp_dict From cafed105a4e031dab73c3dfa5cbafcd329381559 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sat, 13 May 2023 12:01:00 +0200 Subject: [PATCH 18/20] Multiple tests for io_dset_sparse --- tests/io_dset_sparse.c | 54 +++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/tests/io_dset_sparse.c b/tests/io_dset_sparse.c index 4f0259b..2167b61 100644 --- a/tests/io_dset_sparse.c +++ b/tests/io_dset_sparse.c @@ -41,13 +41,19 @@ static int test_write_dset_sparse (const char* file_name, const back_end_t backe assert(rc == TREXIO_SUCCESS); // write dataset chunks of sparse data in the file (including FAKE statements) - uint64_t chunk_size = (uint64_t) size/N_CHUNKS+1; + uint64_t chunk_size = (uint64_t) size/N_CHUNKS; + chunk_size = chunk_size > 0 ? chunk_size : (uint64_t) size; + int n_chunks = size/chunk_size; + printf("chunk_size = %ld\n", chunk_size); + printf("n_chunks = %d\n", n_chunks); + uint64_t offset_f = 0UL; uint64_t offset_d = 0UL; if (offset != 0L) offset_f += offset; // write n_chunks times using write_sparse - for(int i=0; i size) chunk_size = size-offset_f; rc = trexio_write_mo_2e_int_eri(file, offset_f, chunk_size, &index[4*offset_d], &value[offset_d]); printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc)); assert(rc == TREXIO_SUCCESS); @@ -142,44 +148,42 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen // specify the read parameters, here: // 1 chunk of 10 elements using offset of 40 (i.e. lines No. 40--59) into elements of the array starting from 5 int64_t chunk_read = size/3; - int64_t offset_file_read = size/3; - int offset_data_read = 2L; + chunk_read = chunk_read < 2 ? 2 : chunk_read; + int64_t offset_file_read = 1; int64_t read_size_check; read_size_check = chunk_read; if (offset != 0L) offset_file_read += offset; // read one chunk using the aforementioned parameters - rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]); + rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[0], &value_read[0]); printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc)); +/* for (int i=0 ; i size_max) int64_t size_max; rc = trexio_read_mo_2e_int_eri_size(file, &size_max); assert(rc == TREXIO_SUCCESS); - offset_file_read = size_max-chunk_read+1L; - offset_data_read = 1L; + offset_file_read = size_max-chunk_read+1; int64_t eof_read_size_check = size_max - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 if (offset != 0L) offset_file_read += offset; // read one chunk that will reach EOF and return TREXIO_END code - rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]); + rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[0], &value_read[0]); + printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc)); assert(rc == TREXIO_END); - for (int i=0 ; i Date: Sat, 13 May 2023 12:28:17 +0200 Subject: [PATCH 19/20] Improved io_dset_sparse.c test --- tests/io_dset_sparse.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/io_dset_sparse.c b/tests/io_dset_sparse.c index 2167b61..298158e 100644 --- a/tests/io_dset_sparse.c +++ b/tests/io_dset_sparse.c @@ -37,8 +37,10 @@ static int test_write_dset_sparse (const char* file_name, const back_end_t backe } // write mo_num which will be used to determine the optimal size of int indices - rc = trexio_write_mo_num(file, mo_num); - assert(rc == TREXIO_SUCCESS); + if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) { + rc = trexio_write_mo_num(file, mo_num); + assert(rc == TREXIO_SUCCESS); + } // write dataset chunks of sparse data in the file (including FAKE statements) uint64_t chunk_size = (uint64_t) size/N_CHUNKS; @@ -47,13 +49,14 @@ static int test_write_dset_sparse (const char* file_name, const back_end_t backe printf("chunk_size = %ld\n", chunk_size); printf("n_chunks = %d\n", n_chunks); - uint64_t offset_f = 0UL; + uint64_t offset_f = 0UL + offset; uint64_t offset_d = 0UL; - if (offset != 0L) offset_f += offset; // write n_chunks times using write_sparse while(offset_d < size) { - if (offset_f+chunk_size > size) chunk_size = size-offset_f; + if (offset_d+chunk_size > size) chunk_size = size-offset_d; + printf("chunk_size = %ld\n", chunk_size); + if (chunk_size == 0L) break; rc = trexio_write_mo_2e_int_eri(file, offset_f, chunk_size, &index[4*offset_d], &value[offset_d]); printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc)); assert(rc == TREXIO_SUCCESS); @@ -163,9 +166,9 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen printf("%d %d | %ld %ld %ld\n", i, index_read[i], offset, offset_file_read, chunk_read); } */ - assert(rc == TREXIO_SUCCESS); + //assert(rc == TREXIO_SUCCESS); assert(chunk_read == read_size_check); - assert(index_read[0] == offset_file_read); + assert(index_read[0] == offset_file_read-offset); // now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max) @@ -175,15 +178,16 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen offset_file_read = size_max-chunk_read+1; int64_t eof_read_size_check = size_max - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 - if (offset != 0L) offset_file_read += offset; // read one chunk that will reach EOF and return TREXIO_END code rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[0], &value_read[0]); printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc)); assert(rc == TREXIO_END); printf("%d %d x\n", (int32_t) index_read[0], (int32_t) (4L*offset_file_read)); + printf("%ld %ld\n", chunk_read, eof_read_size_check); assert(chunk_read == eof_read_size_check); - assert(index_read[0] == (int32_t) offset_file_read); + printf("%d %d\n", index_read[0] , (int32_t) (offset_file_read - offset)); + assert(index_read[0] == (int32_t) offset_file_read - offset); // close current session rc = trexio_close(file); @@ -238,7 +242,7 @@ int main(){ rc = system(RM_COMMAND); assert (rc == 0); - int32_t mo_num[8] = {6,12,30,62,120,252,510,1020}; + int32_t mo_num[8] = {6,12,30,62,252,510,1020,9000}; for (int i=0 ; i<8 ; ++i) { @@ -250,12 +254,10 @@ int main(){ test_read_dset_sparse (TREXIO_FILE, TEST_BACKEND, 0); test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, size); - /* // check the second write attempt (SIZE elements written in N_CHUNKS chunks) test_write_dset_sparse (TREXIO_FILE, TEST_BACKEND, size, mo_num[i]); test_read_dset_sparse (TREXIO_FILE, TEST_BACKEND, size); - test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, size*2); - */ + test_read_dset_sparse_size(TREXIO_FILE, TEST_BACKEND, 2*size); rc = system(RM_COMMAND); assert (rc == 0); From e6b9ee62adb646e25f2883935fe2d2c0195d7fb6 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 22 May 2023 12:10:20 +0200 Subject: [PATCH 20/20] Fixing too modern fortran test --- tests/test_f.f90 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_f.f90 b/tests/test_f.f90 index 523558c..c82608e 100644 --- a/tests/test_f.f90 +++ b/tests/test_f.f90 @@ -131,7 +131,19 @@ subroutine test_write(file_name, back_end) basis_shell_num = 24 basis_nucleus_index = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 /) - label = [character(len=8) :: 'C', 'Na','C', 'C 66', 'C','C', 'H 99', 'Ru', 'H', 'H', 'H', 'H' ] + allocate(character(len=8) :: label(12)) + label(1) = 'C' + label(2) = 'Na' + label(3) = 'C' + label(4) = 'C 66' + label(5) = 'C' + label(6) = 'C' + label(7) = 'H 99' + label(8) = 'Ru' + label(9) = 'H' + label(10)= 'H' + label(11)= 'H' + label(12)= 'H' sym_str = 'B3U with some comments'