Simulation Core
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

137 lignes
5.2 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_C(address,port,password,datakey,status) BIND(C, name='initConnection')
  10. use iso_c_binding, only: c_char,c_int
  11. character(kind=c_char) :: address(*)
  12. integer(kind=c_int)::port,status
  13. character(kind=c_char) :: password(*),datakey(*)
  14. END SUBROUTINE initConnection_C
  15. SUBROUTINE setData_C(part,str) BIND(C,name='setData')
  16. use iso_c_binding, only: c_char
  17. character(kind=c_char) :: str(*)
  18. character(kind=c_char) :: part(*)
  19. END SUBROUTINE setData_C
  20. FUNCTION getData_C(len) BIND(C,name='getData')
  21. use iso_c_binding, only: c_ptr,c_int
  22. integer(kind=c_int)::len
  23. type(c_ptr) :: getData_C
  24. END FUNCTION getData_C
  25. SUBROUTINE deallocateData() BIND(C, name='deallocData')
  26. END SUBROUTINE deallocateData
  27. End Interface
  28. contains
  29. SUBROUTINE initConnection(address,port,password, datakey,status)
  30. use iso_c_binding, only: c_null_char,c_char
  31. ! use json_module
  32. character(len=*) :: password,address,datakey
  33. integer::port,status
  34. character(len=:),allocatable::c_address,c_password,c_datakey
  35. ! type(json_file) :: jsonfile
  36. ! type(json_value),pointer :: jsonvalue,jsonvalue2
  37. ! type(json_core) :: jsoncore
  38. ! call jsonfile%initialize()
  39. ! print *,"Initilized: simulation with ",configFilename
  40. ! call jsonfile%load_file(configFilename);
  41. ! if (jsonfile%failed()) then
  42. ! print *,"can not open config file: ",configFilename ;
  43. ! stop
  44. ! endif
  45. ! ! print *,"file read"
  46. ! call jsonfile%json_file_get_root(jsonvalue)
  47. ! call jsoncore%get(jsonvalue,'redis',jsonvalue2)
  48. ! call jsoncore%get(jsonvalue2,"address",address);
  49. ! call jsoncore%get(jsonvalue2,"port",port);
  50. ! call jsoncore%get(jsonvalue2,"password",password);
  51. ! call jsoncore%get(jsonvalue2,"datakey",datakey);
  52. c_datakey = datakey//c_null_char
  53. c_password = password//c_null_char
  54. c_address = address//c_null_char
  55. call initConnection_C(c_address,port,c_password,c_datakey,status)
  56. ! print *,"returned to initConnection"
  57. END SUBROUTINE initConnection
  58. SUBROUTINE setData(str)
  59. use SimulationVariables
  60. use iso_c_binding, only: c_null_char
  61. character(len=*):: str
  62. character(len=len_trim(str)+1)::c_str
  63. character(len=4)::part
  64. part = "out"//c_null_char
  65. c_str = str//c_null_char
  66. if(log_level>4) print *,"setting Data: ",len_trim(str)
  67. call setData_C(part,c_str)
  68. END SUBROUTINE setData
  69. SUBROUTINE setInput(str)
  70. use SimulationVariables
  71. use iso_c_binding, only: c_null_char
  72. character(len=*):: str
  73. character(len=len_trim(str)+1)::c_str
  74. character(len=4)::part
  75. part = "in"//c_null_char
  76. c_str = str//c_null_char
  77. if(log_level>4) print *,"setting Data: ",len_trim(str)
  78. call setData_C(part,c_str)
  79. END SUBROUTINE setInput
  80. SUBROUTINE getData(string)
  81. use iso_c_binding, only: c_char,c_ptr,c_f_pointer,c_null_ptr
  82. ! character(:),allocatable :: getData2
  83. character(:),allocatable :: string
  84. integer :: string_shape(1)
  85. type(c_ptr) :: c_string
  86. integer::l
  87. l = 30000
  88. ! print *,"reading data l=",l
  89. c_string = getData_C(l)
  90. ! print *,"data read. l=",l
  91. ! len = int(c_len,kind=kind(len))
  92. string_shape(1) = l!int(l,kind=kind(Integer))
  93. if(.not. allocated(string)) then
  94. print *,"allocate string"
  95. allocate(character(l) :: string)
  96. endif
  97. call c_f_pointer(c_string, string, string_shape)
  98. c_string=c_null_ptr
  99. string = trim(string)
  100. ! print *,len_trim(string), "chars read."
  101. ! print *,string(1:l)
  102. ! getData2=string
  103. END SUBROUTINE getData
  104. ! SUBROUTINE getData2(string) !result(string)
  105. ! use iso_c_binding, only: c_char,c_ptr,c_f_pointer,c_null_ptr
  106. ! ! character(:),allocatable :: getData2
  107. ! character(:),allocatable :: string
  108. ! integer :: string_shape(1)
  109. ! type(c_ptr) :: c_string
  110. ! integer::l
  111. ! ! print *,"reading data (getData2)"
  112. ! c_string = getData_C(l)
  113. ! ! string = c_str
  114. ! ! len = int(c_len,kind=kind(len))
  115. ! string_shape(1) = l! int(l,kind=kind(integer))
  116. ! if(.not. allocated(string)) allocate(character(l) :: string)
  117. ! call c_f_pointer(c_string, string, string_shape)
  118. ! c_string=c_null_ptr
  119. ! ! print *,len_trim(string), "chars read."
  120. ! ! print *,string(1:l)
  121. ! ! getData2=string
  122. ! END SUBROUTINE getData2
  123. END Module RedisInterface