2021-06-17 17:20:01 +02:00
|
|
|
#include "trexio.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2021-06-18 12:53:00 +02:00
|
|
|
#define TEST_BACKEND TREXIO_HDF5
|
2021-06-22 17:57:34 +02:00
|
|
|
#define TREXIO_FILE "test_num.h5"
|
2021-06-18 12:53:00 +02:00
|
|
|
#define RM_COMMAND "rm -rf " TREXIO_FILE
|
|
|
|
|
2021-06-17 17:20:01 +02:00
|
|
|
static int test_write_num (const char* file_name, const back_end_t backend) {
|
|
|
|
|
2021-06-18 12:53:00 +02:00
|
|
|
/* Try to write a dimensioning attribute (num variable) into the TREXIO file */
|
2021-06-17 17:20:01 +02:00
|
|
|
|
|
|
|
trexio_t* file = NULL;
|
|
|
|
trexio_exit_code rc;
|
|
|
|
|
|
|
|
// parameters to be written
|
|
|
|
int num = 12;
|
|
|
|
|
|
|
|
/*================= START OF TEST ==================*/
|
|
|
|
|
|
|
|
// open file in 'write' mode
|
2021-09-22 14:50:22 +02:00
|
|
|
file = trexio_open(file_name, 'w', backend, &rc);
|
2021-06-17 17:20:01 +02:00
|
|
|
assert (file != NULL);
|
|
|
|
|
|
|
|
// write numerical attribute in an empty file
|
2021-06-18 12:53:00 +02:00
|
|
|
rc = trexio_write_nucleus_num(file, num);
|
2021-06-17 17:20:01 +02:00
|
|
|
assert (rc == TREXIO_SUCCESS);
|
|
|
|
|
2021-12-09 16:23:22 +01:00
|
|
|
rc = trexio_write_nucleus_repulsion(file, 2.14171677);
|
|
|
|
assert (rc == TREXIO_SUCCESS);
|
|
|
|
|
2021-09-21 15:41:12 +02:00
|
|
|
// 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);
|
2021-09-22 11:41:29 +02:00
|
|
|
assert (rc == TREXIO_INVALID_NUM);
|
2021-09-21 15:41:12 +02:00
|
|
|
|
|
|
|
// write numerical attribute ao_cartesian as 0
|
|
|
|
rc = trexio_write_ao_cartesian(file, 0);
|
|
|
|
assert (rc == TREXIO_SUCCESS);
|
|
|
|
|
2021-06-18 12:53:00 +02:00
|
|
|
// 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 ==================*/
|
|
|
|
|
2021-06-21 12:51:21 +02:00
|
|
|
// open file
|
2021-09-22 14:50:22 +02:00
|
|
|
file = trexio_open(file_name, 'r', backend, &rc);
|
2021-06-18 12:53:00 +02:00
|
|
|
assert (file != NULL);
|
|
|
|
|
|
|
|
// check that the previously written num variable exists
|
|
|
|
rc = trexio_has_nucleus_num(file);
|
|
|
|
assert (rc == TREXIO_SUCCESS);
|
|
|
|
|
2021-12-09 16:23:22 +01:00
|
|
|
rc = trexio_has_nucleus_repulsion(file);
|
|
|
|
assert (rc == TREXIO_SUCCESS);
|
|
|
|
|
2021-06-18 12:53:00 +02:00
|
|
|
// check that the num variable does not exist
|
|
|
|
rc = trexio_has_mo_num(file);
|
|
|
|
assert (rc == TREXIO_HAS_NOT);
|
2021-06-17 17:20:01 +02:00
|
|
|
|
|
|
|
// close current session
|
|
|
|
rc = trexio_close(file);
|
|
|
|
assert (rc == TREXIO_SUCCESS);
|
|
|
|
|
|
|
|
/*================= END OF TEST ==================*/
|
|
|
|
|
|
|
|
return 0;
|
2021-06-18 12:53:00 +02:00
|
|
|
}
|
2021-06-17 17:20:01 +02:00
|
|
|
|
2021-06-18 12:53:00 +02:00
|
|
|
|
|
|
|
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;
|
2021-09-21 15:41:12 +02:00
|
|
|
int cartesian;
|
2021-12-09 16:23:22 +01:00
|
|
|
float repulsion_32;
|
|
|
|
double repulsion_64, d;
|
2021-06-18 12:53:00 +02:00
|
|
|
|
|
|
|
/*================= START OF TEST ==================*/
|
|
|
|
|
2021-06-21 12:51:21 +02:00
|
|
|
// open file in 'read' mode
|
2021-09-22 14:50:22 +02:00
|
|
|
file = trexio_open(file_name, 'r', backend, &rc);
|
2021-06-18 12:53:00 +02:00
|
|
|
assert (file != NULL);
|
|
|
|
|
|
|
|
// read numerical attribute from the file
|
|
|
|
rc = trexio_read_nucleus_num(file, &num);
|
|
|
|
assert (rc == TREXIO_SUCCESS);
|
2021-06-21 09:28:37 +02:00
|
|
|
assert (num == 12);
|
2021-06-18 12:53:00 +02:00
|
|
|
|
2021-12-09 16:23:22 +01:00
|
|
|
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 );
|
|
|
|
|
2021-09-21 15:41:12 +02:00
|
|
|
// 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);
|
|
|
|
|
2021-06-18 12:53:00 +02:00
|
|
|
// close current session
|
|
|
|
rc = trexio_close(file);
|
|
|
|
assert (rc == TREXIO_SUCCESS);
|
|
|
|
|
|
|
|
/*================= END OF TEST ==================*/
|
|
|
|
|
|
|
|
return 0;
|
2021-06-17 17:20:01 +02:00
|
|
|
}
|
|
|
|
|
2021-06-18 12:53:00 +02:00
|
|
|
|
2021-06-17 17:20:01 +02:00
|
|
|
int main(void) {
|
|
|
|
|
|
|
|
/*============== Test launcher ================*/
|
|
|
|
|
|
|
|
int rc;
|
2021-06-18 12:53:00 +02:00
|
|
|
rc = system(RM_COMMAND);
|
2021-06-17 17:20:01 +02:00
|
|
|
assert (rc == 0);
|
2021-06-18 12:53:00 +02:00
|
|
|
|
|
|
|
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);
|
2021-06-17 17:20:01 +02:00
|
|
|
assert (rc == 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|