1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-03-04 06:10:23 +01:00

Fixed bug for arrays of strings in text backend

This commit is contained in:
Anthony Scemama 2024-12-05 13:10:00 +01:00
parent e5a30615a6
commit 66bb1e9c21
8 changed files with 34 additions and 29 deletions

View File

@ -982,7 +982,7 @@ trexio_text_write_$group_dset$ (trexio_t* const file, const char** dset, const u
if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
for (uint64_t i=0 ; i<dims[0] ; ++i) {
size_t tmp_len = strlen(dset[i]);
size_t tmp_len = strlen(dset[i])+1;
$group$->$group_dset$[i] = tmp_str;
strncpy(tmp_str, dset[i], tmp_len);
tmp_str[tmp_len-1] = '\0';

View File

@ -52,7 +52,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
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};
@ -250,11 +249,11 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
assert(check_diff*check_diff < 1e-14);
// check the value of determinant_num
int32_t det_num = 0;
int32_t size_check = SIZE;
int64_t det_num = 0;
int64_t size_check = SIZE;
if (offset != 0L) size_check += offset;
rc = trexio_read_determinant_num(file, &det_num);
rc = trexio_read_determinant_num_64(file, &det_num);
assert(rc == TREXIO_SUCCESS);
assert(det_num == size_check);

View File

@ -23,12 +23,12 @@ 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;
uint64_t size = mo_num/2;
index = calloc(4L*size, sizeof(int32_t));
value = calloc(size, sizeof(double));
for(int i=0; i<size; i++){
for(int i=0; (uint64_t) i<size; i++){
index[4*i] = i;
index[4*i+1] = i+1;
index[4*i+2] = i+2;
@ -38,16 +38,16 @@ 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
if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) {
rc = trexio_write_mo_num(file, mo_num);
rc = trexio_write_mo_num_64(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;
chunk_size = chunk_size > 0 ? chunk_size : (uint64_t) size;
int n_chunks = size/chunk_size;
uint64_t n_chunks = size/chunk_size;
printf("chunk_size = %ld\n", (long) chunk_size);
printf("n_chunks = %d\n", n_chunks);
printf("n_chunks = %ld\n", (long) n_chunks);
uint64_t offset_f = 0UL + offset;
uint64_t offset_d = 0UL;

View File

@ -63,9 +63,13 @@ static int test_has_dset_str (const char* file_name, const back_end_t backend) {
// open file
file = trexio_open(file_name, 'r', backend, &rc);
assert (file != NULL);
assert (rc == TREXIO_SUCCESS);
// check that the previously written dataset of strings exists
rc = trexio_has_nucleus_label(file);
if (rc != TREXIO_SUCCESS) {
printf("%s\n", trexio_string_of_error(rc));
}
assert (rc == TREXIO_SUCCESS);
// check that the dataset of strings does not exist

View File

@ -1,5 +1,6 @@
#include "trexio.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -119,25 +120,25 @@ static int test_read_jastrow (const char* file_name, const back_end_t backend) {
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);
assert (fabs(ee[0]-0.5) < 1.e-15);
assert (fabs(ee[1]-2.0) < 1.e-15);
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);
assert (fabs(en[0]-1.0) < 1.e-15);
assert (fabs(en[1]-2.0) < 1.e-15);
assert (fabs(en[2]-3.0) < 1.e-15);
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);
assert (fabs(een[0]-11.0) < 1.e-15);
assert (fabs(een[1]-12.0) < 1.e-15);
assert (fabs(een[2]-13.0) < 1.e-15);
assert (fabs(een[3]-14.0) < 1.e-15);
assert (fabs(een[4]-15.0) < 1.e-15);
assert (fabs(een[5]-16.0) < 1.e-15);
int en_nucleus [3] = { 0, 0, 0 };
rc = trexio_read_jastrow_en_nucleus(file, en_nucleus);
@ -159,14 +160,14 @@ static int test_read_jastrow (const char* file_name, const back_end_t backend) {
double ee_scaling = 0.0;
rc = trexio_read_jastrow_ee_scaling(file, &ee_scaling);
assert (rc == TREXIO_SUCCESS);
assert (ee_scaling == 1.0);
assert (fabs(ee_scaling-1.0) < 1.e-15);
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);
assert (fabs(en_scaling[0]-0.5) < 1.e-15);
assert (fabs(en_scaling[1]-1.0) < 1.e-15);
assert (fabs(en_scaling[2]-0.5) < 1.e-15);
rc = trexio_close(file);
/*================= END OF TEST ==================*/

View File

@ -117,7 +117,7 @@ static int test_open_errors (const back_end_t backend) {
}
static int test_inquire (const back_end_t backend) {
static int test_inquire () {
/* Try to call trexio_inquire function */
@ -151,7 +151,7 @@ int main(void) {
test_open_r (TREXIO_FILE, TEST_BACKEND);
test_open_auto (TREXIO_FILE);
test_open_errors(TEST_BACKEND);
test_inquire (TEST_BACKEND);
test_inquire ();
rc = system(RM_COMMAND);
assert (rc == 0);

View File

@ -170,7 +170,7 @@ static int test_overwrite_safe (const char* file_name, const back_end_t backend)
}
int test_read(const char* file_name, const back_end_t backend) {
static int test_read(const char* file_name, const back_end_t backend) {
/*========= Test read ===========*/

View File

@ -327,7 +327,8 @@ subroutine test_read(file_name, back_end)
integer(trexio_t) :: trex_file
integer :: i, j, k, ind, offset, flag
integer*8 :: i
integer :: j, k, ind, offset, flag
integer(trexio_exit_code) :: rc = 1
integer :: num, num_read, basis_shell_num