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

introduce calls to trexio_assert and trexio_strarray2str subroutines

This commit is contained in:
q-posev 2021-06-14 11:54:10 +02:00
parent 2c4555b7bb
commit 4287d76de2

View File

@ -14,7 +14,7 @@ program test_trexio
call test_write('test_write_f.h5', TREXIO_HDF5) call test_write('test_write_f.h5', TREXIO_HDF5)
print *, 'call test_read(''test_write_f.h5'', TREXIO_HDF5)' print *, 'call test_read(''test_write_f.h5'', TREXIO_HDF5)'
call test_read('test_write_f.h5', TREXIO_HDF5) call test_read('test_write_f.h5', TREXIO_HDF5)
! call system('rm -rf test_write_f.h5') call system('rm -rf test_write_f.h5')
end program test_trexio end program test_trexio
@ -34,10 +34,7 @@ subroutine test_write(file_name, back_end)
integer :: rc = 1 integer :: rc = 1
integer :: i
integer :: num integer :: num
character*(128) :: str
double precision :: charge(12) double precision :: charge(12)
double precision :: coord(3,12) double precision :: coord(3,12)
@ -64,117 +61,51 @@ subroutine test_write(file_name, back_end)
label = [character(len=8) :: 'C', 'Na','C', 'C 66', 'C','C', 'H 99', 'Ru', 'H', 'H', 'H', 'H' ] label = [character(len=8) :: 'C', 'Na','C', 'C 66', 'C','C', 'H 99', 'Ru', 'H', 'H', 'H', 'H' ]
label_str = '' call trexio_strarray2str(label, num, 4, label_str)
do i = 1,num
label_str = label_str // trim(label(i)) // TREXIO_DELIM sym_str = 'B3U with some comments' // c_null_char
enddo
label_str = label_str // c_null_char
sym_str = 'B3U with some juice' // c_null_char
! ================= START OF TEST ===================== ! ! ================= START OF TEST ===================== !
trex_file = trexio_open(file_name, 'w', back_end) trex_file = trexio_open(file_name, 'w', back_end)
rc = trexio_has_nucleus_num(trex_file) rc = trexio_has_nucleus_num(trex_file)
if (rc == TREXIO_HAS_NOT) then call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 1')
write(*,*) 'SUCCESS HAS NOT 1'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
rc = trexio_has_nucleus_charge(trex_file) rc = trexio_has_nucleus_charge(trex_file)
if (rc == TREXIO_HAS_NOT) then call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 2')
write(*,*) 'SUCCESS HAS NOT 2'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
rc = trexio_write_nucleus_num(trex_file, num) rc = trexio_write_nucleus_num(trex_file, num)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE NUM')
write(*,*) 'SUCCESS WRITE NUM'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
rc = trexio_write_nucleus_charge(trex_file, charge) rc = trexio_write_nucleus_charge(trex_file, charge)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE CHARGE')
write(*,*) 'SUCCESS WRITE CHARGE'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
rc = trexio_write_nucleus_coord(trex_file, coord) rc = trexio_write_nucleus_coord(trex_file, coord)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE COORD')
write(*,*) 'SUCCESS WRITE COORD'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
if (back_end == TREXIO_HDF5) rc = trexio_write_nucleus_label(trex_file, label_str, 8) rc = trexio_write_nucleus_label(trex_file, label_str, 5)
deallocate(label_str) deallocate(label_str)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE LABEL')
write(*,*) 'SUCCESS WRITE LABEL'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
if (back_end == TREXIO_HDF5) rc = trexio_write_nucleus_point_group(trex_file, sym_str, 32) rc = trexio_write_nucleus_point_group(trex_file, sym_str, 32)
deallocate(sym_str) deallocate(sym_str)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE POINT GROUP')
write(*,*) 'SUCCESS WRITE POINT GROUP'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
rc = trexio_has_nucleus_num(trex_file) rc = trexio_has_nucleus_num(trex_file)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 1')
write(*,*) 'SUCCESS HAS 1'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
rc = trexio_has_nucleus_coord(trex_file) rc = trexio_has_nucleus_coord(trex_file)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 2')
write(*,*) 'SUCCESS HAS 2'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
rc = trexio_close(trex_file) rc = trexio_close(trex_file)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS CLOSE')
write(*,*) 'SUCCESS CLOSE'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
! ================= END OF TEST ===================== ! ! ================= END OF TEST ===================== !
end subroutine test_write end subroutine test_write
subroutine test_read(file_name, back_end) subroutine test_read(file_name, back_end)
! ============ Test read functionality =============== ! ! ============ Test read functionality =============== !
@ -208,42 +139,39 @@ subroutine test_read(file_name, back_end)
trex_file = trexio_open(file_name, 'r', back_end) trex_file = trexio_open(file_name, 'r', back_end)
rc = trexio_read_nucleus_num(trex_file, num_read)
if (rc == TREXIO_SUCCESS .and. num_read == num) then rc = trexio_read_nucleus_num(trex_file, num_read)
call trexio_assert(rc, TREXIO_SUCCESS)
if (num_read == num) then
write(*,*) 'SUCCESS READ NUM' write(*,*) 'SUCCESS READ NUM'
else else
call trexio_string_of_error(TREXIO_READONLY,str) print *, 'FAILURE NUM CHECK'
print *, trim(str) call exit(-1)
call exit(1)
endif endif
rc = trexio_read_nucleus_charge(trex_file, charge) rc = trexio_read_nucleus_charge(trex_file, charge)
call trexio_assert(rc, TREXIO_SUCCESS)
if (rc == TREXIO_SUCCESS .and. (dabs(charge(11) - 1.d0) < 1.0D-8) ) then if (dabs(charge(11) - 1.d0) < 1.0D-8) then
write(*,*) 'SUCCESS READ CHARGE' write(*,*) 'SUCCESS READ CHARGE'
else else
call trexio_string_of_error(TREXIO_READONLY,str) print *, 'FAILURE CHARGE CHECK'
print *, trim(str)
call exit(-1) call exit(-1)
endif endif
rc = trexio_read_nucleus_coord(trex_file, coord) rc = trexio_read_nucleus_coord(trex_file, coord)
call trexio_assert(rc, TREXIO_SUCCESS)
if (rc == TREXIO_SUCCESS .and. (dabs(coord(2,1) - 1.39250319d0) < 1.0D-8) ) then if (dabs(coord(2,1) - 1.39250319d0) < 1.0D-8) then
write(*,*) 'SUCCESS READ COORD' write(*,*) 'SUCCESS READ COORD'
else else
call trexio_string_of_error(TREXIO_READONLY,str) print *, 'FAILURE COORD CHECK'
print *, trim(str)
call exit(-1) call exit(-1)
endif endif
if (back_end == TREXIO_HDF5) then
rc = trexio_read_nucleus_label(trex_file, label_str, 2) rc = trexio_read_nucleus_label(trex_file, label_str, 2)
call trexio_assert(rc, TREXIO_SUCCESS)
! write(*,*) label_str
! -------------------------------------------------- ! --------------------------------------------------
! dummy parser of big string with TREXIO_DELIM delimeters ! dummy parser of big string with TREXIO_DELIM delimeters
! -------------------------------------------------- ! --------------------------------------------------
@ -265,38 +193,26 @@ subroutine test_read(file_name, back_end)
write(*,*) label(i) write(*,*) label(i)
offset=ind offset=ind
enddo enddo
! -------------------------------------------------- ! --------------------------------------------------
if (trim(label(2)) == 'Na') then
if (rc == TREXIO_SUCCESS .and. (trim(label(2)) == 'Na') ) then
write(*,*) 'SUCCESS READ LABEL' write(*,*) 'SUCCESS READ LABEL'
else else
call trexio_string_of_error(TREXIO_READONLY,str) print *, 'FAILURE LABEL CHECK'
print *, trim(str)
call exit(-1) call exit(-1)
endif endif
rc = trexio_read_nucleus_point_group(trex_file, sym_str, 32) rc = trexio_read_nucleus_point_group(trex_file, sym_str, 32)
call trexio_assert(rc, TREXIO_SUCCESS)
if (rc == TREXIO_SUCCESS .and. (sym_str(1:3) == 'B3U') ) then if (sym_str(1:3) == 'B3U') then
write(*,*) 'SUCCESS READ POINT GROUP' write(*,*) 'SUCCESS READ POINT GROUP'
else else
call trexio_string_of_error(TREXIO_READONLY,str) print *, 'FAILURE POINT GROUP CHECK'
print *, trim(str)
call exit(-1) call exit(-1)
endif endif
endif
rc = trexio_close(trex_file) rc = trexio_close(trex_file)
if (rc == TREXIO_SUCCESS) then call trexio_assert(rc, TREXIO_SUCCESS)
write(*,*) 'SUCCESS CLOSE'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
! ================= END OF TEST ===================== ! ! ================= END OF TEST ===================== !