In doing the following integral I don't understand shouldn't the intent of a,b be IN what is the intent of f? shouldn't all argument variables in a subroutine have an intent? This is confusing for me even though it works i Would like to know how?
Also, I see that x is intent (in) since y gets passed as the formal argument of f in the subroutine. I'm just not sure what is going on with the intents of the subroutine also it seems like integral should be intent(OUT) right?
PROGRAM MAIN
IMPLICIT NONE
real*10 :: integral
a= 1; b =2;n=1000;
call simpson(f,a,b,integral,n)
REAL*10 FUNCTION f(x)
REAL*10, INTENT(IN) :: x
f = x**(2.*charge)*exp(-a*x**2 -(b/2)*x**4)
END FUNCTION f
SUBROUTINE simpson(f,a,b,integral,n)
REAL*10 :: integral, a, b
REAL*10 :: f
REAL*10 h, y ,s
integer n, i
! if n is odd we add +1 to make it even
if((n/2)*2.ne.n) n=n+1
! loop over n (number of intervals)
s = 0.0
h = (b-a)/dfloat(n)
do i=2, n-2, 2
y = a+dfloat(i)*h
s = s + 2.0*f(y) + 4.0*f(y+h)
end do
integral = (s + f(a) + f(b) + 4.0*f(a+h))*h/3.0
end subroutine simpson
end program main