Mohammed Niyasdeen
Mohammed Niyasdeen

Reputation: 39

Is there any common Fortran compiler for both f77 and f90 codes

I am trying to run some of old legacy fortran code of my team.

  1. I have two Fortran 77 codes (cklib.f and grcom.f) which I compile using fort77 and got two object files.
  2. And I have two Fortran 90 codes (write_counterflow_sol.f and read_counterflow_sol.f) which I compile using gfortran and got another two object files.

Now, using a following makefile, I am trying to create an executable called remail.e

SOURCE_CHEMKIN = ../CHEMKIN/DATA_BASES/SOURCES
SOURCE_APPLI= ../SOURCES_COUNTERFLOW/
SOURCES_f77 = $(SOURCE_CHEMKIN)cklib.f $(SOURCE_APPLI)grcom.f $(SOURCE_APPLI)write_counterflow_sol.f $(SOURCE_APPLI)read_counterflow_sol.f
TARGET = remail.e
OBJECTS =  $(SOURCES_f77:.f=.o)
COMPILE = f90
.f90.o :
    $(COMPILE) -o $*.o -c $*.f90
.f.o :
    $(COMPILE) -o $*.o -c $*.f
$(TARGET) : $(OBJECTS)
$(COMPILE)  $(OBJECTS) -o $@
del :
$(DELETE) $(OBJECTS)

but end up with the following error,

make: f90: Command not found
make: *** [remail.e] Error 127

I know there is no f90 compiler in my system, so I tried with COMPILE=gfortran instead of COMPILE=f90in the makefile and ended up with this error.

gfortran  ../CHEMKIN/DATA_BASES/SOURCES/cklib.o ../SOURCES_COUNTERFLOW/grcom.o ../SOURCES_COUNTERFLOW/write_counterflow_sol.o ../SOURCES_COUNTERFLOW/read_counterflow_sol.o -o remail.e
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start': 
(.text+0x20): undefined reference to `main'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckcomp_':
fort77-27216-1.c:(.text+0x3a4a): undefined reference to `s_cmp'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckcpml_':
fort77-27216-1.c:(.text+0x3eb8): undefined reference to `pow_di'
fort77-27216-1.c:(.text+0x476f): undefined reference to `s_wsle'
fort77-27216-1.c:(.text+0x4788): undefined reference to `do_lio'
fort77-27216-1.c:(.text+0x478d): undefined reference to `e_wsle'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckrat_':
fort77-27216-1.c:(.text+0xfac0): undefined reference to `pow_dd'
fort77-27216-1.c:(.text+0xfb17): undefined reference to `pow_dd'
fort77-27216-1.c:(.text+0xfef5): undefined reference to `pow_di'
../SOURCES_COUNTERFLOW/grcom.o: In function `MAIN__':
fort77-27073-1.c:(.text+0x1d): undefined reference to `s_copy'
fort77-27073-1.c:(.text+0x36): undefined reference to `s_copy'
fort77-27073-1.c:(.text+0x13e): undefined reference to `s_wsle' 
../SOURCES_COUNTERFLOW/write_counterflow_sol.o: In function `write_counterflow_sol__':
fort77-27083-1.c:(.text+0x85): undefined reference to `f_open'
fort77-27083-1.c:(.text+0xc0): undefined reference to `s_wsfe'
fort77-27083-1.c:(.text+0xd6): undefined reference to `do_fio'
../SOURCES_COUNTERFLOW/read_counterflow_sol.o: In function `read_counterflow_sol__':
fort77-28808-1.c:(.text+0x85): undefined reference to `f_open'
fort77-28808-1.c:(.text+0x9b): undefined reference to `s_rsfe'
fort77-28808-1.c:(.text+0xb1): undefined reference to `do_fio'
collect2: error: ld returned 1 exit status
make: *** [remail.e] Error 1

Also I tried with COMPILE=f77 in the makefile and successfully executed but when I run the executable I get this following error.

fmt: end of file
apparent state: unit 14 named sol2
last format: (3i10)
lately reading sequential formatted external IO
Aborted (core dumped)

The output of f77 -v gives the following,

/usr/bin/f77: fort77 Version 1.15
/usr/bin/f77: No input files specified

The output of f77 --version gives the following,

/usr/bin/f77: Illegal option: --version

The output of type f77 gives the following,

f77 is hashed (/usr/bin/f77)

Sorry for the long post. But any help is appreciated.

Upvotes: 0

Views: 1128

Answers (2)

So to be specific. Most of the current errors you see in your post are from the missing fort77 runtime library. The code you compiled with f77 translated its open, read, write,... statements to calls to functions implemented in C in the runtime library. Eg., f_open is called where the open statement was invoked, the pow_dd function is called where some power like a**b was invoked when both a and b are double precision, pow_di is for a**i where i is an integer, and so on.

These functions are incompatible with gfortran-compiled code. The I/O part of the library is incompatible. The files opened in fort77 code cannot be used by read or write in gfortran and vice versa.

You might be able to get most of the error messages go away by linking the runtime library. Perhaps by -lf2c. However, that does not mean the code will work correctly. It might in simple cases, but it won't in general.

You should really compile everything with gfortran as janneb answered. If your code is incompatible with gfortran, it is very likely not standard conforming and will have to be fixed.

For specific advice on such possible fixes you have to create questions with the specific errors, such as How to solve the "fmt: end of file, last format: (3i10)" error? but with a full [mcve]. We really need a full code that we can test with all the necessary data it needs. The code must be also reasonably short. Be aware that isolating such small independent code is often hard work, but it is necessary.

Upvotes: 1

janneb
janneb

Reputation: 37208

Gfortran supports Fortran 90, which is a superset of Fortran 77. Gfortran also supports several popular language extensions that were commonly used before Fortran 90.

Trying to use several different compilers to compile a single application will likely lead to problems due to different runtime libraries and different ABI's.

So, forget about fort77 and g77 and other obsolete compilers.

Upvotes: 3

Related Questions