Simulation Core
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

139 Zeilen
4.9 KiB

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