! While passing procedures as arguments a few things should be noted: ! ! (1) Functions that are declared in the main program after 'contains' ! cannot be passed as arguments ! (2) Functions declared outside of the main program have to be declared ! as external in the main program ! Module module my_mod contains function integrate(fx, a, b, n) implicit none real, external :: fx ! external here is optional but recommended real :: integrate, a, b, delta, total integer :: n, i delta = (b - a) / real (n) total = 0.0 do i = 1, n total = total + (fx (a + (i-1) * delta + delta / 2.0) ) * delta end do integrate = total end function integrate end module my_mod ! Main Program program main use my_mod implicit none real :: value real, external :: fx_1, fx_2 ! external here is necessary value = integrate(fx_1, 1., 2., 100) print*, value value = integrate(fx_2, 1., 2., 100) print*, value end program main ! --- Function 1 function fx_1(x) implicit none real :: x, fx_1 fx_1 = x**2 end function fx_1 ! --- Function 2 function fx_2(x) implicit none real :: x, fx_2 fx_2 = x**3 + x**2 end function fx_2