*     G12ZAF Example Program Text
*     Mark 20 Revised. NAG Copyright 2001.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          NMAX, MMAX, MLWK, MNRS
      PARAMETER        (NMAX=500,MMAX=20,MLWK=10000,MNRS=1000)
*     .. Local Scalars ..
      DOUBLE PRECISION DEV, TOL
      INTEGER          I, IFAIL, IP, IPRINT, J, LDZ, LWK, M, MAXIT, MXN,
     +                 N, ND, NS, NUM, NXS
*     .. Local Arrays ..
      DOUBLE PRECISION B(MMAX), COV(MMAX*(MMAX+1)/2), SC(MMAX),
     +                 SE(MMAX), T(NMAX), TP(NMAX), WK(MLWK),
     +                 X(MNRS,MMAX), Z(NMAX,MMAX)
      INTEGER          IC(NMAX), ID(MNRS), IRS(NMAX), ISI(NMAX),
     +                 ISZ(MMAX), IXS(MNRS), NCA(NMAX), NCT(NMAX)
*     .. External Subroutines ..
      EXTERNAL         G11CAF, G12ZAF
*     .. Executable Statements ..
      WRITE (NOUT,*) 'G12ZAF Example Program Results'
*     Skip heading in data file
      READ (NIN,*)
      READ (NIN,*) N, M, NS, MAXIT, IPRINT
      IF (N.LE.NMAX .AND. M.LE.MMAX) THEN
         IF (NS.GT.0) THEN
            DO 20 I = 1, N
               READ (NIN,*) T(I), (Z(I,J),J=1,M), IC(I), ISI(I)
   20       CONTINUE
         ELSE
            DO 40 I = 1, N
               READ (NIN,*) T(I), (Z(I,J),J=1,M), IC(I)
   40       CONTINUE
         END IF
         READ (NIN,*) (ISZ(I),I=1,M), IP
         LDZ = NMAX
         MXN = MNRS
*
         IFAIL = 0
*
         CALL G12ZAF(N,M,NS,Z,LDZ,ISZ,IP,T,IC,ISI,NUM,IXS,NXS,X,MXN,ID,
     +               ND,TP,IRS,IFAIL)
*
         TOL = 1.0D-5
         LWK = MLWK
         READ (NIN,*) (B(I),I=1,IP)
*
         IFAIL = 0
*
         CALL G11CAF(NUM,IP,NXS,X,MXN,ISZ,IP,ID,IXS,DEV,B,SE,SC,COV,NCA,
     +               NCT,TOL,MAXIT,IPRINT,WK,LWK,IFAIL)
*
         WRITE (NOUT,*)
         WRITE (NOUT,*) ' Parameter      Estimate',
     +     '       Standard Error'
         WRITE (NOUT,*)
         DO 60 I = 1, IP
            WRITE (NOUT,99999) I, B(I), SE(I)
   60    CONTINUE
      END IF
*
99999 FORMAT (I6,2(10X,F8.4))
      END
