1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-10-02 14:31:05 +02:00

[WIP] working tests with string converters

This commit is contained in:
q-posev 2021-06-01 14:59:08 +02:00
parent 6979c84c38
commit 13fe1e8690
2 changed files with 69 additions and 8 deletions

View File

@ -62,6 +62,8 @@ int test_h5write() {
"H" ,
"H" ,
"H" };
char labelxxx[] = "C C C Na C C H H H Ru H H";
/*================= START OF TEST ==================*/
@ -82,7 +84,8 @@ int test_h5write() {
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_nucleus_charge(file,charge);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_nucleus_label(file,label);
//rc = trexio_write_nucleus_label(file,label);
rc = trexio_write_nucleus_label(file,labelxxx);
assert (rc == TREXIO_SUCCESS);
// check if the written data exists in the file
@ -135,6 +138,7 @@ int test_h5read() {
int num;
double* coord;
char** label;
char* labelxxx;
/*================= START OF TEST ==================*/
@ -162,10 +166,17 @@ int test_h5read() {
label[i] = (char*) malloc(max_str_len*sizeof(char));
}
rc = trexio_read_nucleus_label(file,label);
labelxxx = (char*) malloc(num*4*sizeof(char*));
rc = trexio_read_nucleus_label(file,labelxxx);
//rc = trexio_read_nucleus_label(file,label);
assert (rc == TREXIO_SUCCESS);
assert( strcmp(label[1], "Na") == 0 );
printf("%s\n", labelxxx);
//assert( strcmp(label[1], "Na") == 0 );
char * pch;
pch = strtok(labelxxx, " ");
assert( strcmp(pch, "C") == 0 );
// close current session
rc = trexio_close(file);
@ -193,6 +204,8 @@ int test_h5read() {
}
free(label);
free(labelxxx);
return 0;
}

View File

@ -10,16 +10,21 @@ subroutine test_write()
! ============ Test write functionality =============== !
use trexio
use, intrinsic :: iso_c_binding
implicit none
integer(8) :: trex_file
integer :: rc = 1
integer :: num
integer :: i, num
double precision :: charge(12)
double precision :: coord(3,12)
character(len=:), allocatable :: label_str
character(len=4):: label(12)
! parameters to be written
num = 12
charge = (/ 6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /)
@ -37,10 +42,18 @@ subroutine test_write()
0.00000000d0, 2.47304151d0 , 0.00000000d0 /), &
shape(coord) )
label = [character(len=4) :: 'C', 'Na','C', 'C', 'C','C', 'H', 'H', 'H', 'Ru', 'H', 'H' ]
label_str=''
do i = 1,num
label_str=label_str//trim(label(i))//' '
enddo
! ================= START OF TEST ===================== !
trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT)
! trex_file = trexio_open('test_hdf5_fort.h5', 'w', TREXIO_HDF5)
! trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT)
trex_file = trexio_open('test_hdf5_fort.h5', 'w', TREXIO_HDF5)
rc = trexio_has_nucleus_num(trex_file)
if (rc == TREXIO_HAS_NOT) write(*,*) 'SUCCESS HAS NOT 1'
@ -56,6 +69,10 @@ subroutine test_write()
rc = trexio_write_nucleus_coord(trex_file, coord)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE COORD'
rc = trexio_write_nucleus_label(trex_file, label_str)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE LABEL'
deallocate(label_str)
rc = trexio_has_nucleus_num(trex_file)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS HAS 1'
rc = trexio_has_nucleus_coord(trex_file)
@ -94,11 +111,15 @@ subroutine test_read()
integer(8) :: trex_file
integer :: i, j, k, ind, offset, flag
integer :: rc = 1
integer :: num, num_read
double precision :: charge(12)
double precision :: coord(3,12)
character :: label_str(128)
character(len=4) :: tmp_str
character(len=4) :: label(12)
character*(128) :: str
@ -106,8 +127,8 @@ subroutine test_read()
! ================= START OF TEST ===================== !
trex_file = trexio_open('trexio_test_fort', 'r', TREXIO_TEXT)
! trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5)
! trex_file = trexio_open('trexio_test_fort', 'r', TREXIO_TEXT)
trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5)
rc = trexio_read_nucleus_num(trex_file, num_read)
@ -121,6 +142,33 @@ subroutine test_read()
if (rc == TREXIO_SUCCESS .and. (abs(coord(2,1) - 1.39250319d0) < 1.0D-8) ) write(*,*) 'SUCCESS READ COORD'
rc = trexio_read_nucleus_label(trex_file, label_str)
! --------------------------------------------------
! dummy parser of big string with space delimeters
! --------------------------------------------------
ind=1
offset=1
do i=1,num
k = 1
tmp_str=''
do j=ind,128
if ( (label_str(j)==" ") ) then
ind=j+1
exit
endif
tmp_str(k:k) = label_str(j)
k = k + 1
enddo
label(i)=tmp_str
offset=ind
enddo
write(*,*) label
! --------------------------------------------------
if (rc == TREXIO_SUCCESS .and. (trim(label(2)) == 'Na' )) write(*,*) 'SUCCESS READ LABEL'
rc = trexio_close(trex_file)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE'