    PROGRAM g11sbfe

!      G11SBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g11sbf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, ip, ldx, n, ns
!      .. Local Arrays ..
       INTEGER, ALLOCATABLE            :: irl(:)
       LOGICAL, ALLOCATABLE            :: x(:,:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G11SBF Example Program Results'
       WRITE (nout,*)

!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n, ip

       ldx = n
       ALLOCATE (x(ldx,ip),irl(n))

!      Read in data
       READ (nin,*) (x(i,1:ip),i=1,n)

       ifail = 0
       CALL g11sbf(ip,n,ns,x,ldx,irl,ifail)

!      Display results
       WRITE (nout,*) 'Frequency     Score pattern'
       WRITE (nout,*)
       DO i = 1, ns
          WRITE (nout,99999) irl(i), x(i,1:ip)
       END DO

99999  FORMAT (1X,I5,12X,5(L2))
    END PROGRAM g11sbfe
