Fortran Fortran 77 compatibility with Fortran 95

  • Thread starter Thread starter ngendler
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
A user is attempting to integrate a Fortran 77 program into a Fortran 95 program but encounters issues with the INCLUDE directive. Initially, the user receives an error indicating that the compiler cannot open the file 'vegas.f'. After confirming that the file is in the same directory, the user still faces over 25 syntax errors related to the Fortran 77 code when compiling. The discussion clarifies that Fortran 77 is a subset of Fortran 95, which should allow compatibility, but the formatting differences between the two versions are causing issues. To resolve the problem, it is suggested that the user compile 'vegas.f' separately to create an object file and then link it with the Fortran 95 program. The user successfully compiles the code but then encounters an error when attempting to run the program, as the executable defaults to 'a.out'. The solution provided is to specify the output name during compilation to create an executable named 'vegastest'.
ngendler
Messages
20
Reaction score
0
Hi, I have a program written in Fortran 77 that I need to include in my Fortran 95 program. I don't have an F77 compiler, but I was told that F95 should be able to read F77 programs. I'd like to write

INCLUDE 'vegas.f'

in the first line of my program, but it's not compiling. I keep getting an error that says 'Error: Can't open included file 'vegas.f' '

Need help!
 
Technology news on Phys.org
You will have to do a little detective work.

Is 'vegas.f' on your computer?
Is 'vegas.f' in the same directory as the source file you are trying to compile?
Have you tried compiling your program with the full path of 'vegas.f' added to the INCLUDE directive?
 
It is in the same directory. I'm not sure what you mean by "full path of vegas.f"
 
Now I am not getting the same error message, but the compiler is simply not reading the f77 code. Over 25 errors on 'vegas.f', all about syntax that is clearly from the earlier version.
 
Well, we really can't provide any more detailed suggestions unless you furnish your Fortran code and the error messages. If the compiler isn't reading 'vegas.f', how are you getting specific syntax errors generated by your compiler.

Fortran 77 is supposed to be a subset of Fortran 95, in order to provide compatibility with older code.

Full path means instead of just 'vegas.f' you supply something like 'c:\subdirectory\subdirectory\vegas.f' so that the compiler can trace the location of 'vegas.f' from the root volume to the directory where the file is stored.
 
This is my Fortran 95 code. 'vegas.f' is written in Fortran 77 and too long to include in this reply:

INCLUDE 'vegas.f'

program vegastest
implicit none
external gaussian

call vegas(gaussian,0.d0,2,1000,5,1,0)

print *,'The integral of the gaussian is',s1

end program vegastest

When I compile it, I get over 25 errors similar to this one:

Included at vegastest.f95:1:

C*************************************************************
1
Error: Unclassifiable statement at (1)

This makes me think that my compiler is simply not understanding the Fortran 77 code.
 
The include statement just puts the contents of the file vegas.f inside the file vegastest.f95 when compiling. As the latter is in free form, while the fortran 77 file is formatted (comment indicated by C in the first column, 1st-5th columns for labels, 6th column for continuation of the previous line, statements in columns 7-80), it is normal that the compiler complains.

You shouldn't include the code, but compile it seperately and link the object file. For example:

gfortran -c vegas.f

gfortran vegastest.f95 vegas.o

Most modern compilers usually assume by default that a file with extension .f is column-formatted, but some compilers can require a flag be set to explicitely indicate that a file is formatted.
 
DrClaude, thank you so much for helping! That worked! The only thing is that now when I try to run the program (./vegastest), it says "-bash: ./vegastest: No such file or directory". Is there a different way I have to run the program?
 
By default, the executable is named a.out. If you want it to be named vegastest, try

gfortran -o vegastest vegastest.f95 vegas.o
 

Similar threads

Replies
25
Views
3K
Replies
3
Views
5K
Replies
5
Views
2K
Replies
17
Views
6K
Replies
8
Views
4K
Replies
4
Views
2K
Replies
5
Views
5K
Back
Top