Fortran Explicit and implicit interfaces External subprograms and implicit interfaces

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

A subprogram is said to be external when it is not contained in the main program, nor in a module or antoher subprogram. In particular it can be defined by means of a programming language other than Fortran.

When an external subprogram is invoked, the compiler cannot access to its code, so all the information allowable to the compiler is implicitly contained in the calling statement of the calling program and in the type an properties of the acutal arguments, not the dummy arguments (whose declaration is unknown to the compiler). In this case we say that the interface is implicit.

An external statement can be used to specify that a procedure's name is relative to an external procedure,

external external_name_list

but even so, the interface remain implicit.

An interface block can be used to specify the interface of an external procedure,

interface
  interface_body
end interface

where the interface_body is normally an exact copy of the procedure header followed by the declaration of all its arguments and, if it is a function, of the result.

For example, for function WindSpeed

real function WindSpeed(u, v)
  real, intent(in) :: u, v
  WindSpeed = sqrt(u*u + v*v)
end function WindSpeed

You can write the following interface

interface
  real function WindSpeed(u, v)
    real, intent(in) :: u, v
  end function WindSpeed
end interface


Got any Fortran Question?