From 0a28b5e5a5812d56246b211798b774da06b7485e Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 23 Mar 2021 16:34:13 +0100 Subject: [PATCH] working read_num [fortran] --- src/templates_front/templator_front.org | 2 +- src/test.f90 | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 111184d..f1678b1 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -468,7 +468,7 @@ interface integer (c_int32_t) function trexio_read_$group_num$ (trex_file, num) bind(C) use, intrinsic :: iso_c_binding type (c_ptr), intent(in), value :: trex_file - integer (c_int64_t), value :: num + type (c_ptr), value :: num end function trexio_read_$group_num$ end interface diff --git a/src/test.f90 b/src/test.f90 index 00e410f..a95e6a1 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -7,18 +7,30 @@ program test_trexio type(c_ptr) :: file1 integer :: rc - integer (c_int64_t) :: num + integer (c_int64_t) :: num + + type(c_ptr) :: num_test + integer, pointer :: num_read + integer, target :: num666 rc = 0 num = 10 + num_test = c_loc(num666) + file1 = trexio_open('trexio_test' // c_null_char, 'w', 1) ! file1 = trexio_open('test_fort.h5' // c_null_char, 'w', 0) rc = trexio_write_nucleus_num(file1, num) - if (rc == 0) write(*,*) 'SUCCESS 1' + if (rc == 0) write(*,*) 'SUCCESS WRITE' + + rc = trexio_read_nucleus_num(file1, num_test) + + call c_f_pointer(num_test, num_read) + + if (rc == 0 .and. num_read == num) write(*,*) 'SUCCESS READ' rc = trexio_close(file1) - if (rc == 0) write(*,*) 'SUCCESS 2' + if (rc == 0) write(*,*) 'SUCCESS CLOSE' end program test_trexio