Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Transfer data between 2 individual program fortran

  1. May 8, 2012 #1
    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
  2. jcsd
  3. May 9, 2012 #2
    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.
  4. May 9, 2012 #3
    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 ...
  5. May 10, 2012 #4


    Staff: Mentor

    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.
  6. May 10, 2012 #5
    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.
  7. May 10, 2012 #6


    User Avatar
    Homework Helper

    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.
  8. May 14, 2012 #7


    User Avatar
    Science Advisor

    Can you implement networking capability through FORTRAN like TCP/IP?

    If you can, then do this.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook