program series

!-- compute the terms of the arithmetic progression (s + di) for i = m to n

  implicit none
  print *, series_sum(400, 700, 100.0, 0.1)

  print *, series_sum(m=400, n=700, s=100.0)
  print *, series_sum(m=400, n=700, s=100.0, d=0.1)
  
  contains
  
  function series_sum(m, n, s, d) result(series_sum_result)
  
  real, intent(in), optional :: d
  integer :: m, n, i
  real :: s, temp_d, series_sum_result
 
  if (present(d)) then
    temp_d = d
  else 
    temp_d = 0.1
  endif
 
  series_sum_result = 0.0
  do i = m, n
    series_sum_result = series_sum_result + s + i * temp_d
  enddo
  
  end function series_sum
    
end program series
