1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
module procedure_03_mod
implicit none
interface
subroutine func(x, y, n)
implicit none
integer, intent(in) :: n
real, intent(in) :: x(n)
real, intent(out) :: y(n)
end subroutine
end interface
contains
subroutine hybrd(fcn)
procedure(func) :: fcn
integer, parameter :: m = 3
real, parameter :: eps = 1e-5
real :: a(m), b(m)
a = [1, 2, 3]
print *, lbound(a, 1), ubound(a, 1)
call fcn(a, b, m)
print *, a
print *, b
if ((b(1) - 3) > eps) error stop
if ((b(2) - 6) > eps) error stop
if ((b(3) - 9) > eps) error stop
end subroutine
end module
program procedure_03
use procedure_03_mod, only: hybrd
implicit none
call hybrd(fn)
contains
subroutine fn(x, y, k)
integer, intent(in) :: k
real, intent(in) :: x(k)
real, intent(out) :: y(k)
y = x * 3
end subroutine
end program
|