Real-time data exchange between Python and Fortran

Viewed 48

My dear friends, many thanks for your comments, but I still need your help. For example:

Fortran code:

program simple
implicit none
integer:: a, b, c
a = 1
b = 2
c = a + b
write(*,*) 'c = ', c
end program simple

Now, I want to use the calculated in Fortran value "c" in Python.

Python code:

# c = received data from Fortran
a = c + 1
# the variable "a" shall be sent to Fortran

Now, the calculated in Python value "a" shall be sent to Fortran, to calculate the new value of "c":

Fortran Code (I know, that this code does not work):

program simple
implicit none
integer:: a, b, c, recv_data
!recv_data = the calculated value in Python "a"
a = recv_data
b = 2
c = a + b
write(*,*) 'c = ', c
end program simple

I do not want to use the third party file (e.g. .txt), where the values can be written and read. If I would use only Python, I would use socket function (TCP/IP for server and client) to exchange data between client and server.

Are there similar options to implement a real time data exchange between Fortran and Python?

If you could provide a small example for solving this problem, I would be appreciate.

Many thanks in advance!

0 Answers
Related