Fortran Transfer data between 2 individual program fortran

AI Thread Summary
Transferring data between two separate Fortran programs is not feasible through memory sharing, as each program operates independently with its own memory space. Instead, data can be exchanged by writing to and reading from disk files, either in text or binary format. If one program is modified to function as a subroutine, it changes the context of the data transfer. Specific errors encountered during variable allocation need to be clarified for effective troubleshooting. Additionally, using handshake files can facilitate synchronization between the two programs, allowing one to signal the other when data is ready to be processed. Implementing networking capabilities, such as TCP/IP, in Fortran could also provide an alternative method for data transfer.
luonganh89
Messages
12
Reaction score
0
hi all
i try to transfer data between 2 individual program fortran . I've ever tranferred data between 2 subroutine by using common block, but 2 program make so confused. Have you ever done like me can share some experience ?

thank you
 
Technology news on Phys.org
If you are talking about 2 different fortran progarms, each with its own 'main'...it is not possible to share memory between them (that's what common blocks are...memory).

If you have the ability to run one fortran program at one time and the other at other time...you cannot expect them to share memory.

If anything, you can write the data to disk in certain order from one program and read it from the other in the same order when it runs...you can choose text or binary format.
 
Dear gsal

Of course, I know that and I try to change one of two programe to a sub-program and try to transfer data. But when i allocate some variable in it , it occcurs erros ...
 
luonganh89 said:
Dear gsal

Of course, I know that and I try to change one of two programe to a sub-program and try to transfer data. But when i allocate some variable in it , it occcurs erros ...
If you want help here, you're going to have to be more specific. "it occcurs erros" doesn't give us any ideas what kinds of problems you are encountering.
 
Yeah, please be clear...

In your original post (and title of this thread) you said you wanted to transfer data between two programs...now you say that you turned on of them into a subroutine...that's not transfering data between two programs!

If you can, "stop the hand waving" and ask very specific questions and, if possible, post the fortran code itself.
 
I assume there is no way for separate fortran programs to access each others memory via the DuplicateHandle() method available with various versions of Windows with C programs (although generally the one program has to invoke the other program in order to pass some parameters on the command line used to define and share handles required for DuplicateHandle() ).

An option would be to use a file to share data, along with one or more "handshake" files used to synchonize communication. The issue here is how to "wait" for input from the "other" program. If your version of Fortran includes a sleep function, you can reduce the cpu overhead and/or prevent locking up the process. For each handshake file, you only need one integer as a state flag for each data path (from one program to the other or vice versa):

0 = no pending data, set by sending program (and also the initial value)
1 = pending data, set by sending program (which then "waits" for value == 2 or 3)
2 = data read by receiving program, set by receiving program
3 = optional state, set by receiving program to indicate it's ready to for more data.
 
Can you implement networking capability through FORTRAN like TCP/IP?

If you can, then do this.
 

Similar threads

Replies
8
Views
4K
Replies
16
Views
3K
Replies
59
Views
11K
Replies
9
Views
4K
Replies
8
Views
4K
Replies
42
Views
5K
Back
Top