Esteemed FTN Gurus,
Both of My FTN 95 books are unclear on how to pass as arguments the names of (i) array-valued functions, and (ii) subroutines. Perhaps someone can help. :?:
A short sample program is appended at the end of this query to illustrate the problem. For a scalar-valued function, everything works. But with the array-valued function, passing its name as an argument bombs out ('floating point stack fault...') while running
- although it does not generate any compile errors.
1.) Do I need the INTENT(IN) attribute in the REAL, EXTERNAL declaration of function FUNC_1D?
2.) What is the trick to getting the name of an array-valued function to work when passed as an argument?
3.) How do I pass the name of a subroutine as an argument?
With many thanks 😄, Ludwig
!############################################ module subroutine_library contains !------------------------------------------------- subroutine tabulate_function_1d (func) implicit none integer :: i real :: x real, external, intent(in) :: func do i = 1, 10 x = real(i) print 100, x, func(x) end do 100 format ('x = ', f12.7, 3x, 'f = ', f12.7) end subroutine tabulate_function_1d !------------------------------------------------- subroutine tabulate_function_2d (func) implicit none integer :: i, j real, dimension(2) :: x, f real, external, intent(in) :: func do i = 1, 3 do j = 1, 3 x = (/ real(i), real(j) /) f = func(x) print 100, x(1), x(2), f(1), f(2) end do end do 100 format ('x1 = ', f12.7, 1x, 'x2 = ', f12.7, 1x, / & 'f1 = ', f12.7, 1x, 'f2 = ', f12.7) end subroutine tabulate_function_2d !------------------------------------------------- end module subroutine_library !############################################ module function_library contains !------------------------------------------------- function func_1d (x) result (f) implicit none real, intent(in) :: x real :: f f = x**2 end function func_1d !------------------------------------------------- function func_2d (x) result (f) implicit none real, dimension(2), intent(in) :: x real, dimension(2) :: f f(1) = x(1) + x(2) f(2) = x(1)**2 + x(2)**2 end function func_2d !------------------------------------------------- end module function_library !############################################ program try use subroutine_library use function_library call tabulate_function_1d (func_1d) call tabulate_function_2d (func_2d) end program try !############################################