*     F11DSF Example Program Text
*     Mark 19 Release. NAG Copyright 1999.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          NMAX, LA, LWORK
      PARAMETER        (NMAX=1000,LA=10000,LWORK=10000)
*     .. Local Scalars ..
      DOUBLE PRECISION OMEGA, RNORM, TOL
      INTEGER          I, IFAIL, ITN, L, LWREQ, M, MAXITN, N, NNZ
      CHARACTER        PRECON
      CHARACTER*8      METHOD
*     .. Local Arrays ..
      COMPLEX *16      A(LA), B(NMAX), WORK(LWORK), X(NMAX)
      INTEGER          ICOL(LA), IROW(LA), IWORK(2*NMAX+1)
*     .. External Subroutines ..
      EXTERNAL         F11DSF
*     .. Intrinsic Functions ..
      INTRINSIC        MAX
*     .. Executable Statements ..
      WRITE (NOUT,*) 'F11DSF Example Program Results'
      WRITE (NOUT,*)
*     Skip heading in data file
      READ (NIN,*)
*
*     Read algorithmic parameters
*
      READ (NIN,*) N
      IF (N.LE.NMAX) THEN
         READ (NIN,*) NNZ
         READ (NIN,*) METHOD, PRECON
         READ (NIN,*) OMEGA
         READ (NIN,*) M, TOL, MAXITN
*
*        Check size of workspace
*
         L = N
         IF (PRECON.EQ.'N' .OR. PRECON.EQ.'n') L = 0
         LWREQ = MAX(4*N+M*(M+N+5)+L+121,8*N+L+120,2*N*(M+3)+M*(M+2)
     +           +L+120,11*N+L+120)
         IF (LWORK.LT.LWREQ) THEN
            WRITE (NOUT,*) 'LWORK must be at least', LWREQ
            STOP
         END IF
*
*        Read the matrix A
*
         DO 20 I = 1, NNZ
            READ (NIN,*) A(I), IROW(I), ICOL(I)
   20    CONTINUE
*
*        Read rhs vector b and initial approximate solution x
*
         READ (NIN,*) (B(I),I=1,N)
         READ (NIN,*) (X(I),I=1,N)
*
*        Solve Ax = b using F11DSF
*
         IFAIL = 0
         CALL F11DSF(METHOD,PRECON,N,NNZ,A,IROW,ICOL,OMEGA,B,M,TOL,
     +               MAXITN,X,RNORM,ITN,WORK,LWORK,IWORK,IFAIL)
*
         WRITE (NOUT,'(1X,A,I10,A)') 'Converged in', ITN, ' iterations'
         WRITE (NOUT,'(1X,A,1P,D16.3)') 'Final residual norm =', RNORM
         WRITE (NOUT,*)
*
*        Output x
*
         WRITE (NOUT,*) '                   X'
         DO 40 I = 1, N
            WRITE (NOUT,'(1X,''('',1P,D16.4,'','',1P,D16.4,'')'')') X(I)
   40    CONTINUE
*
      END IF
      STOP
      END
