C*******************************************************************************
C  POST.HYDROGRAPH.F77 -- A PROGRAM TO CREATE A META FILE OF HYDROGAPHS OF
C  MEASURED VERSUS MODEL GENERATED WATER LEVELS
C
C               BY   WES DANSKIN
C                    LAST REVISION 10/13/89
C*******************************************************************************
C  REQUIRED DIMENSIONS
C    NUMBER OF TIMESTEPS = 26, DIMENSIONED TO 30
C    NUMBER OF MEASURED DATAPOINTS = 2000
C    HEAD ARRAY FROM MODEL (NCOL,NROW) = (40,180)
C*******************************************************************************
C      IMPLICIT REAL (A-H,O-Z)
      INTEGER TEXT(4)
      DIMENSION TMOD(30),HDMOD1(30),HDMOD2(30),HDMOD(40,180),
     - TMEAS(2000),HDMEAS(2000),TLSD(2),XLSD(2)
      CHARACTER*25 NAME1
      CHARACTER*15 NAME2,NAME3
      CHARACTER*5  ALAY
C  DEFINE CONSTANTS
      NAME2='  ROW, COL, LAY'
C  CALL DISSPLA SUBROUTINES
      CALL COMPRS
C  COMPRS AUTOMATICALLY OPENS POPFIL ON UNIT 32
C  SET PAGE SIZE
      READ(5,*)XPGSIZ,YPGSIZ
C  SET X,Y OFFSET FROM PLOT BORDER
      READ(5,*)XOFF,YOFF
C  SET DISTANCE BETWEEN SUBPLOTS
      READ(5,*)XSEP,YSEP
C  SET INITIAL XAXIS AND YAXIS VALUES
      XAXIS=2.0
      YAXIS=2.0
C  BEGIN PAGE OF PLOTS
  300 X=XOFF
      Y=YPGSIZ-YOFF-YAXIS
      CALL PAGE(XPGSIZ,YPGSIZ)
C      CALL NOBRDR
C  REZERO COUNTER
      NCOUNT=0
C  BEGIN SUBPLOTS
  310 CALL PHYSOR(X,Y)
C  SET COUNTER
      NCOUNT=NCOUNT+1
C  READ MEASURED HEAD DATA
C  READ NAME OF WELL
      READ(5,900,END=800)NAME1
      WRITE(20,900)NAME1
C      WRITE(33,900)NAME1
C  READ NUMBER OF DATA POINTS AND ALTITUDE
      READ(5,901)NMEAS,ALT
      WRITE(20,901)NMEAS,ALT
C  SET LSD ARRAY TO ALTITUDE
      XLSD(1)=ALT
      XLSD(2)=ALT
C  READ WELL MODEL LOCATION AND LAYER FLAG
      READ(5,902)KROW,KCOL,ALAY,KLAY,IFLAG
      WRITE(20,902)KROW,KCOL,ALAY,KLAY,IFLAG
C  RE-READ NAME AS A CHARACTER VARIABLE FOR HEADING
      BACKSPACE(5)
      READ(5,903) NAME3
      WRITE(20,903) NAME3
C  READ CHARACTERISTICS OF GRAPH
C  DIMENSION OF SUBPLOT IN INCHES, X AXIS, Y AXIS
      READ(5,904)XAXIS,YAXIS,XORIG,XSTP,XMAX,YORIG,YSTP,YMAX
      WRITE(20,904)XAXIS,YAXIS,XORIG,XSTP,XMAX,YORIG,YSTP,YMAX
C  SET TLSD ARRAY TO MAX AND MIN OF XAXIS
      TLSD(1)=XORIG
      TLSD(2)=XMAX
C  DO NOT PLOT LSD IF OUTSIDE GRAPH AREA
      IF(ALT.GT.YMAX)XLSD(1)=0.
      IF(ALT.GT.YMAX)XLSD(2)=0.
C  READ MEASURED HYDRAULIC HEADS
      DO 100 I=1,NMEAS
      READ(5,905)MM,DD,YY,HDMEAS(I)
      WRITE(20,906)MM,DD,YY,HDMEAS(I)
C  CONVERT TO DRAWDOWN
C      HDMEAS(I)=ALT-HDMEAS(I)
C  CONVERT TO DECIMAL DATE
      IF(MM.EQ.1)XMM=0.
      IF(MM.EQ.2)XMM=31.
      IF(MM.EQ.3)XMM=59.
      IF(MM.EQ.4)XMM=90.
      IF(MM.EQ.5)XMM=120.
      IF(MM.EQ.6)XMM=151.
      IF(MM.EQ.7)XMM=181.
      IF(MM.EQ.8)XMM=212.
      IF(MM.EQ.9)XMM=242.
      IF(MM.EQ.10)XMM=273.
      IF(MM.EQ.11)XMM=303.
      IF(MM.EQ.12)XMM=334.
      TMEAS(I)=((XMM+DD)/365.)+YY
C      WRITE(33,907)TMEAS(I),HDMEAS(I)
  100 CONTINUE
C
      ITSTEP=0
C  READ THE HEADER RECORD FROM MODEL
  350 READ(49,END=330)KSTP,KPER,PERTIME,TOTIM,TEXT,NCOL,NROW,NLAY
C  READ HYDRAULIC HEAD ARRAY FROM MODEL
      READ(49)HDMOD
      ITSTEP=KPER
      IF(NLAY.EQ.1)HDMOD1(ITSTEP)=HDMOD(KCOL,KROW)
      IF(NLAY.EQ.2)HDMOD2(ITSTEP)=HDMOD(KCOL,KROW)
      TMOD(ITSTEP)=(FLOAT(KPER))+1962.
      GO TO 350
  330 REWIND(49)
C
      CALL SETCLR('BLACK')
C      CALL HWSHD
C      CALL SETCLR('CYAN')
C      CALL HWSPEC (1.0,'BACKGROUND')
C      CALL SETCLR ('RED')
      CALL AREA2D(XAXIS,YAXIS)
      CALL INTAXS
      CALL YAXANG(0)
      CALL XAXANG(90)
      CALL XREVTK
      CALL YREVTK
      CALL THKFRM(0.000001)
      CALL FRAME
      CALL XTICKS(5)
      CALL HEIGHT(0.10)
      CALL XNAME('CALENDER YEARS$',14)
      CALL YNAME('HEAD, IN FT AMSL$',16)
      CALL HEIGHT(0.14)
      CALL HEADIN(NAME1,25,0.8,3)
      CALL HEIGHT(0.10)
      CALL HEADIN(NAME2,15,0.5,3)
      CALL HEADIN(NAME3,15,0.5,3)
      CALL GRAF(XORIG,XSTP,XMAX,YORIG,YSTP,YMAX)
      CALL CURVE(TMEAS,HDMEAS,NMEAS,0)
      CALL SETCLR('RED')
      CALL CURVE(TLSD,XLSD,2,0)
      IF(IFLAG.EQ.1) THEN
        CALL SETCLR('GREEN')
        CALL CURVE(TMOD,HDMOD1,ITSTEP,0)
        CALL SETCLR('BLUE')
        CALL CURVE(TMOD,HDMOD2,ITSTEP,0)
      ELSE
        IF(KLAY.EQ.1) THEN
          CALL SETCLR('GREEN')
          CALL CURVE(TMOD,HDMOD1,ITSTEP,0)
        ENDIF
        IF(KLAY.EQ.2) THEN
          CALL SETCLR('BLUE')
          CALL CURVE(TMOD,HDMOD2,ITSTEP,0)
        ENDIF
      ENDIF
C  END OF SUBPLOT
      CALL ENDGR(0)
      IF (NCOUNT.EQ.45)X=X+16.
      IF (NCOUNT.EQ.50)X=X+XSEP+16.
      IF (NCOUNT.EQ.55)X=X+XSEP+16.
      IF (NCOUNT.EQ.55)GOTO 790
      X=X+XSEP+XAXIS
      IF (XAXIS.LT.(XPGSIZ-X)) GOTO 310
C  RESET TO RIGHT MARGIN
      Y=Y-YSEP-YAXIS
      X=XOFF
      IF (YAXIS.LE.Y) GOTO 310
C  RESET TO NEW PLOT
  790 CONTINUE
      CALL ENDPL(0)
      GO TO 300
C  END OF PLOT
  800 CALL ENDPL(0)
      CALL DONEPL
C  FORMAT STATEMENTS
  900 FORMAT(A25)
  901 FORMAT(I10,F10.0)
  902 FORMAT(2I5,A5,2I5)
  903 FORMAT(A15)
  904 FORMAT(8F10.0)
  905 FORMAT(I2,1X,F2.0,1X,F4.0,F10.0)
  906 FORMAT(I2,1X,F4.0,1X,F6.0,F10.0)
  907 FORMAT(2F10.2)
  908 FORMAT(3(I2,1X,F2.0,1X,F4.0,F10.0,10X))
      STOP
      END
