module figure_5_21
public  ::  count_letter
contains
! Figure 5.21
      function count_letter (letter, string) result(c)
         character (len=*), intent(in) :: letter, string
         integer :: c
         integer :: i
      !  Count the number of occurrences of letter in string
         c = 0
         do i = 1, len(string)
            if (string(i:i) == letter(1:1)) then
               c = c + 1
            end if
         end do
      end function count_letter
end module figure_5_21
