! 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 G16M
    implicit none
    public :: Decap
  contains
    function Decap( String ) result( Decap_R )
      character (len = *), intent(in) :: String  ! Assumed length (see Section 8.3)
      character (len = len( String )) :: Decap_R ! Automatic length result
      integer, parameter :: ALPHABET = 26
      character (len = ALPHABET), parameter :: UCAlph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", &
          LCAlph = "abcdefghijklmnopqrstuvwxyz"
      integer :: Next, S
  ! start function Decap
      Decap_R = String
      do S = 1, len( String )
        Next = index( UCAlph, String(S: S) )
        if (Next /= 0) then
          Decap_R(S: S) = LCAlph (Next: Next)
        end if
      end do
      return
    end function Decap
  end module G16M
