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