[PLUG] tcp/ip networking with g77 fortran?

Terry Griffin griffint at pobox.com
Sat May 22 12:14:02 UTC 2004


On Saturday 22 May 2004 11:17 am, Russell Senior wrote:
> My fortran writing experience is rather old now, but in the context of
> working with some legacy fortran code (that is actually quite fast
> compiled with g77 -O6), I have been wondering whether it is possible
> (and are there examples available) for making fortran code network
> aware?  That is, I want to know how tractable it is to retrofit an
> interface to load input data over a tcp socket instead of from a file.
> Any clues or pointers?  I am not succeeding in my google query
> attempts.

Not that I would admit to remembering any Fortran, but I think this
ought not to be too difficult. Under the hood g77 uses a library
called libg2c which is really just GNU's name for libf2c. You can
find the source for libf2c here:

   http://www.netlib.org/f2c/

(Scroll down, look for libf2c.zip.) This library is written in C but
callable from Fortran. Following the examples here it should be possible
to write your own Fortran-callable wrappers around any C functions
including BSD socket functions. The tricky bit will be figuring out how
to map a BSD socket descriptor to a Fortran Unit number. File open.c
in libf2c would probably be a good place to start for this.

Another option would to redirect externally. You could have the Fortran
program open a named pipe (which to it is just another file), while some
other program written in C feeds data to the named pipe from a network
socket.

Terry





More information about the PLUG mailing list