Real Function series_sum(init_term, next_func, nterms, extra_arg)
 Implicit None
 Real, external :: next_func
 Real, Intent(IN) :: init_term, extra_arg
 Integer, Intent(IN) :: nterms
 ! some local variables
 Real :: ans, cterm
 integer :: i
 ! initialize
 ans = init_term
 cterm = init_term 
 do i = 2, nterms
   cterm = next_func(cterm, i, extra_arg)
   ans = ans + cterm
 end do
 series_sum = ans
End Function series_sum
