! 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.

! Example 6.12. Substring of a constant.
  program G12
    implicit none
    integer, parameter :: STRING_LENGTH = 120
    character (len = STRING_LENGTH) :: Text
    integer :: S, Next
! start program G12
    open (unit = 1, file = "g12.txt", status = "old", action = "read", position = "rewind")
    read (unit = 1, fmt = *) Text
    do S = 1, STRING_LENGTH
      Next = index( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Text(S: S) )
      if (Next /= 0) then
        Text(S: S) = "abcdefghijklmnopqrstuvwxyz" (Next: Next)
      end if
    end do
    write (unit = *, fmt = *) Text(: STRING_LENGTH /2)
    write (unit = *, fmt = *) Text(STRING_LENGTH /2 + 1 :)
    stop
  end program G12
