Module quad1
  Implicit None
  Private
  Public rectangle_rule
  Interface rectangle_rule
    Module Procedure rectangle_dp
  End Interface
Contains
  Subroutine rectangle_dp(f,from,to,nstep,integral)
    Interface
      Double Precision Function f(x)
        Double Precision,Intent(In) :: x
      End Function
    End Interface
    Double Precision,Intent(In) :: from,to
    Integer,Intent(In) :: nstep
    Double Precision,Intent(Out) :: integral
    Double Precision x1,x2,y,stepval
    Integer i
    If (to<=from) Error Stop 'Invalid from-to'
    stepval = (to-from)/nstep
    x1 = from
    integral = 0
    Do i=1,nstep
      x2 = from + i*stepval
      y = f((x1+x2)/2)
      integral = integral + y
      x1 = x2
    End Do
    integral = integral*stepval
  End Subroutine
End Module
