This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subroutine caller(arg, called) | |
integer :: arg | |
external :: called | |
call called(arg) | |
end subroutine caller |
as it is in fortran 77. It actually compiles by pgf90 but does not run (worked for the function which did not take any arguments).
You should actually include interface description for it to work in f90:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subroutine caller(arg, called) | |
integer :: arg | |
interface | |
subroutine called(arg) | |
integer :: arg | |
end subroutine called | |
end interface | |
call called(arg) | |
end subroutine caller |
Update: This appeared also to be the case when passing to a subrouting allocatable array which is supposed to be initialized inside the subroutine. And also, as I understood from the posts of smart people, it is not necessary to describe the interface of the called subroutine if it is declared inside a module.
Below is the example of a subroutine parameter which has an allocatable array as one of the arguments:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program main | |
implicit none | |
interface | |
subroutine to_be_called(arg, nx, ny, arr) | |
integer :: arg, nx, ny | |
integer, allocatable, intent(out) :: arr(:, :) | |
end subroutine to_be_called | |
end interface | |
print *, "Hello" | |
call caller(5, to_be_called) | |
end program main | |
subroutine to_be_called(iarg, nx, ny, arr) | |
integer :: iarg, nx, ny | |
integer, allocatable, intent(out) :: arr(:, :) | |
allocate (arr(nx, ny)) | |
arr = iarg | |
end subroutine to_be_called | |
subroutine caller(arg, called) | |
integer :: arg | |
interface | |
subroutine called(arg, nx, ny, arr) | |
integer :: arg, nx, ny | |
integer, allocatable, intent(out) :: arr(:, :) | |
end subroutine called | |
end interface | |
integer :: nx, ny | |
integer, allocatable :: arr(:, :) | |
nx = 5; | |
ny = 5; | |
call called(arg, nx, ny, arr) | |
print *, size(arr) | |
print *, arr | |
end subroutine caller |