Я знаю, что вы можете создавать общие процедуры, используя абстрактные типы, как здесь:
объявление класса fortran фиктивного аргумента
Но могу ли я сделать то же самое со следующим кодом?
module proc_mod
public :: forced,ideal
interface forced; module procedure forced1; end interface
interface forced; module procedure forced2; end interface
contains
function forced1() result(forced)
implicit none
integer:: forced
forced = 1
end function
function forced2(t) result(forced)
implicit none
integer,intent(in) :: t
integer:: forced
forced = t
end function
function ideal() result(i)
implicit none
integer:: i
i = 2
end function
end module
program procTest
use proc_mod
implicit none
integer :: n
procedure(forced), pointer:: funPointer => NULL()
write(*,'(A)') "Please enter the type of vortex calculation you wish to use."
read(*,*) n
select case( n )
case( 1 ); funPointer => forced
case( 2 ); funPointer => ideal
case default; funPointer => ideal
end select
write(*,'(A,I3)') "You chose function: ", funPointer()
stop
end program
Прямо сейчас я получаю сообщение об ошибке: funPointer не может быть универсальным. Я уверен, что есть способ обойти это, но я не знаком с общими процедурами.