Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interface between Fortran77 program and Fortran90 program

Status
Not open for further replies.

DavidF87

Programmer
Oct 3, 2018
1
GB
Hi all,
I'm new to Fortran programming, so I might probably ask some really trivial questions - please forgive me.
I have two source codes of big programs. One is coded in Fortran77 and the other one in Fortran90.
Now, I need to build an interface so that the Fortran90 program can call some subroutines/functions in the Fortran77 program.

Now, I know that usually you would use a module for that purpose: just put all the subroutines and functions you want inside the module, and call it from your main program.
However, in my case, the two programs are very big and spread across many files and obviously there are two "program units. Does that change anything? If so, how?

In general, what would you suggest be the best way of building such an interface between the two?

Cheers,
Dave
 
Nothing needs to change. They can call each other. Also not all routines have to live in modules - it just makes it easier to type use modulename rather than declaring a whole bunch of externals. Some implementations allow you to get away without declaring any externs.
Code:
     subroutine f77sub
          print *, 'f77sub'
          print *, 'calling f90'
          call f90sub
      end subroutine f77sub
Code:
subroutine f90sub
    print *, "f90sub"
end subroutine f90sub


program main
    print *, 'In f90'
    print *, 'calling f77'
    call f77sub
end program main
To build

gfortran main.f90 suby.f77

 
Well, it was mentioned that each set of sources is an actual program, each with its own "program" unit.

In any case, there is no need for a formal interface, if you don't want one.

So, it all depends what you want to achieve...if the Fortran 90 needs nothing from the "main" of the Fortran 77 and all it needs is to benefit from the subroutines, they all can be compiled into a single executable.

If you need the "main" from the Fotran 77 program to drive, manage the subroutines for the Fortran 90 program, then, you may need to turn the Fortran 77 "main" into a subroutine.

Get the picture?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top