FUNCTION howmany(k)
  IMPLICIT NONE
  INTEGER, INTENT (in) :: k
  INTEGER :: howmany

  INTEGER, PARAMETER :: fileunit = 12
  INTEGER :: n, i, p

  OPEN (unit = fileunit, file="rndint", action = "read", status = "old")

  READ (fileunit, *) n

  howmany = 0

  DO i=1,n
     READ (fileunit , *) p
     IF (p == k) howmany = howmany + 1
  ENDDO

  CLOSE (unit = fileunit)

END FUNCTION howmany


PROGRAM countfile
  IMPLICIT NONE
  INTERFACE
     FUNCTION howmany(k)
       IMPLICIT NONE
       INTEGER, INTENT (in) :: k
       INTEGER :: howmany
     END FUNCTION howmany
  END INTERFACE
  INTEGER :: a,b,c
  
  a = howmany(5744)
  b = howmany(6789)
  c = howmany(2774)

  PRINT *, a,b,c

END PROGRAM countfile
