! 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.14. Pattern matching (one occurrence) with the intrinsic function Index.
  program G14
    implicit none
    integer, parameter :: Lines = 5, L_S = 50
    character (len = *), parameter :: Pattern = "meter"
    integer, dimension(Lines) :: Location
    integer :: Loop
    character (len = L_S), dimension(Lines) :: Metric
! start program G14
    Metric(1) = " One centimeter equals ten millimeters. "
    Metric(2) = " One decimeter equals ten centimeters. "
    Metric(3) = " One meter equals ten decimeters. "
    Metric(4) = " One thermometer equals ten meters. "  ! ??
    Metric(5) = " This is the key to the metric system. "
    do Loop = 1, Lines
      Location(Loop) = index (String = Metric(Loop), Substring = Pattern)
    end do
    write (unit = *, fmt = *) Location
    stop
  end program G14
