1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 18:57:39 +02:00

more fortran-ic test

This commit is contained in:
q-posev 2021-03-24 16:06:04 +01:00
parent f7c78e73d2
commit c0b6f95e52

View File

@ -11,29 +11,20 @@ subroutine test_write()
use, intrinsic :: iso_c_binding
implicit none
type(c_ptr) :: trex_file
integer(8) :: trex_file
integer :: rc
integer (c_int64_t) :: num
integer(8) :: num
real, dimension(12), target :: charge
real, dimension(36), target :: coord
type(c_ptr) :: charge_ptr
real(c_double), pointer :: charge_cp(:)
type(c_ptr) :: coord_ptr
real(c_double), pointer :: coord_cp(:)
double precision :: charge(12)
double precision :: coord(36)
rc = 0
num = 12
charge = (/6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /)
allocate(charge_cp(size(charge)))
charge_cp = charge
charge_ptr = c_loc(charge_cp)
coord = (/ 0.00000000 , 1.39250319 , 0.00000000 , &
-1.20594314 , 0.69625160 , 0.00000000 , &
-1.20594314 , -0.69625160 , 0.00000000 , &
@ -47,22 +38,17 @@ subroutine test_write()
2.14171677 , 1.23652075 , 0.00000000 , &
0.00000000 , 2.47304151 , 0.00000000 /)
allocate(coord_cp(size(coord)))
coord_cp = coord
coord_ptr = c_loc(coord_cp)
rc = 0
trex_file = trexio_open('test_text_fort' // c_null_char, 'w', 1)
! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'w', 0)
trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT)
! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'w', TREXIO_HDF5)
rc = trexio_write_nucleus_num(trex_file, num)
if (rc == 0) write(*,*) 'SUCCESS WRITE NUM'
rc = trexio_write_nucleus_charge(trex_file, charge_ptr)
rc = trexio_write_nucleus_charge(trex_file, charge)
if (rc == 0) write(*,*) 'SUCCESS WRITE CHARGE'
rc = trexio_write_nucleus_coord(trex_file, coord_ptr)
rc = trexio_write_nucleus_coord(trex_file, coord)
if (rc == 0) write(*,*) 'SUCCESS WRITE COORD'
rc = trexio_close(trex_file)
@ -74,22 +60,16 @@ subroutine test_write()
! hdf5 backend -> open with 'a'
! ---------------------------------- !
trex_file = trexio_open('test_text_fort' // c_null_char, 'w', 1);
! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'a', 0)
trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT);
! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'a', TREXIO_HDF5)
coord(1) = 666.666
coord_cp = coord
coord_ptr = c_loc(coord_cp)
rc = trexio_write_nucleus_coord(trex_file,coord_ptr)
rc = trexio_write_nucleus_coord(trex_file,coord)
if (rc == 0) write(*,*) 'SUCCESS MODIFY COORD'
rc = trexio_close(trex_file)
if (rc == 0) write(*,*) 'SUCCESS CLOSE 2'
deallocate(charge_cp)
deallocate(coord_cp)
if (rc == 0) write(*,*) 'SUCCESS CLOSE'
end subroutine test_write
@ -99,49 +79,30 @@ subroutine test_read()
use, intrinsic :: iso_c_binding
implicit none
type(c_ptr) :: trex_file
integer(8) :: trex_file
integer :: rc
integer (c_int64_t) :: num
integer(8) :: num, num_read
type(c_ptr) :: num_test
integer, pointer :: num_read
integer, target :: num666
real, dimension(12) :: charge
type(c_ptr) :: charge_ptr
real(c_double), pointer :: charge_read(:)
double precision :: charge(12)
num = 12
charge = (/0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0. /)
allocate(charge_read(size(charge)))
charge_read = charge
charge_ptr = c_loc(charge_read)
rc = 0
num_test = c_loc(num666)
trex_file = trexio_open('test_text_fort' // c_null_char, 'r', TREXIO_TEXT)
! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'r', TREXIO_HDF5)
trex_file = trexio_open('test_text_fort' // c_null_char, 'r', 1)
! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'r', 0)
rc = trexio_read_nucleus_num(trex_file, num_test)
call c_f_pointer(num_test, num_read)
rc = trexio_read_nucleus_num(trex_file, num_read)
if (rc == 0 .and. num_read == num) write(*,*) 'SUCCESS READ NUM'
rc = trexio_read_nucleus_charge(trex_file, charge_ptr)
call c_f_pointer(charge_ptr, charge_read, [num_read])
rc = trexio_read_nucleus_charge(trex_file, charge)
if (rc == 0 .and. (abs (charge_read(11) - 1.0) < 1.0D-8) ) write(*,*) 'SUCCESS READ CHARGE'
if (rc == 0 .and. (abs (charge(11) - 1.0) < 1.0D-8) ) write(*,*) 'SUCCESS READ CHARGE'
rc = trexio_close(trex_file)
if (rc == 0) write(*,*) 'SUCCESS CLOSE'
deallocate(charge_read)
end subroutine test_read