C*******************************************************************************
C  POST.NEW.STHEADS.F77 -- A PROGRAM TO CREATE NEW STARTING HEADS FROM AN
C  PREVIOUS MODEL RUN.
C               BY   WES DANSKIN
C                    LAST REVISION 2/8/89
C*****************************************************************************
C  MAIN PROGRAM
C*****************************************************************************
      DIMENSION BUF(40,180)
      CHARACTER*80 HEADNG
C  READ CONTROL PARAMETERS
      READ(30,902)HEADNG
      WRITE(6,902)HEADNG
      READ(30,902)HEADNG
      WRITE(6,902)HEADNG
      READ(30,903)NL,NR,NC,NYEARS
      WRITE(6,903)NL,NR,NC,NYEARS
C  DEFINE DIMENSIONS OF ROWS AND COLUMNS
C      NC=40
C      NR=180
C      NL=2
C  SET WHICH ARRAY TO GET
       READ(5,900)ITSTEP
C  READ ALL ARRAYS UP TO THE ONE OF INTEREST
       DO 100 I=1,ITSTEP
C  ZERO MATRICES AND VARIABLES
      CALL ZERO2D (BUF,NC,NR)
      IREAD=0
      IOUT=0
C  READ HEAD DATA
C--HEADS, LAYER 1 (UPPER)
      IREAD=49
      IOUT=68
      READ(IREAD)KSTP,KPER,PERTIM,TOTIM,TEXT,NCOL,NROW,ILAY
      CALL ZERO2D (BUF,NC,NR)
      READ(IREAD)BUF
      IF(I.EQ.ITSTEP)CALL HEADST (BUF,NC,NR,NL,IOUT)
C--HEADS, LAYER 2 (LOWER)
      IREAD=49
      IOUT=69
      READ(IREAD)KSTP,KPER,PERTIM,TOTIM,TEXT,NCOL,NROW,ILAY
      CALL ZERO2D (BUF,NC,NR)
      READ(IREAD)BUF
      IF(I.EQ.ITSTEP)CALL HEADST (BUF,NC,NR,NL,IOUT)
  100 CONTINUE
C  FORMAT STATEMENTS
  900 FORMAT(I10)
  902 FORMAT(A80)
  903 FORMAT(4I10)
C  END OF MAIN PROGRAM
      STOP
      END
C*****************************************************************************
      SUBROUTINE ZERO2D(BUF,NC,NR)
C*****************************************************************************
      DIMENSION BUF(40,180)
C      COMMON /ZERO2/ BUF
C--ZERO 2-DIMENSIONAL BUFFER
      DO 100 J=1,NR
      DO 100 I=1,NC
        BUF(I,J)=0.
  100 CONTINUE
      RETURN
      END
C*****************************************************************************
      SUBROUTINE ZERO3D(BUFF,NC,NR,NL)
C*****************************************************************************
      DIMENSION BUFF(40,180,2)
C      COMMON /ZERO3/ BUFF
C--ZERO 3-DIMENISONAL BUFFER
      DO 100 K=1,NL
      DO 100 J=1,NR
      DO 100 I=1,NC
        BUFF(I,J,K)=0.
  100 CONTINUE
      RETURN
      END
C*****************************************************************************
      SUBROUTINE HEADST (BUF,NC,NR,NL,IOUT)
C
C  CREATE FILE OF OUTPUT HEADS TO USE AS STARTING HEADS FOR OTHER SIMULATIONS
C
C*****************************************************************************
      DIMENSION BUF(40,180)
C--WRITE OUTPUT FILE OF HEADS IN INPUT FORMAT
      DO 100 J=1,NR
      WRITE(IOUT,900)(BUF(I,J),I=1,NC)
  100 CONTINUE
C--FORMAT STATEMENTS
  900 FORMAT(8F10.2)
      RETURN
      END
