Simulation Core
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

58 рядки
2.0 KiB

  1. Module RedisInterface
  2. ! use iso_c_binding, only: c_char
  3. Interface
  4. SUBROUTINE addnums(a, b) BIND(C,name='addnums')
  5. USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT
  6. IMPLICIT NONE
  7. INTEGER(C_INT) :: a, b
  8. END SUBROUTINE addnums
  9. SUBROUTINE initConnection() BIND(C, name='initConnection')
  10. END SUBROUTINE initConnection
  11. SUBROUTINE setData_C(str) BIND(C,name='setData')
  12. use iso_c_binding, only: c_char
  13. character(kind=c_char) :: str(*)
  14. END SUBROUTINE setData_C
  15. FUNCTION getData_C(len) BIND(C,name='getData')
  16. use iso_c_binding, only: c_ptr,c_int
  17. integer(kind=c_int)::len
  18. type(c_ptr) :: getData_C
  19. END FUNCTION getData_C
  20. SUBROUTINE deallocateData() BIND(C, name='deallocData')
  21. END SUBROUTINE deallocateData
  22. End Interface
  23. contains
  24. SUBROUTINE setData(str)
  25. use iso_c_binding, only: c_null_char
  26. character(len=*):: str
  27. character(len=len_trim(str)+1)::c_str
  28. c_str = str//c_null_char
  29. call setData_C(c_str)
  30. END SUBROUTINE setData
  31. SUBROUTINE getData(string) !result(string)
  32. use iso_c_binding, only: c_char,c_ptr,c_f_pointer
  33. ! character(:),allocatable :: getData2
  34. character(:),allocatable :: string
  35. integer :: string_shape(1)
  36. type(c_ptr) :: c_string
  37. integer::l
  38. ! print *,"reading data (getData2)"
  39. c_string = getData_C(l)
  40. ! string = c_str
  41. ! len = int(c_len,kind=kind(len))
  42. string_shape(1) = int(l,kind=kind(integer))
  43. if(.not. allocated(string)) allocate(character(l) :: string)
  44. call c_f_pointer(c_string, string, string_shape)
  45. ! print *,len_trim(string), "chars read."
  46. ! print *,string(1:l)
  47. ! getData2=string
  48. END SUBROUTINE getData
  49. END Module RedisInterface