Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran 77 compatibility with Fortran 95

  1. May 26, 2013 #1
    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!
  2. jcsd
  3. May 26, 2013 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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?
  4. May 26, 2013 #3
    It is in the same directory. I'm not sure what you mean by "full path of vegas.f"
  5. May 26, 2013 #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.
  6. May 26, 2013 #5


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
  7. May 27, 2013 #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:

    Error: Unclassifiable statement at (1)

    This makes me think that my compiler is simply not understanding the Fortran 77 code.
  8. May 27, 2013 #7


    User Avatar

    Staff: Mentor

    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.
  9. May 27, 2013 #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?
  10. May 28, 2013 #9


    User Avatar

    Staff: Mentor

    By default, the executable is named a.out. If you want it to be named vegastest, try

    gfortran -o vegastest vegastest.f95 vegas.o
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Fortran 77 compatibility with Fortran 95
  1. Fortran 95 (Replies: 12)

  2. Fortran 77 (Replies: 1)