Can Fortran 95 compiler compile Fortran 77 code?

Vineetha picture Vineetha · Jun 21, 2016 · Viewed 8.8k times · Source

Currently I'm compiling fortran95 source codes on mac using gfortran 6.1. I was wondering if I can run FORTRAN 77 source codes using the same. If not, any suggestions?

Answer

Jagte picture Jagte · Jun 21, 2016

You do not mention what error you encountered during the compilation process. See this link. Specifically:

    -std=*std*

where std may be one of ‘f95’, ‘f2003’, ‘f2008’, ‘gnu’, or ‘legacy’. The

Default value for std is ‘gnu’. From the same page: The ‘legacy’ value is equivalent but without the warnings for obsolete extensions, and may be useful for old non-standard programs. The ‘f95’, ‘f2003’ and ‘f2008’ values specify strict conformance to the Fortran 95, Fortran 2003 and Fortran 2008 standards, respectively; errors are given for all extensions beyond the relevant language standard, and warnings are given for the Fortran 77 features that are permitted but obsolescent in later standards.

For example, if you have a file old_fortran.f77 to compile, you could do:

   gfortran -std=legacy old_fortran.f77 -o a.out

where -o a.out gives you the executable a.out. I have used an older version of this compiler successfully without using this option. You may get some warnings though. First try:

   gfortran old_fortran.f77 -o a.out

EDIT: After looking at comments below by OP, it looks like a different issue may be involved. It might be that either your installation is faulty (which is possible) or your LD_LIBRARY_PATH is messed up. I think your linker (ld) in your path is 32bit and the object file that was created by your compiler might have been 64 bit. Just a hunch. Can you post the output of

  which ld

suppose that returns: /path/to/ld. Then take that output and do

  file /path/to/ld

Can you post the output of both commands as comment?