2021-03-22 16:40:45 +01:00
|
|
|
program test_trexio
|
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
call test_write()
|
|
|
|
call test_read()
|
|
|
|
|
|
|
|
end program test_trexio
|
2021-03-22 16:40:45 +01:00
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
subroutine test_write()
|
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-03-22 16:40:45 +01:00
|
|
|
implicit none
|
|
|
|
|
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-04-07 17:37:04 +02:00
|
|
|
integer :: num
|
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-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
|
|
|
|
|
|
|
! ================= START OF TEST ===================== !
|
2021-03-23 18:12:53 +01:00
|
|
|
|
2021-03-30 11:56:04 +02:00
|
|
|
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)
|
2021-04-01 22:48:04 +02:00
|
|
|
if (rc == TREXIO_HAS_NOT) write(*,*) 'SUCCESS HAS NOT 1'
|
2021-03-30 11:56:04 +02:00
|
|
|
rc = trexio_has_nucleus_charge(trex_file)
|
2021-04-01 22:48:04 +02:00
|
|
|
if (rc == TREXIO_HAS_NOT) write(*,*) 'SUCCESS HAS NOT 2'
|
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-03-29 14:34:41 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE NUM'
|
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-03-29 14:34:41 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE CHARGE'
|
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-03-29 14:34:41 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE COORD'
|
2021-03-23 16:34:13 +01:00
|
|
|
|
2021-03-30 11:56:04 +02:00
|
|
|
rc = trexio_has_nucleus_num(trex_file)
|
2021-04-01 22:48:04 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS HAS 1'
|
2021-03-30 11:56:04 +02:00
|
|
|
rc = trexio_has_nucleus_coord(trex_file)
|
2021-04-01 22:48:04 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS HAS 2'
|
2021-03-30 11:56:04 +02:00
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
rc = trexio_close(trex_file)
|
2021-04-01 22:48:04 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE'
|
2021-03-24 11:14:47 +01:00
|
|
|
|
|
|
|
! ---------------------------------- !
|
|
|
|
! to modify fiels of existing file:
|
|
|
|
! text backend -> open with 'w'
|
|
|
|
! hdf5 backend -> open with 'a'
|
|
|
|
! ---------------------------------- !
|
|
|
|
|
2021-03-25 11:42:13 +01:00
|
|
|
!! trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT);
|
2021-03-24 17:22:58 +01:00
|
|
|
!! trex_file = trexio_open('test_hdf5_fort.h5', 'a', TREXIO_HDF5)
|
2021-04-01 22:48:04 +02:00
|
|
|
|
2021-03-24 17:13:53 +01:00
|
|
|
! coord(1) = 666.666
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-03-24 17:13:53 +01:00
|
|
|
! rc = trexio_write_nucleus_coord(trex_file,coord)
|
2021-03-29 14:34:41 +02:00
|
|
|
! if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS MODIFY COORD'
|
2021-03-24 11:14:47 +01:00
|
|
|
|
2021-03-24 17:13:53 +01:00
|
|
|
! rc = trexio_close(trex_file)
|
2021-04-01 22:48:04 +02:00
|
|
|
! if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE'
|
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
|
|
|
|
|
|
|
|
subroutine test_read()
|
|
|
|
|
2021-03-30 14:20:46 +02:00
|
|
|
! ============ Test read functionality =============== !
|
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
use trexio
|
|
|
|
implicit none
|
|
|
|
|
2021-03-24 16:06:04 +01:00
|
|
|
integer(8) :: trex_file
|
2021-03-24 11:14:47 +01:00
|
|
|
|
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)
|
|
|
|
|
|
|
|
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-03-30 11:56:04 +02:00
|
|
|
trex_file = trexio_open('trexio_test_fort', 'r', TREXIO_TEXT)
|
|
|
|
! trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5)
|
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-03-29 14:34:41 +02:00
|
|
|
if (rc == TREXIO_SUCCESS .and. num_read == num) write(*,*) 'SUCCESS READ NUM'
|
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-03-30 14:20:46 +02:00
|
|
|
if (rc == TREXIO_SUCCESS .and. (abs(charge(11) - 1.0) < 1.0D-8) ) write(*,*) 'SUCCESS READ CHARGE'
|
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
|
|
|
|
|
|
|
if (rc == TREXIO_SUCCESS .and. (abs(coord(2,1) - 1.39250319d0) < 1.0D-8) ) write(*,*) 'SUCCESS READ COORD'
|
2021-03-24 17:22:58 +01:00
|
|
|
|
2021-03-24 11:14:47 +01:00
|
|
|
rc = trexio_close(trex_file)
|
2021-04-01 22:48:04 +02:00
|
|
|
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE'
|
|
|
|
|
|
|
|
call trexio_string_of_error(TREXIO_READONLY,str)
|
|
|
|
write(*,*) str
|
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
|
|
|
|