From f8a28a037da81f1f0ede1ea390d367391f6576ff Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 24 Mar 2021 17:13:53 +0100 Subject: [PATCH] more fortran-ic trexio_open --- src/templates_front/templator_front.org | 29 ++++++++++++++++++++----- src/test.f90 | 21 +++++++++--------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 55fd1b1..6b00cd1 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -295,12 +295,12 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b #+begin_src fortran :tangle prefix_fortran.f90 interface - integer(8) function trexio_open (filename, mode, backend) bind(C) + integer(8) function trexio_open_c (filename, mode, backend) bind(C, name="trexio_open") use, intrinsic :: iso_c_binding - character(kind=c_char), dimension(*) :: filename - character, intent(in), value :: mode - integer, intent(in), value :: backend - end function trexio_open + character(kind=c_char), dimension(*) :: filename + character, intent(in), value :: mode + integer, intent(in), value :: backend + end function trexio_open_c end interface #+end_src @@ -621,6 +621,25 @@ end interface - Text files: not to be used for production, but useful for debugging - JSON: for portability + +* Fortran helper/wrapper functions + + #+begin_src fortran :tangle suffix_fortran.f90 +contains + integer(8) function trexio_open (filename, mode, backend) + use, intrinsic :: iso_c_binding + implicit none + character(len=*) :: filename + character, intent(in), value :: mode + integer, intent(in), value :: backend + character(len=len_trim(filename)+1) :: filename_c + + filename_c = trim(filename) // c_null_char + trexio_open = trexio_open_c(filename_c, mode, backend) + end function trexio_open + #+end_src + + * File suffixes :noxport: #+begin_src c :tangle suffix_front.h diff --git a/src/test.f90 b/src/test.f90 index d6fe1b8..2085c48 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -38,9 +38,8 @@ subroutine test_write() 2.14171677 , 1.23652075 , 0.00000000 , & 0.00000000 , 2.47304151 , 0.00000000 /) - - 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) +! trex_file = trexio_open('test_text_fort', 'w', TREXIO_TEXT) + trex_file = trexio_open('test_hdf5_fort.h5', 'w', TREXIO_HDF5) rc = trexio_write_nucleus_num(trex_file, num) if (rc == 0) write(*,*) 'SUCCESS WRITE NUM' @@ -60,16 +59,16 @@ subroutine test_write() ! hdf5 backend -> open with 'a' ! ---------------------------------- ! - trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT); +! 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(1) = 666.666 - rc = trexio_write_nucleus_coord(trex_file,coord) - if (rc == 0) write(*,*) 'SUCCESS MODIFY COORD' +! 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' +! rc = trexio_close(trex_file) +! if (rc == 0) write(*,*) 'SUCCESS CLOSE' end subroutine test_write @@ -90,8 +89,8 @@ subroutine test_read() rc = 0 - 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', 'r', TREXIO_TEXT) + trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5) rc = trexio_read_nucleus_num(trex_file, num_read)