C     Last change:  TJD  23 Oct 2005    4:21 pm
C
C     ---------------------------------------
      SUBROUTINE SITPACK1(RNAME,ISEL,OUTFILE)
C     ---------------------------------------
C
C     SUBROUTINE AUTHOR:
C     TIM DURBIN
C     TIMOTHY J. DURBIN, INC.
C     5330 PRIMROSE DRIVE, SUITE 228
C     FAIR OAKS, CA 95628
C     (916) 536-2314
C
C     PURPOSE:
C     THIS SUBROUTINE INPUTS PAPAMETERS FOR SOLVING THE SYSTEM
C     OF LINEAR EQUATIONS A*X=B USING JACOBI CONJUGATE GRADIENT METHOD.
C     TO SOLVE A SYSTEM OF EQUATIONS, THIS SUBROUTINE CALLS SUBROUTINE
C     JCG WITHIN THE ITPACK SOLVER PACKAGE.
C
      INCLUDE 'DIMEN.INC'
      INCLUDE 'WUNITS.INC'
      IMPLICIT REAL*8 (A-H,O-Z)
      IMPLICIT INTEGER*4 (I-N)
C
C     INTERNAL SCALARS AND ARRAYS ARRAYS.
C     OUTFILE     OUTPUT FILE NAME.
C     RNAME       SIMULATION NAME.
C     RPARAM()    VECTOR OF REAL PARAMETER VALUES PASSED TO
C                 SUBROUTINE JCG.
C     IPARAM()    VECTOR OF INTEGER PARAMETER VALUES PASSED TO
C                 SUBROUTINE JCG.
C     WKSP()      REAL WORKSPACE VECTOR USED BY SUBROUTINE JCG.
C     IWKSP()     INTEGER WORKSPACE VECTOR USE BY SUBROUTINE JCG.
C     A()         LEFTTHAND MATRIX WITHIN SYSTEM OF EQUATIONS.
C     X()         VECTOR OF UNKNOWNS WITHIN SYSTEM OF EQUATIONS.
C     B()         RIGHTHAND VECTOR WITHIN SYSTEM OF EQUATIONS.
C     IA()        VECTOR INDICATING NUMBER OF NON-ZERO COEFFICIENTS
C                 IN A ROW OF THE LEFTHAND MATRIX.
C     JA()        VECTOR INDICATING COLUMN NUMBER OF A NON-ZERO
C                 COEFFICIENT WITHIN A ROW OF THE LEFTHAND MATRIX.
C     ISEL        SWITCH FOR SELECTING PARAMETER SET FOR SOLVING
C                 GROUNDWATER-FLOW OR SOLUTE-TRANSPORT EQUATIONS.
C     ITMAX()     MAXIMUM NUMBER OF SOLVER ITERATIONS.
C     LEVEL()     SWITCH FOR LEVEL OF DETAIL IN SOLVER OUTPUT.
C     EPS()       CLOSURE CRITERION FOR SOLVER ITERATIONS.
C
      CHARACTER*80 OUTFILE
      CHARACTER*12 RNAME
      REAL*8 RPARAM(12),EPS(2)
      INTEGER*4 IPARAM(12),IWKSP(MAXWKS)
      REAL*8 WKSP(MAXWKS)
      REAL*8 A(MAXNON),B(MAXNN),X(MAXNN)
      INTEGER*4 IA(MAXNN+1),JA(MAXNON),ITMAX(2),LEVEL(2)
      SAVE
C
C     INPUT SOLVER PARAMETERS.
      IF (ISEL.EQ.1) THEN
          WRITE(IWBAS,906)
      ELSE
          WRITE(IWBAS,908)
      ENDIF
      READ(IRBAS,902) ITMAX(ISEL),EPS(ISEL),LEVEL(ISEL)
      WRITE(IWBAS,910) ITMAX(ISEL),EPS(ISEL),LEVEL(ISEL),OUTFILE
      RETURN
C
C     FORMATS:
902   FORMAT(I10,F10.0,I10)
906   FORMAT(/1X,'FLOW EQUATIONS')
908   FORMAT(/1X,'TRANSPORT EQUATIONS')
910   FORMAT(1X,'ITPACK SOLUTION PARAMETERS:'/
     +    1X,'NUMBER OF ITERATIONS....................',I10/
     +    1X,'COLUSRE CRTIERION.......................',1PE10.2/
     +    1X,'SWITCH FOR OUTPUT LEVEL.................',I10/
     +    1X,'OUTPUT FILE FOR SOLVER..................',A80)
C
C     ------------------------------------------------
      ENTRY SITPACK2(IA,JA,A,X,B,NEQ,ISTEP,JITER,ISEL)
C     ------------------------------------------------
C
C     INITIAL OUTPUT.
      IF (ISEL.EQ.1) THEN
          WRITE(IWSOL,914)
      ELSE
          WRITE(IWSOL,916)
      ENDIF
      WRITE(IWSOL,918) ISTEP,JITER
C
C     SET PARAMETERS.
      CALL DFAULT(IPARAM,RPARAM)
      RPARAM(1)=EPS(ISEL)
      IPARAM(1)=ITMAX(ISEL)
      IPARAM(2)=LEVEL(ISEL)
      IPARAM(4)=IWSOL
      IPARAM(5)=1
      IPARAM(6)=1
C
C     SOLVE SYSTEM OF EQUATIONS.
      CALL JCG(NEQ,IA,JA,A,B,X,IWKSP,MAXWKS,WKSP,IPARAM,RPARAM,IER)
      WRITE(IWSOL,922) ISTEP,IPARAM(1),EPS(ISEL),RPARAM(1)
      IF (IER.EQ.0) THEN
          WRITE(IWSOL,924)
      ELSE
          WRITE(IWSOL,926) IER
      ENDIF
      WRITE(*,930) IPARAM(1),RPARAM(1),IER
      RETURN
914   FORMAT(/1X,'FLOW EQUATIONS')
916   FORMAT(/1X,'TRANSPORT EQUATIONS')
918   FORMAT(/1X,'ITERATION RESULTS:'/
     +    1X,'TIME STEP...............................',I10/
     +    1X,'TIME-STEP ITERATION.....................',I10/)
922   FORMAT(/1X,'FINAL SOLUTION RESULTS:'/
     +    1X,'TIME STEP...............................',I10/
     +    1X,'NUMBER OF ITERATIONS....................',I10/
     +    1X,'CLOSURE CRITERION.......................',1PE10.2/
     +    1X,'FINAL RESIDUAL..........................',1PE10.2)
924   FORMAT(1X,'CLOSURE STATUS..........................','OK')
926   FORMAT(1X,'CLOSURE STATUS..........................','NO CLOSURE'/
     +    1X,'CLOSURE CODE............................',I10)
930   FORMAT(1X,' SOLVER ITERATIONS=',I5,' CLOSURE=',1PE9.2,
     +    ' ERROR CODE=',I2)
      END SUBROUTINE
      INCLUDE 'ITPACK.FOR'
