! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

  module I09M
    implicit none
    public :: Series_Sum
  contains
    function Series_Sum (N, S, M, D) result (Series_Sum_Result)
      integer, intent (in) :: N
      real, intent (in) :: S
      integer, intent (in), optional :: M
      real, intent (in), optional :: D
      real :: Series_Sum_Result
      integer :: Temp_M, Loop
      real :: Temp_D
  ! start function Series_Sum
      if (present (M)) then
        Temp_M = M
      else
        Temp_M = 0
      end if
      if (present (D)) then
        Temp_D = D
        else
          Temp_D = 0.1
        end if
      Series_Sum_Result = 0.0
      do Loop = Temp_M, N
        Series_Sum_Result = Series_Sum_Result + S + Temp_D * real (Loop)
      end do
      return
    end function Series_Sum
  end module I09M
