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)

!-- the same call but using keyword arguments in various ways
  PRINT *, series_sum(m=400, n=700, s=100.0, d=0.1)
  PRINT *, series_sum(s=100.0, d=0.1, m=400, n=700)
  PRINT *, series_sum(400, n=700, s=100.0, d=0.1)
  PRINT *, series_sum(400, d=0.1, s=100.0, n=700)
  
  CONTAINS
  
  FUNCTION series_sum(m, n, s, d) result(series_sum_result)
  
  INTEGER :: m, n, i
  REAL :: s, d, series_sum_result
  
  series_sum_result = 0.0
  DO i = m, n
    series_sum_result = series_sum_result + s + i * d
  ENDDO
  
  END FUNCTION series_sum
    
END PROGRAM series