mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-22 12:23:54 +01:00
add tests for string attributes
This commit is contained in:
parent
3082dbbaf3
commit
02d2561d73
16
tests/test.c
16
tests/test.c
@ -70,6 +70,7 @@ int test_h5write() {
|
||||
strcat(labelxxx,TREXIO_DELIM);
|
||||
}
|
||||
|
||||
const char* sym = "B3U";
|
||||
/*================= START OF TEST ==================*/
|
||||
|
||||
// open file in 'write' mode
|
||||
@ -93,6 +94,8 @@ int test_h5write() {
|
||||
rc = trexio_write_nucleus_label(file,labelxxx, 4);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
rc = trexio_write_nucleus_symmetry(file, sym);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
// check if the written data exists in the file
|
||||
rc = trexio_has_nucleus_num(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
@ -100,6 +103,8 @@ int test_h5write() {
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
rc = trexio_has_nucleus_label(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
rc = trexio_has_nucleus_symmetry(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
// should not work: try to overwrite the nucleus_num
|
||||
rc = trexio_write_nucleus_num(file,25);
|
||||
@ -144,6 +149,7 @@ int test_h5read() {
|
||||
double* coord;
|
||||
char** label;
|
||||
char* labelxxx;
|
||||
char* symmetry;
|
||||
|
||||
/*================= START OF TEST ==================*/
|
||||
|
||||
@ -171,7 +177,7 @@ int test_h5read() {
|
||||
label[i] = (char*) malloc(max_str_len*sizeof(char));
|
||||
}
|
||||
|
||||
labelxxx = (char*) malloc(num*4*sizeof(char*));
|
||||
labelxxx = (char*) malloc(num*4*sizeof(char));
|
||||
|
||||
rc = trexio_read_nucleus_label(file,labelxxx, 4);
|
||||
//rc = trexio_read_nucleus_label(file,label);
|
||||
@ -185,6 +191,14 @@ int test_h5read() {
|
||||
pch = strtok(NULL, TREXIO_DELIM);
|
||||
assert( strcmp(pch, "Na") == 0 );
|
||||
|
||||
symmetry = (char*) malloc(32*sizeof(char));
|
||||
|
||||
rc = trexio_read_nucleus_symmetry(file, symmetry);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
assert( strcmp(symmetry, "B3U") == 0 );
|
||||
free(symmetry);
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
@ -23,6 +23,7 @@ subroutine test_write()
|
||||
double precision :: coord(3,12)
|
||||
|
||||
character(len=:), allocatable :: label_str
|
||||
character(len=:), allocatable :: sym_str
|
||||
character(len=4):: label(12)
|
||||
|
||||
! parameters to be written
|
||||
@ -44,12 +45,12 @@ subroutine test_write()
|
||||
|
||||
label = [character(len=4) :: 'C', 'Na','C', 'C', 'C','C', 'H', 'H', 'H', 'Ru', 'H', 'H' ]
|
||||
|
||||
label_str=''
|
||||
label_str = ''
|
||||
do i = 1,num
|
||||
label_str=label_str//trim(label(i))//TREXIO_DELIM
|
||||
label_str = label_str // trim(label(i)) // TREXIO_DELIM
|
||||
enddo
|
||||
|
||||
|
||||
sym_str = 'B3U with some juice' // c_null_char
|
||||
! ================= START OF TEST ===================== !
|
||||
|
||||
! trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT)
|
||||
@ -73,6 +74,10 @@ subroutine test_write()
|
||||
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE LABEL'
|
||||
deallocate(label_str)
|
||||
|
||||
rc = trexio_write_nucleus_symmetry(trex_file, sym_str)
|
||||
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE SYMMETRY'
|
||||
deallocate(sym_str)
|
||||
|
||||
rc = trexio_has_nucleus_num(trex_file)
|
||||
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS HAS 1'
|
||||
rc = trexio_has_nucleus_coord(trex_file)
|
||||
@ -117,10 +122,13 @@ subroutine test_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(len=32) :: sym_str
|
||||
|
||||
character*(128) :: str
|
||||
|
||||
num = 12
|
||||
@ -167,7 +175,11 @@ subroutine test_read()
|
||||
write(*,*) label
|
||||
! --------------------------------------------------
|
||||
|
||||
if (rc == TREXIO_SUCCESS .and. (trim(label(2)) == 'Na' )) write(*,*) 'SUCCESS READ LABEL'
|
||||
if (rc == TREXIO_SUCCESS .and. (trim(label(2)) == 'Na') ) write(*,*) 'SUCCESS READ LABEL'
|
||||
|
||||
rc = trexio_read_nucleus_symmetry(trex_file, sym_str)
|
||||
write(*,*) sym_str
|
||||
if (rc == TREXIO_SUCCESS .and. (trim(sym_str) == 'B3U') ) write(*,*) 'SUCCESS READ SYMMETRY'
|
||||
|
||||
rc = trexio_close(trex_file)
|
||||
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE'
|
||||
|
Loading…
Reference in New Issue
Block a user