C     -----------------
      SUBROUTINE STEPS1
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 DEFINES THE TIME STEP RANGE, THE INTIAL TIME,
C     THE STARTING TIMESTEP, THE NUMBER OF STRESS PERIODS AND THE PRINT
C     AND PLOTTING SEQUENCE FOR A MODEL RUN. THE SUBROUTINE IS CALLED
C     ONCE BY THE MAIN PROGRAM.
C
C     INTERNAL SCALARS AND ARRAYS:
C     ISTEP1      STARTING TIME STEP NUMBER FOR SIMULATION.
C     ISTEP2      ENDING TIME STEP NUMBER FOR SIMULATION.
C     STIME0      INITIAL ELAPSED TIME FOR SIMULATION.
C     NSTRESS     NUMBER OF STRESS PERIODS IN A SIMULATION.
C     TIME()      LENGTH OF STRESS PERIOD.
C     FDELT()     ACCELERATION FACTOR OF TIME WITHIN A STRESS PERIOD.
C     NSTEPS()    NUMBER OF TIME STEPS IN A STRESS PERIOD.
C     NTRANS()    NUMBER OF TRANSPORT STEPS WITHIN A FLOW STEP.
C     NPRINT      NUMBER OF STEPS WITH PRINT OUTPUT.
C     IPRINT()    STEP NUMBER WITH PRINT OUTPUT.
C     NPLOT       NUMBER OF STEPS WITH PLOT OUTPUT.
C     IPLOT()     STEP NUMBER WITH PLOT OUTPUT.
C
C     COMMON BLOCKS.
C     FNAME()     NAMES OF INPUT FILES.
C     RNAME1      SIMULATION NAME FOR GROUNDWATER-FLOW FILES.
C     RNAME2      SIMULATION NAME FOR SOLUTE-TRANSPORT FILES.
C     CNAME()     NAMES FOR COMPARTMENTS.
C     NNC()       NUMBER OF NODES WITHIN A COMPARTMENT.
C     NEC()       NUMBER OF WEDGE ELEMENTS WITHIN A COMPARTMENT.
C     IEL()       PARENT WEDGE ELEMENT FOR TETRAHEDRAL ELEMENT.
C     IN()        ELEMENT INCIDENCE FOR A WEDGE ELEMENT.
C     IN2()       ELEMENT INCIDENCES FOR A TETRAHEDRAL ELEMENT,
C                     WELL LINK, FAULT ELEMENT, OR FAULT LINK.
C     X()         X-COORDINATE OF A NODE.
C     Y()         Y-COORDINATE OF A NODE.
C     Z()         Z-COORDINATE OF A NODE.
C     A()         VECTOR OF NON-ZERO COEFFICIENTS FOR CONDUCTANCE
C                     MATRIX.
C     B()         VECTOR OF NON-ZERO COEFFICIENTS FOR CAPACITANCE
C                     MATRIX.
C     F()         RIGHTHAND VECTOR FOR SYSTEM OF EQUATIONS.
C     IA()        VECTOR INDICATING POSITIONS OF ROW ENDS IN
C                     VECTOR A() OR B().
C     JA()        VECTOR INDICATION COLUMN NUMBER ASSOCIATED WITH
C                     ENTRIES IN VECTORS A() OR B().
C     QX()        DARCY GROUNDWATER VELOCITY IN THE X-DIRECTION.
C     QY()        DARCY GROUNDWATER VELOCITY IN THE Y-DIRECTION.
C     QZ()        DARCY GROUNDWATER VELOCITY IN THE Z-DIRECTION.
C     ITRAN       SWITCH FOR TRANSPORT SIMULATION.
C
      INCLUDE 'DIMEN.INC'
      INCLUDE 'WUNITS.INC'
      IMPLICIT REAL*8 (A-H,O-Z)
      IMPLICIT INTEGER*4 (I-N)
C
C     INTERNAL ARRAYS.
      INTEGER*4 NSTEP(MAXSTP),NTRAN(MAXSTP),IPRINT(MAXSTP),IPLOT(MAXSTP)
      REAL*8 DELT0(MAXSTP),FDELT(MAXSTP),TIME(MAXSTP)
      CHARACTER*80 INFILE,OUTPATH,OUTEXT
C
C     COMMON BLOCKS.
      CHARACTER*80 FNAME(30)
      CHARACTER*12 RNAME1,RNAME2
      CHARACTER*20 CNAME(MAXCEL)
      INTEGER*4 NNC(MAXCEL),NEC(MAXCEL)
      INTEGER*4 IN(MAXNE,6),IN2(MAXNE2,4),IEL(MAXNE2)
      REAL*8 X(MAXNN),Y(MAXNN),Z(MAXNN)
      INTEGER*4 IA(MAXNN+1),JA(MAXNON)
      REAL*8 A(MAXNON),B(MAXNON),F(MAXNN)
      REAL*8 QX(MAXNE2),QY(MAXNE2),QZ(MAXNE2)
      COMMON /NAMES/ FNAME,RNAME1,RNAME2
      COMMON /CELLS/ NCELL,CNAME,NNC,NEC
      COMMON /MESH/ X,Y,Z,IN,IN2,IEL,NE,NE2,NE3,NE4,NE5,NN,NN3,NN5
      COMMON /STEPS/ ISTEP,ISTEP1,ISTEP2,DELT,STIME,IPRN,IPLT,NTSTEP,
     +    ITSTEP
      COMMON /MATRIX/ A,B,IA,JA,NIA,NJA,F
      COMMON /SHARE/ QX,QY,QZ,ITRAN
      SAVE
C
C     INPUT TIME STEP RANGE AND INITIAL TIME.
      READ(IRBAS,902) ISTEP1,ISTEP2,STIME0
      WRITE(IWBAS,903) ISTEP1,ISTEP2,STIME0
C
C     CHECK DIMENSIONS.
      IF (ISTEP2.GT.MAXSTP) THEN
          WRITE(*,904)
          WRITE(*,908)
          STOP
      ENDIF
C
C     CHECK STEP RANGE.
      IF (ISTEP1.GT.ISTEP2) THEN
          WRITE(*,906)
          WRITE(*,908)
          STOP
      ENDIF
C
C     INPUT STRESS PERIOD PARAMETERS.
      READ(IRBAS,910) NSTRESS
      WRITE(IWBAS,912) NSTRESS
C
C     CHECK DIMENSIONS.
      IF (NSTRESS.GT.MAXSTP) THEN
          WRITE(*,914)
          WRITE(*,908)
          STOP
      ENDIF
C
C     LOOP OVER STRESS PERIODS.
      DO ISTRESS=1,NSTRESS
C
C         INPUT LENGTH OF PERIOD, EXPANSION FACTOR, AND NUMBER OF STEPS.
          READ(IRBAS,916) TIME(ISTRESS),FDELT(ISTRESS),NSTEP(ISTRESS),
     +        NTRAN(ISTRESS)
          JSTEP=JSTEP+NSTEP(ISTRESS)
C
C         CALCULATE INITIAL TIME STEP.
          XDELT=1.0/FDELT(ISTRESS)
          XSTIME=0.0
          DO I=1,NSTEP(ISTRESS)
              XDELT=XDELT*FDELT(ISTRESS)
              XSTIME=XSTIME+XDELT
          END DO
          DELT0(ISTRESS)=TIME(ISTRESS)/XSTIME
          WRITE(IWBAS,920) TIME(ISTRESS),FDELT(ISTRESS),NSTEP(ISTRESS),
     +        DELT0(ISTRESS),NTRAN(ISTRESS)
      END DO
      WRITE(IWBAS,921) JSTEP
C
C     CHECK FOR SUFFICIENT STRESS PERIODS.
      IF (JSTEP.LT.ISTEP2) THEN
          WRITE(*,918)
          WRITE(*,908)
          STOP
      ENDIF
C
C     INPUT PRINT AND PLOT SCHEDULE.
      READ(IRBAS,922) NPRINT
      WRITE(IWBAS,924) NPRINT
      READ(IRBAS,926) (IPRINT(II),II=1,NPRINT)
      WRITE(IWBAS,928) (IPRINT(II),II=1,NPRINT)
      READ(IRBAS,930) NPLOT
      WRITE(IWBAS,932) NPLOT
      READ(IRBAS,934) (IPLOT(II),II=1,NPLOT)
      WRITE(IWBAS,936) (IPLOT(II),II=1,NPLOT)
      RETURN
C
C     FORMATS
900   FORMAT(1X,'*START READING IN FLUX')
901   FORMAT(1X,'**START READING IN FLUX**')
902   FORMAT(2I10,F10.0)
903   FORMAT(/1X,'TIME STEP PARAMETERS:'/
     +    1X,'INITIAL TIME STEP.......................',I10/
     +    1X,'FINAL TIME STEP.........................',I10/
     +    1X,'INITIAL TIME............................',F10.1)
904   FORMAT(1X,'*ERROR* NUMBER OF TIME STEPS EXCEEDS DIMENSION')
906   FORMAT(1X,'*ERROR* RANGE OF TIME STEPS INVERTED')
908   FORMAT(1X,'*ERROR* SIMULATION TERMINATED IN STEPS')
910   FORMAT(I10)
912   FORMAT(/1X,'STRESS PERIOD PARAMETERS:'/
     +    1X,'NUMBER STRESS PERIODS...................',I10/
     +    1X,'PERIODS:'/
     +    1X,4X,'LENGTH',4X,'FACTOR',5X,'STEPS',3X,'INITIAL',6X,'TRAN')
914   FORMAT(1X,'*ERROR* NUMBER OF STRESS PERIODS EXCEEDS DIMENSION')
916   FORMAT(2F10.0,2I10)
918   FORMAT(1X,'*ERROR* INSUFFICIENT STEPS IN STRESS PERIODS')
920   FORMAT(1X,2(1PE10.2),I10,1PE10.2,I10)
921   FORMAT(/1X,'NUMBER OF TIME STEPS....................',I10)
922   FORMAT(I10)
924   FORMAT(/1X,'PRINT OUTPUT CONTROL:'/
     +    1X,'NUMBER OF OUTPUT STEPS..................',I10/
     +    1X,'OUTPUT STEPS:')
926   FORMAT(5I10)
928   FORMAT(1X,10I5)
930   FORMAT(I10)
932   FORMAT(/1X,'PRINT OUTPUT CONTROL:'/
     +    1X,'NUMBER OF OUTPUT STEPS..................',I10/
     +    1X,'OUTPUT STEPS:')
934   FORMAT(5I10)
936   FORMAT(1X,10I5)
C
C     ------------
      ENTRY STEPS2
C     ------------
C
C     INITIALIZE ELAPSED TIME.
      IF (ISTEP.EQ.ISTEP1) STIME=STIME0
C
C     IDENTIFY CURRENT STRESS PERIOD.
      JSTEP2=0
      DO ISTRESS=1,NSTRESS
          JSTEP1=JSTEP2+1
          JSTEP2=JSTEP2+NSTEP(ISTRESS)
          IF (ISTEP.GE.JSTEP1 .AND. ISTEP.LE.JSTEP2) EXIT
      END DO
C
C     IDENTIFY CURRENT TIME STEP AND TRANSPORT STEPS WITHIN FLOW STEP.
      DELT=DELT0(ISTRESS)/FDELT(ISTRESS)
      DO JSTEP=JSTEP1,ISTEP
          DELT=DELT*FDELT(ISTRESS)
      END DO
      STIME=STIME+DELT
      NTSTEP=NTRAN(ISTRESS)
C
C     IDENTIFY IF PRINT OR PLOT STEP.
      IPRN=0
      IPLT=0
      DO II=1,NPRINT
          IF (IPRINT(II).EQ.ISTEP) THEN
              IPRN=1
              EXIT
          ENDIF
      END DO
      DO II=1,NPLOT
          IF (IPLOT(II).EQ.ISTEP) THEN
              IPLT=1
              EXIT
          ENDIF
      END DO
      RETURN
      END SUBROUTINE
