Fortran 77 compatibility with Fortran 95

  • Fortran
  • Thread starter ngendler
  • Start date
  • Tags
    Fortran
In summary, your compiler is not reading the f77 code in 'vegas.f'. You will have to do a little detective work to find out what is causing the compiler to generate errors.
  • #1
ngendler
20
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
  • #2
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?
 
  • #3
It is in the same directory. I'm not sure what you mean by "full path of vegas.f"
 
  • #4
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.
 
  • #5
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.
 
  • #6
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.
 
  • #7
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.
 
  • #8
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?
 
  • #9
By default, the executable is named a.out. If you want it to be named vegastest, try

gfortran -o vegastest vegastest.f95 vegas.o
 

FAQ: Fortran 77 compatibility with Fortran 95

What is the difference between Fortran 77 and Fortran 95?

Fortran 95 is an updated version of Fortran 77, with new features and improvements such as better support for modern programming techniques and improved error handling. It also includes all the features of Fortran 77, making it backward compatible.

Can Fortran 77 code be compiled and run in a Fortran 95 compiler?

Yes, Fortran 95 is designed to be compatible with Fortran 77, so most Fortran 77 codes can be compiled and run in a Fortran 95 compiler without any modifications.

Are there any differences in syntax between Fortran 77 and Fortran 95?

Yes, Fortran 95 introduces some new syntax, such as the use of the "intent" keyword for procedure arguments and the "optional" keyword for optional arguments. However, these new syntax features do not affect the compatibility of Fortran 77 code.

Are there any major changes in the standard library between Fortran 77 and Fortran 95?

Fortran 95 introduces some new library functions and modules, but it also includes all the functions and modules from Fortran 77. So, Fortran 77 code using standard library functions should still be compatible with Fortran 95.

Can I mix Fortran 77 and Fortran 95 code in the same program?

Yes, Fortran 95 allows for mixing Fortran 77 and Fortran 95 code in the same program. However, care should be taken to ensure that the syntax and features used are compatible between the two versions.

Similar threads

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