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

Fortran - c interprocess communication

  1. Oct 24, 2011 #1
    there is a program in written in fortran 90 and a program written in c, the first program is able to modify .xyz (mol files) and the C program can read those,
    so is it possible to make an interprocess communication between these 2 program to let one update instantly if i change anything in the fortran progra for example or in the c program
    if i change anything in the .xyz file using fortran it should instantly appear changed in the c program and vica versa
    is that possible somehow? i am not sure about c and fortran interprocessing abilities
    thanks for the help in advance

    i think my problem is quite similar to this topic but i am not using 2 fortran program so thats why i am not sure about compatibility that c and fortran is compatible in both ways or not
  2. jcsd
  3. Oct 24, 2011 #2


    User Avatar
    Science Advisor

    There are different ways you can do this.

    In terms of Inter Process Communication (IPC), typically you use pretty standardized objects like pipes. A pipe is basically a read,write,(or both) object and typically what happens is that programs create specially named pipes, and then each process will get the appropriate handle and then send and receive data to it, as if it was like a network connection.

    Similarly one trick you could use is to use a network protocol of some sort. This could be overkill, but it does work.

    In the context of your problem (making changes to file, need to update other programs), there is bound to be an OS level framework that allows this, but I haven't tried it myself. In terms of IPC, I've used the network idea and used a standard protocol framework that uses publish/subscribe (fancy way for managing events and callbacks) and with that you just make a connection and send a network packet to another port on the local machine.

    I haven't used FORTRAN though, so what kind of access can you get to functions in DLL's? Is there a platform library, or some way of getting access to system level libraries (DLL's or SO's)?
  4. Oct 24, 2011 #3
    i am not sure about what you are asking but i dont think so you can access systems dll`s

    by the way would you be more specific or can you provide any links about your ideas where i can look for details how to do it and which program i have to rewrite to make this communication possible?

    i got the source code of both program so i can change anything i want in c and the fortran one as well but i am not sure how to do it

    i was thinking about a loop first (thats runs with the program till quitting) which is checking for changes in the files or something
  5. Oct 25, 2011 #4


    User Avatar
    Science Advisor

    In terms of the networking ideas, its basically implementing a simple network model based on the reliable TCP/IP protocol. For this, just look at the sockets library. Windows has an implementation called Winsock, which you you will want to check out for windows, or on the *nix platform, just use the standard sockets library.

    For pipes, just look up named pipes. If you want more details look at the Windows API documentation.

    You should also look at things like this:

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook