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 pass_array_by_data_05_find_fit_module
implicit none
contains
subroutine find_fit(data_x, expr)
real, intent(in) :: data_x(:)
real :: y
interface
function expr(x) result(z)
real, intent(in) :: x(:)
real :: z
end function expr
end interface
print *, size(data_x)
y = expr(data_x)
print *, y
if (abs(y - 6.000) > 1e7 ) error stop
end subroutine find_fit
end module
program example_primes
use pass_array_by_data_05_find_fit_module, only: find_fit
implicit none
real :: data_x(3)
integer :: i
data_x = [1.0, 2.0, 3.0]
call find_fit(data_x, expression)
contains
function expression(x) result(y)
real, intent(in) :: x(:)
real :: y
integer :: i
do i = 1, size(x)
y = y + x(i)
end do
end function expression
end program example_primes
|