다른 유형의 서브 루틴에 인수로 유형 바인드 프로 시저를 전달하려고합니다. 이것이 Fortran에서 가능한지 알고 싶습니다. 다음은 내가하려고하는 것을 보여주는 코드 스 니펫입니다.인수로 유형 바인드 프로 시저 전달
module type_definitions
type test_type
integer :: i1, i2,i3
contains
procedure :: add_integers_up
end type test_type
contains
subroutine add_integers_up(this,i4,ans)
class(test_type) :: this
integer :: i4,ans
ans = this%i1+this%i2+this%i3+i4
end subroutine add_integers_up
subroutine print_result_of_subroutine(i4,random_subroutine)
integer :: i4,ans
interface
subroutine random_subroutine(i1,i2)
integer:: i1,i2
end subroutine random_subroutine
end interface
call random_subroutine(i4,ans)
write(*,*) ans
end subroutine print_result_of_subroutine
end module type_definitions
program main
use type_definitions
implicit none
integer :: i1,i2,i3,i4
integer :: ans
type(test_type) :: test_obj
i1 =1; i2=2; i3=3
test_obj%i1 = i1
test_obj%i2 = i2
test_obj%i3 = i3
i4 = 4
call print_result_of_subroutine(i4,test_obj%add_integers_up)
end program main
이것은 포트란에서 가능합니까? ifort를 사용하여이 코드를 컴파일하려고하면 컴파일러 오류가 발생합니다.
이 필요합니다! 인터페이스 블록에서 '절차'또는 '모듈 프로 시저'를 사용하고 직접 인터페이스를 지정하지 않도록 추가 할 수 있습니다. –