2021-03-22 16:40:45 +01:00
|
|
|
program test_trexio
|
2021-06-04 18:14:45 +02:00
|
|
|
use trexio
|
|
|
|
implicit none
|
2021-03-22 16:40:45 +01:00
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
call system('rm -rf trexio_test_fort')
|
|
|
|
print *, 'call test_write(''trexio_test_fort'', TREXIO_TEXT)'
|
|
|
|
call test_write('trexio_test_fort', TREXIO_TEXT)
|
|
|
|
print *, 'call test_read(''trexio_test_fort'', TREXIO_TEXT)'
|
|
|
|
call test_read('trexio_test_fort', TREXIO_TEXT)
|
|
|
|
call system('rm -rf trexio_test_fort')
|
|
|
|
|
|
|
|
call system('rm -rf trexio_test_fort')
|
|
|
|
print *, 'call test_write(''trexio_test_fort.h5'', TREXIO_HDF5)'
|
|
|
|
call test_write('trexio_test_fort.h5', TREXIO_HDF5)
|
|
|
|
print *, 'call test_read(''trexio_test_fort.h5'', TREXIO_HDF5)'
|
|
|
|
call test_read('trexio_test_fort.h5', TREXIO_HDF5)
|
|
|
|
call system('rm -rf trexio_test_fort.h5')
|
2021-03-24 11:14:47 +01:00
|
|
|
|
|
|
|
end program test_trexio
|
2021-03-22 16:40:45 +01:00
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
subroutine test_write(file_name, back_end)
|
2021-03-30 14:20:46 +02:00
|
|
|
|
|
|
|
! ============ Test write functionality =============== !
|
2021-04-01 22:48:04 +02:00
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
use trexio
|
2021-06-03 13:42:56 +02:00
|
|
|
use, intrinsic :: iso_c_binding
|
2021-06-01 14:59:08 +02:00
|
|
|
|
2021-03-22 16:40:45 +01:00
|
|
|
implicit none
|
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
character*(*), intent(in) :: file_name
|
2021-06-07 11:17:02 +02:00
|
|
|
integer, intent(in) :: back_end
|
2021-06-04 18:14:45 +02:00
|
|
|
|
2021-03-24 16:06:04 +01:00
|
|
|
integer(8) :: trex_file
|
2021-03-22 16:40:45 +01:00
|
|
|
|
2021-03-24 17:22:58 +01:00
|
|
|
integer :: rc = 1
|
2021-06-07 11:01:37 +02:00
|
|
|
|
|
|
|
integer :: i
|
2021-04-07 17:37:04 +02:00
|
|
|
integer :: num
|
2021-06-04 18:14:45 +02:00
|
|
|
character*(128) :: str
|
2021-03-23 16:34:13 +01:00
|
|
|
|
2021-03-24 16:06:04 +01:00
|
|
|
double precision :: charge(12)
|
2021-04-20 01:34:11 +02:00
|
|
|
double precision :: coord(3,12)
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-06-01 14:59:08 +02:00
|
|
|
character(len=:), allocatable :: label_str
|
2021-06-04 15:36:56 +02:00
|
|
|
character(len=:), allocatable :: sym_str
|
2021-06-01 14:59:08 +02:00
|
|
|
character(len=4):: label(12)
|
|
|
|
|
2021-03-30 14:20:46 +02:00
|
|
|
! parameters to be written
|
2021-03-23 18:12:53 +01:00
|
|
|
num = 12
|
2021-04-20 01:34:11 +02:00
|
|
|
charge = (/ 6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /)
|
|
|
|
coord = reshape( (/ 0.00000000d0, 1.39250319d0 , 0.00000000d0 , &
|
|
|
|
-1.20594314d0, 0.69625160d0 , 0.00000000d0 , &
|
|
|
|
-1.20594314d0, -0.69625160d0 , 0.00000000d0 , &
|
|
|
|
0.00000000d0, -1.39250319d0 , 0.00000000d0 , &
|
|
|
|
1.20594314d0, -0.69625160d0 , 0.00000000d0 , &
|
|
|
|
1.20594314d0, 0.69625160d0 , 0.00000000d0 , &
|
|
|
|
-2.14171677d0, 1.23652075d0 , 0.00000000d0 , &
|
|
|
|
-2.14171677d0, -1.23652075d0 , 0.00000000d0 , &
|
|
|
|
0.00000000d0, -2.47304151d0 , 0.00000000d0 , &
|
|
|
|
2.14171677d0, -1.23652075d0 , 0.00000000d0 , &
|
|
|
|
2.14171677d0, 1.23652075d0 , 0.00000000d0 , &
|
|
|
|
0.00000000d0, 2.47304151d0 , 0.00000000d0 /), &
|
|
|
|
shape(coord) )
|
2021-03-30 14:20:46 +02:00
|
|
|
|
2021-06-01 14:59:08 +02:00
|
|
|
label = [character(len=4) :: 'C', 'Na','C', 'C', 'C','C', 'H', 'H', 'H', 'Ru', 'H', 'H' ]
|
|
|
|
|
2021-06-04 15:36:56 +02:00
|
|
|
label_str = ''
|
2021-06-01 14:59:08 +02:00
|
|
|
do i = 1,num
|
2021-06-04 15:36:56 +02:00
|
|
|
label_str = label_str // trim(label(i)) // TREXIO_DELIM
|
2021-06-01 14:59:08 +02:00
|
|
|
enddo
|
|
|
|
|
2021-06-04 15:36:56 +02:00
|
|
|
sym_str = 'B3U with some juice' // c_null_char
|
2021-03-30 14:20:46 +02:00
|
|
|
! ================= START OF TEST ===================== !
|
2021-03-23 18:12:53 +01:00
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
trex_file = trexio_open(file_name, 'w', back_end)
|
2021-03-30 11:56:04 +02:00
|
|
|
|
|
|
|
rc = trexio_has_nucleus_num(trex_file)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_HAS_NOT) then
|
|
|
|
write(*,*) 'SUCCESS HAS NOT 1'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
|
|
|
|
2021-03-30 11:56:04 +02:00
|
|
|
rc = trexio_has_nucleus_charge(trex_file)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_HAS_NOT) then
|
|
|
|
write(*,*) 'SUCCESS HAS NOT 2'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
|
|
|
|
2021-03-22 16:40:45 +01:00
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
rc = trexio_write_nucleus_num(trex_file, num)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS WRITE NUM'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
2021-04-01 22:48:04 +02:00
|
|
|
|
2021-03-24 16:06:04 +01:00
|
|
|
rc = trexio_write_nucleus_charge(trex_file, charge)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS WRITE CHARGE'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
2021-03-23 16:34:13 +01:00
|
|
|
|
2021-03-24 16:06:04 +01:00
|
|
|
rc = trexio_write_nucleus_coord(trex_file, coord)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS WRITE COORD'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
2021-03-23 16:34:13 +01:00
|
|
|
|
2021-06-07 11:17:02 +02:00
|
|
|
if (back_end == TREXIO_HDF5) rc = trexio_write_nucleus_label(trex_file, label_str, 4)
|
2021-06-01 14:59:08 +02:00
|
|
|
deallocate(label_str)
|
2021-06-07 11:01:37 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS WRITE LABEL'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
2021-06-01 14:59:08 +02:00
|
|
|
|
2021-06-07 11:17:02 +02:00
|
|
|
if (back_end == TREXIO_HDF5) rc = trexio_write_nucleus_point_group(trex_file, sym_str)
|
2021-06-04 15:36:56 +02:00
|
|
|
deallocate(sym_str)
|
2021-06-07 11:01:37 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS WRITE POINT GROUP'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
2021-06-04 15:36:56 +02:00
|
|
|
|
2021-03-30 11:56:04 +02:00
|
|
|
rc = trexio_has_nucleus_num(trex_file)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS HAS 1'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
|
|
|
|
2021-03-30 11:56:04 +02:00
|
|
|
rc = trexio_has_nucleus_coord(trex_file)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS HAS 2'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
2021-03-30 11:56:04 +02:00
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
rc = trexio_close(trex_file)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS CLOSE'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-03-30 14:20:46 +02:00
|
|
|
! ================= END OF TEST ===================== !
|
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
end subroutine test_write
|
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subroutine test_read(file_name, back_end)
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-03-30 14:20:46 +02:00
|
|
|
! ============ Test read functionality =============== !
|
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
use trexio
|
|
|
|
implicit none
|
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
character*(*), intent(in) :: file_name
|
2021-06-07 11:17:02 +02:00
|
|
|
integer, intent(in) :: back_end
|
2021-06-04 18:14:45 +02:00
|
|
|
|
2021-03-24 16:06:04 +01:00
|
|
|
integer(8) :: trex_file
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-06-01 14:59:08 +02:00
|
|
|
integer :: i, j, k, ind, offset, flag
|
2021-03-24 17:22:58 +01:00
|
|
|
integer :: rc = 1
|
2021-04-07 17:37:04 +02:00
|
|
|
integer :: num, num_read
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-04-01 22:48:04 +02:00
|
|
|
double precision :: charge(12)
|
|
|
|
double precision :: coord(3,12)
|
2021-06-04 15:36:56 +02:00
|
|
|
|
2021-06-01 14:59:08 +02:00
|
|
|
character :: label_str(128)
|
|
|
|
character(len=4) :: tmp_str
|
|
|
|
character(len=4) :: label(12)
|
2021-04-01 22:48:04 +02:00
|
|
|
|
2021-06-04 15:36:56 +02:00
|
|
|
character(len=32) :: sym_str
|
|
|
|
|
2021-04-01 22:48:04 +02:00
|
|
|
character*(128) :: str
|
2021-03-24 11:14:47 +01:00
|
|
|
|
|
|
|
num = 12
|
|
|
|
|
2021-03-30 14:20:46 +02:00
|
|
|
! ================= START OF TEST ===================== !
|
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
trex_file = trexio_open(file_name, 'r', back_end)
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-03-24 16:06:04 +01:00
|
|
|
rc = trexio_read_nucleus_num(trex_file, num_read)
|
2021-03-23 16:34:13 +01:00
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS .and. num_read == num) then
|
|
|
|
write(*,*) 'SUCCESS READ NUM'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-03-24 16:06:04 +01:00
|
|
|
rc = trexio_read_nucleus_charge(trex_file, charge)
|
2021-04-01 22:48:04 +02:00
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS .and. (dabs(charge(11) - 1.d0) < 1.0D-8) ) then
|
|
|
|
write(*,*) 'SUCCESS READ CHARGE'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(-1)
|
|
|
|
endif
|
2021-03-22 16:40:45 +01:00
|
|
|
|
2021-03-24 17:22:58 +01:00
|
|
|
rc = trexio_read_nucleus_coord(trex_file, coord)
|
2021-03-30 14:20:46 +02:00
|
|
|
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS .and. (dabs(coord(2,1) - 1.39250319d0) < 1.0D-8) ) then
|
|
|
|
write(*,*) 'SUCCESS READ COORD'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(-1)
|
|
|
|
endif
|
2021-03-24 17:22:58 +01:00
|
|
|
|
2021-06-07 11:17:02 +02:00
|
|
|
if (back_end == TREXIO_HDF5) then
|
|
|
|
|
2021-06-03 16:13:57 +02:00
|
|
|
rc = trexio_read_nucleus_label(trex_file, label_str, 4)
|
2021-06-01 14:59:08 +02:00
|
|
|
|
|
|
|
! --------------------------------------------------
|
2021-06-04 09:43:56 +02:00
|
|
|
! dummy parser of big string with TREXIO_DELIM delimeters
|
2021-06-01 14:59:08 +02:00
|
|
|
! --------------------------------------------------
|
|
|
|
ind=1
|
|
|
|
offset=1
|
|
|
|
do i=1,num
|
|
|
|
k = 1
|
|
|
|
tmp_str=''
|
|
|
|
do j=ind,128
|
|
|
|
|
2021-06-03 13:42:56 +02:00
|
|
|
if ( (label_str(j)==TREXIO_DELIM) ) then
|
2021-06-01 14:59:08 +02:00
|
|
|
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
|
|
|
|
! --------------------------------------------------
|
|
|
|
|
2021-06-07 11:01:37 +02:00
|
|
|
if (rc == TREXIO_SUCCESS .and. (trim(label(2)) == 'Na') ) then
|
|
|
|
write(*,*) 'SUCCESS READ LABEL'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(-1)
|
|
|
|
endif
|
2021-06-04 15:36:56 +02:00
|
|
|
|
2021-06-04 18:42:52 +02:00
|
|
|
rc = trexio_read_nucleus_point_group(trex_file, sym_str)
|
2021-06-07 11:17:02 +02:00
|
|
|
write(*,*) sym_str(1:3)
|
|
|
|
if (rc == TREXIO_SUCCESS .and. (sym_str(1:3) == 'B3U') ) then
|
2021-06-07 11:01:37 +02:00
|
|
|
write(*,*) 'SUCCESS READ POINT GROUP'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(-1)
|
|
|
|
endif
|
2021-06-01 14:59:08 +02:00
|
|
|
|
2021-06-07 11:17:02 +02:00
|
|
|
endif
|
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
rc = trexio_close(trex_file)
|
2021-06-04 18:14:45 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) then
|
|
|
|
write(*,*) 'SUCCESS CLOSE'
|
|
|
|
else
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
print *, trim(str)
|
|
|
|
call exit(1)
|
|
|
|
endif
|
2021-04-01 22:48:04 +02:00
|
|
|
|
2021-03-22 16:40:45 +01:00
|
|
|
|
2021-03-30 14:20:46 +02:00
|
|
|
! ================= END OF TEST ===================== !
|
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
end subroutine test_read
|
2021-03-23 18:12:53 +01:00
|
|
|
|