1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-05 11:00:30 +01:00

inline with master branch

This commit is contained in:
q-posev 2021-06-07 11:01:37 +02:00
commit 231fe479e7
4 changed files with 163 additions and 36 deletions

View File

@ -87,7 +87,7 @@ tests_test_f_SOURCES = $(test_trexio_f) tests/test_f.f90
tests_test_f_LDADD = src/libtrexio.la tests_test_f_LDADD = src/libtrexio.la
tests_test_f_LDFLAGS = -no-install tests_test_f_LDFLAGS = -no-install
$(test_trexio_f): $(test_trexio_f): $(trexio_f)
cp $(trexio_f) $(test_trexio_f) cp $(trexio_f) $(test_trexio_f)
clean-local: clean-local:

View File

@ -25,11 +25,12 @@ module trexio
implicit none implicit none
integer, parameter :: trexio_exit_code = 4 integer, parameter :: trexio_exit_code = 4
integer, parameter :: trexio_backend = 4
integer, parameter :: TREXIO_HDF5 = 0 integer(trexio_backend), parameter :: TREXIO_HDF5 = 0
integer, parameter :: TREXIO_TEXT = 1 integer(trexio_backend), parameter :: TREXIO_TEXT = 1
! integer, parameter :: TREXIO_JSON = 2 ! integer(trexio_backend), parameter :: TREXIO_JSON = 2
integer, parameter :: TREXIO_INVALID_BACK_END = 2 integer(trexio_backend), parameter :: TREXIO_INVALID_BACK_END = 2
character(kind=c_char), parameter :: TREXIO_DELIM = c_new_line character(kind=c_char), parameter :: TREXIO_DELIM = c_new_line
#+end_src #+end_src
@ -591,9 +592,10 @@ trexio_open(const char* file_name, const char mode,
interface interface
integer(8) function trexio_open_c (filename, mode, backend) bind(C, name="trexio_open") integer(8) function trexio_open_c (filename, mode, backend) bind(C, name="trexio_open")
use, intrinsic :: iso_c_binding use, intrinsic :: iso_c_binding
character(kind=c_char), dimension(*) :: filename import
character, intent(in), value :: mode character(kind=c_char), dimension(*) :: filename
integer, intent(in), value :: backend character, intent(in), value :: mode
integer(trexio_backend), intent(in), value :: backend
end function trexio_open_c end function trexio_open_c
end interface end interface
#+end_src #+end_src
@ -1867,7 +1869,7 @@ contains
implicit none implicit none
character(len=*) :: filename character(len=*) :: filename
character, intent(in), value :: mode character, intent(in), value :: mode
integer, intent(in), value :: backend integer(trexio_backend), intent(in), value :: backend
character(len=len_trim(filename)+1) :: filename_c character(len=len_trim(filename)+1) :: filename_c
filename_c = trim(filename) // c_null_char filename_c = trim(filename) // c_null_char

View File

@ -16,11 +16,15 @@ int main() {
assert (rc == 0); assert (rc == 0);
test_write("test_write.h5", TREXIO_HDF5); test_write("test_write.h5", TREXIO_HDF5);
test_read ("test_write.h5", TREXIO_HDF5); test_read ("test_write.h5", TREXIO_HDF5);
rc = system("rm -rf test_write.h5");
assert (rc == 0);
rc = system("rm -rf test_write.dir"); rc = system("rm -rf test_write.dir");
assert (rc == 0); assert (rc == 0);
test_write("test_write.dir", TREXIO_TEXT); test_write("test_write.dir", TREXIO_TEXT);
test_read ("test_write.dir", TREXIO_TEXT); test_read ("test_write.dir", TREXIO_TEXT);
rc = system("rm -rf test_write.dir");
assert (rc == 0);
return 0; return 0;
} }

View File

@ -1,11 +1,24 @@
program test_trexio program test_trexio
use trexio
implicit none
call test_write() call system('rm -rf trexio_test_fort')
call test_read() 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')
end program test_trexio end program test_trexio
subroutine test_write() subroutine test_write(file_name, back_end)
! ============ Test write functionality =============== ! ! ============ Test write functionality =============== !
@ -14,10 +27,16 @@ subroutine test_write()
implicit none implicit none
character*(*), intent(in) :: file_name
integer(trexio_backend), intent(in) :: back_end
integer(8) :: trex_file integer(8) :: trex_file
integer :: rc = 1 integer :: rc = 1
integer :: i, num
integer :: i
integer :: num
character*(128) :: str
double precision :: charge(12) double precision :: charge(12)
double precision :: coord(3,12) double precision :: coord(3,12)
@ -53,50 +72,118 @@ subroutine test_write()
sym_str = 'B3U with some juice' // c_null_char sym_str = 'B3U with some juice' // c_null_char
! ================= START OF TEST ===================== ! ! ================= START OF TEST ===================== !
! trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT) trex_file = trexio_open(file_name, 'w', back_end)
trex_file = trexio_open('test_hdf5_fort.h5', 'w', TREXIO_HDF5)
rc = trexio_has_nucleus_num(trex_file) rc = trexio_has_nucleus_num(trex_file)
if (rc == TREXIO_HAS_NOT) write(*,*) 'SUCCESS HAS NOT 1' 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
rc = trexio_has_nucleus_charge(trex_file) rc = trexio_has_nucleus_charge(trex_file)
if (rc == TREXIO_HAS_NOT) write(*,*) 'SUCCESS HAS NOT 2' 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
rc = trexio_write_nucleus_num(trex_file, num) rc = trexio_write_nucleus_num(trex_file, num)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE NUM' 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
rc = trexio_write_nucleus_charge(trex_file, charge) rc = trexio_write_nucleus_charge(trex_file, charge)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE CHARGE' 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
rc = trexio_write_nucleus_coord(trex_file, coord) rc = trexio_write_nucleus_coord(trex_file, coord)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE COORD' 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
rc = trexio_write_nucleus_label(trex_file, label_str, 4) rc = trexio_write_nucleus_label(trex_file, label_str, 4)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE LABEL'
deallocate(label_str) deallocate(label_str)
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
rc = trexio_write_nucleus_point_group(trex_file, sym_str) rc = trexio_write_nucleus_point_group(trex_file, sym_str)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS WRITE SYMMETRY'
deallocate(sym_str) deallocate(sym_str)
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
rc = trexio_has_nucleus_num(trex_file) rc = trexio_has_nucleus_num(trex_file)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS HAS 1' 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
rc = trexio_has_nucleus_coord(trex_file) rc = trexio_has_nucleus_coord(trex_file)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS HAS 2' 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
rc = trexio_close(trex_file) rc = trexio_close(trex_file)
if (rc == TREXIO_SUCCESS) write(*,*) 'SUCCESS CLOSE' if (rc == TREXIO_SUCCESS) then
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()
subroutine test_read(file_name, back_end)
! ============ Test read functionality =============== ! ! ============ Test read functionality =============== !
use trexio use trexio
implicit none implicit none
character*(*), intent(in) :: file_name
integer(trexio_backend), intent(in) :: back_end
integer(8) :: trex_file integer(8) :: trex_file
integer :: i, j, k, ind, offset, flag integer :: i, j, k, ind, offset, flag
@ -118,20 +205,38 @@ subroutine test_read()
! ================= START OF TEST ===================== ! ! ================= START OF TEST ===================== !
! trex_file = trexio_open('trexio_test_fort', 'r', TREXIO_TEXT) trex_file = trexio_open(file_name, 'r', back_end)
trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5)
rc = trexio_read_nucleus_num(trex_file, num_read) rc = trexio_read_nucleus_num(trex_file, num_read)
if (rc == TREXIO_SUCCESS .and. num_read == num) write(*,*) 'SUCCESS READ NUM' 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
rc = trexio_read_nucleus_charge(trex_file, charge) rc = trexio_read_nucleus_charge(trex_file, charge)
if (rc == TREXIO_SUCCESS .and. (abs(charge(11) - 1.0) < 1.0D-8) ) write(*,*) 'SUCCESS READ CHARGE' 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
rc = trexio_read_nucleus_coord(trex_file, coord) rc = trexio_read_nucleus_coord(trex_file, coord)
if (rc == TREXIO_SUCCESS .and. (abs(coord(2,1) - 1.39250319d0) < 1.0D-8) ) write(*,*) 'SUCCESS READ COORD' 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
rc = trexio_read_nucleus_label(trex_file, label_str, 4) rc = trexio_read_nucleus_label(trex_file, label_str, 4)
@ -158,17 +263,33 @@ subroutine test_read()
write(*,*) label write(*,*) label
! -------------------------------------------------- ! --------------------------------------------------
if (rc == TREXIO_SUCCESS .and. (trim(label(2)) == 'Na') ) write(*,*) 'SUCCESS READ LABEL' 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
rc = trexio_read_nucleus_point_group(trex_file, sym_str) rc = trexio_read_nucleus_point_group(trex_file, sym_str)
write(*,*) sym_str write(*,*) sym_str
if (rc == TREXIO_SUCCESS .and. (trim(sym_str) == 'B3U') ) write(*,*) 'SUCCESS READ SYMMETRY' if (rc == TREXIO_SUCCESS .and. (trim(sym_str) == 'B3U') ) then
write(*,*) 'SUCCESS READ POINT GROUP'
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) write(*,*) 'SUCCESS CLOSE' if (rc == TREXIO_SUCCESS) then
write(*,*) 'SUCCESS CLOSE'
else
call trexio_string_of_error(TREXIO_READONLY,str)
print *, trim(str)
call exit(1)
endif
call trexio_string_of_error(TREXIO_READONLY,str)
write(*,*) str
! ================= END OF TEST ===================== ! ! ================= END OF TEST ===================== !