# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Redis/Redis_Interface.f90" Module RedisInterface ! use iso_c_binding, only: c_char Interface SUBROUTINE addnums(a, b) BIND(C,name='addnums') USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT IMPLICIT NONE INTEGER(C_INT) :: a, b END SUBROUTINE addnums SUBROUTINE initConnection_C(address,port,password,datakey,status) BIND(C, name='initConnection') use iso_c_binding, only: c_char,c_int character(kind=c_char) :: address(*) integer(kind=c_int)::port,status character(kind=c_char) :: password(*),datakey(*) END SUBROUTINE initConnection_C SUBROUTINE setData_C(part,str) BIND(C,name='setData') use iso_c_binding, only: c_char character(kind=c_char) :: str(*) character(kind=c_char) :: part(*) END SUBROUTINE setData_C FUNCTION getData_C(len) BIND(C,name='getData') use iso_c_binding, only: c_ptr,c_int integer(kind=c_int)::len type(c_ptr) :: getData_C END FUNCTION getData_C SUBROUTINE deallocateData() BIND(C, name='deallocData') END SUBROUTINE deallocateData End Interface contains SUBROUTINE initConnection(address,port,password, datakey,status) use iso_c_binding, only: c_null_char,c_char ! use json_module character(len=*) :: password,address,datakey integer::port,status character(len=:),allocatable::c_address,c_password,c_datakey ! type(json_file) :: jsonfile ! type(json_value),pointer :: jsonvalue,jsonvalue2 ! type(json_core) :: jsoncore ! call jsonfile%initialize() ! print *,"Initilized: simulation with ",configFilename ! call jsonfile%load_file(configFilename); ! if (jsonfile%failed()) then ! print *,"can not open config file: ",configFilename ; ! stop ! endif ! ! print *,"file read" ! call jsonfile%json_file_get_root(jsonvalue) ! call jsoncore%get(jsonvalue,'redis',jsonvalue2) ! call jsoncore%get(jsonvalue2,"address",address); ! call jsoncore%get(jsonvalue2,"port",port); ! call jsoncore%get(jsonvalue2,"password",password); ! call jsoncore%get(jsonvalue2,"datakey",datakey); c_datakey = datakey//c_null_char c_password = password//c_null_char c_address = address//c_null_char call initConnection_C(c_address,port,c_password,c_datakey,status) ! print *,"returned to initConnection" END SUBROUTINE initConnection SUBROUTINE setData(str) use SimulationVariables use iso_c_binding, only: c_null_char character(len=*):: str character(len=len_trim(str)+1)::c_str character(len=4)::part part = "out"//c_null_char c_str = str//c_null_char if(logging>4) print *,"setting Data: ",len_trim(str) call setData_C(part,c_str) END SUBROUTINE setData SUBROUTINE setInput(str) use SimulationVariables use iso_c_binding, only: c_null_char character(len=*):: str character(len=len_trim(str)+1)::c_str character(len=4)::part part = "in"//c_null_char c_str = str//c_null_char if(logging>4) print *,"setting Data: ",len_trim(str) call setData_C(part,c_str) END SUBROUTINE setInput SUBROUTINE getData(string) use iso_c_binding, only: c_char,c_ptr,c_f_pointer,c_null_ptr ! character(:),allocatable :: getData2 character(:),allocatable :: string integer :: string_shape(1) type(c_ptr) :: c_string integer::l l = 30000 ! print *,"reading data l=",l c_string = getData_C(l) ! print *,"data read. l=",l ! len = int(c_len,kind=kind(len)) string_shape(1) = l!int(l,kind=kind(Integer)) if(.not. allocated(string)) then print *,"allocate string" allocate(character(l) :: string) endif call c_f_pointer(c_string, string, string_shape) c_string=c_null_ptr string = trim(string) ! print *,len_trim(string), "chars read." ! print *,string(1:l) ! getData2=string END SUBROUTINE getData ! SUBROUTINE getData2(string) !result(string) ! use iso_c_binding, only: c_char,c_ptr,c_f_pointer,c_null_ptr ! ! character(:),allocatable :: getData2 ! character(:),allocatable :: string ! integer :: string_shape(1) ! type(c_ptr) :: c_string ! integer::l ! ! print *,"reading data (getData2)" ! c_string = getData_C(l) ! ! string = c_str ! ! len = int(c_len,kind=kind(len)) ! string_shape(1) = l! int(l,kind=kind(integer)) ! if(.not. allocated(string)) allocate(character(l) :: string) ! call c_f_pointer(c_string, string, string_shape) ! c_string=c_null_ptr ! ! print *,len_trim(string), "chars read." ! ! print *,string(1:l) ! ! getData2=string ! END SUBROUTINE getData2 END Module RedisInterface