views:

365

answers:

2

I am looking for an rpm or simple install instructions for getting f2c to work on my redhat linux os. I am new to linux and it is difficult finding something like this on google.

(The goal is to use f2c to convert a simple fortran77 file to c, then compile)

Does anybody have any suggestions?

+1  A: 
  1. Getting the source with rsync (recommended):

    $ rsync -avz netlib.org::netlib/f2c/src f2c
    

    Getting the sources via FTP:

    $ mkdir -p f2c/src
    $ cd f2c/src
    $ ftp ftp.netlib.org
    ftp> cd f2c
    ftp> prompt
    ftp> mget *
    
  2. To build the sources, in the f2c/src directory do:

    $ make -f makefile.u
    
  3. To install the binary, copy it to a directory in your $PATH:

    $ mkdir -p /usr/local/bin /usr/local/man/man1
    $ cp f2c /usr/local/bin
    $ cp f2c.1t /usr/local/man/man1
    
  4. To compile Fortran programs you will also need libf2c:

    $ mkdir libf2c
    $ cd libf2c
    $ unzip ../libf2c.zip
    $ make -f makefile.u
    $ make -f makefile.u install LIBDIR=/usr/local/lib
    

    libf2c is a combination of the libF77 and libI77 libraries. You can install these libraries separately and then link with "-lF77 -lI77". Assuming f2c/src is available from the current directory, save libF77 and libI77 and do the following (not necessary if you have already installed libf2c above):

    $ sh libf77
    $ sh libi77
    $ cd libF77
    $ make CFLAGS=-I../f2c/src
    $ make install LIBDIR=/usr/local/lib
    $ cd ../libI77
    $ make CFLAGS=-I../f2c/src
    $ make install LIBDIR=/usr/local/lib
    
  5. The fc shell script is a nice frontend to use with f2c. Save it somewhere and do:

    $ cp fc /usr/local/bin/f77
    $ chmod 755 /usr/local/bin/f77
    

    I renamed it to f77 to avoid conflicts, since fc is a bash builtin. The fc script expects libf2c rather than libF77 and libI77, so you have to edit it and replace "-lf2c" with "-lF77 -lI77" if you have installed these libraries instead of libf2c above.

  6. Finally, to compile your program you can do:

    $ f77 source.f -o binary
    

Also check out the f2c parent directory. It contains getopt.c, f2c.pdf and some other stuff that may be useful.

For more further information about f2c consult the readme (less f2c/src/readme) and the manpage (man f2c). For further information about the fc script look at the comments at the beginning of the file.

Inshallah
wow. that's an incredible answer! thanks! i got it to install. However, when i run "f77 source.f -o binary", i get this error: "error: f2c.h: No such file or directory". Do you know what I am doing wrong? (I installed libf2c according to your first set of instructions)
chris
You can try *"f77 -I f2c/src source.f -o binary"*, where f2c/src is the directory that contains the f2c sources (including f2c.h). Copying f2c.h into /usr/local/include should make this permanent.
Inshallah
+2  A: 

You can get a precompiled f2c package from ATrpms: http://atrpms.net/name/f2c/ It does include both the headers (such as f2c.h) and the library (libf2c) in standard directories, so you shouldn't have any trouble compiling after that.

Otherwise, you could try to compile directly with a free Fortran compiler; try gfortran. If not installed, it's in package gcc-gfortran, so you can install it with the command: yum install gcc-gfortran.

FX