C******************** START FILE GRFUF1.FOR ; GROUP GRFUF1 *************
C  GRAFX4 - DMC - REWRITTEN BASIC F1,2,3,4(X) GRAPHICS INTERFACE ROUTINE
C    THIS ROUTINE CONTROLS DRAWING AND LABELING OF A 1 PAGE PLOT
C    OF *FOUR* FUNCTIONS Fj(X), AND GENERATION OF A
C    REPLOT/RESCALE (UREAD) OPTION MENU
C
C  DEFAULT LINE STYLES:
C
C    Y1 -- SOLID,  Y2 -- SHORT DASH  Y3 -- LONG DASH,  Y4 -- DOT-DASH
C
C
C    A NEW CALLING ARGUMENT LIST IS PROVIDED
C
      SUBROUTINE GRAFX4(X,Y,Y2,Y3,Y4,N,XUN,YUN,LBL1,LBL2,LBL3)
C
C  DATA:
      REAL X(N),Y(N),Y2(N),Y3(N),Y4(N)
C  LABELS:
      CHARACTER*(*) XUN,YUN,LBL1,LBL2,LBL3
C
C  CONTROL:
      INTEGER IMENU
C
C  IF IMENU=1 JUMP DIRECTLY TO REPLOT MENU (DO NOT DRAW GRAPH 1ST)
C
      integer icounter
      integer, save :: iopcod=0
C
C  SCALE SETTING COMMON BLOCKS --
C
      INCLUDE 'GSCALE_BLK'
C
      INCLUDE 'PLOT1MMX'
C
      EXTERNAL GRADUM  ! FOR GRAOPT CALL INTERFACE
C
      DATA IMENU/0/
C
C-------------------------------------------------------------
C
      icounter=0
C-------------------------------------
C
C  SCALE SET SWITCHE CLEARED:
C
      ILOCSC=0
C
C  GET DEFAULT AXIS SELECTION
C
      CALL GAXGDF(ISEL)
C
      IF(IMENU.EQ.1) GO TO 200
C
C----------------------------------------------------------------
C  AUTOMATIC GENERATION OF PLOT
C
 100  CONTINUE
      icounter=icounter+1
C
C  SET AXES
C
      CALL GAXCUR(ISEL)
C
      IF(ILOCSC.EQ.0) THEN
C  COMPUTE X AND Y PLOT SCALE (USE GSCALE DEFAULTS)
        CALL GSCSET(X,Y,Y2,1,N)
      ELSE IF(ILOCSC.EQ.1) THEN
C  COMPUTE Y AUTOSCALE ONLY
        CALL GSCMMX(X,N,Y,Y2,1,N,1,1,1,1,N,XMIN,XMAX,1)
        CALL GSCYDF(1)
      ENDIF
C
      zxmin=xmin
      zxmax=xmax
      zymin=ymin
      zymax=ymax
C
      IF(ILOCSC.EQ.0) THEN
C  COMPUTE X AND Y PLOT SCALE (USE GSCALE DEFAULTS)
        CALL GSCSET(X,Y3,Y2,1,N)
      ELSE IF(ILOCSC.EQ.1) THEN
C  COMPUTE Y AUTOSCALE ONLY
        CALL GSCMMX(X,N,Y3,Y2,1,N,1,1,1,1,N,XMIN,XMAX,1)
        CALL GSCYDF(1)
      ENDIF
C
      zxmin=amin1(xmin,zxmin)
      zxmax=amax1(xmax,zxmax)
      zymin=amin1(ymin,zymin)
      zymax=amax1(ymax,zymax)
C
      IF(ILOCSC.EQ.0) THEN
C  COMPUTE X AND Y PLOT SCALE (USE GSCALE DEFAULTS)
        CALL GSCSET(X,Y4,Y2,1,N)
      ELSE IF(ILOCSC.EQ.1) THEN
C  COMPUTE Y AUTOSCALE ONLY
        CALL GSCMMX(X,N,Y4,Y2,1,N,1,1,1,1,N,XMIN,XMAX,1)
        CALL GSCYDF(1)
      ENDIF
C
      xmin=amin1(xmin,zxmin)
      xmax=amax1(xmax,zxmax)
      ymin=amin1(ymin,zymin)
      ymax=amax1(ymax,zymax)
C
      CALL GSCSEP(XMIN,XMAX)
      CALL GSCSEP(YMIN,YMAX)
C
      LUNTRM=LNOUT(0)
      CALL GAXCHK(LUNTRM,ISEL,ICOD) ! AXIS (LOG/LIN) CHECK
C
      CALL GSCREC  ! RECORD PLOT SCALE IN MEMORY
C
      CALL DPLOT1(X,Y,N,ICOD) ! DRAW GRID AND F(X) CURVE
      CALL DPLOT1(X,Y2,N,2) ! DRAW F2(X) CURVE DASHED
      CALL DPLOT1(X,Y3,N,4) ! DRAW F3(X) CURVE Long-Dash
      CALL DPLOT1(X,Y4,N,6) ! DRAW F4(X) DOT-DASH
C
      CALL GRALBL(XUN,YUN,LBL1,LBL2,LBL3)  ! LABEL THE PLOT
C
      CALL UPAUST(2)  ! PAUSE AFTER PLOT
      GO TO 200
C
C  POST PLOT OPTIONS
C
 200  CONTINUE
C
C  GENERATE MENU AND FETCH USER REPLY
C
      CALL GRAOPT('SA',ISEL,ILOCSC,IOPCOD,GRADUM)
C
C  ACT ON USER REPLY - REPLOT?
C
      IF(IOPCOD.EQ.1) THEN
         GO TO 100
      ELSE IF(IOPCOD.EQ.2) THEN
         RETURN
      ENDIF
C
      CALL UERMSI(' ?GRAFX4 *FATAL BUG* UNANTICIPATED OPERATION CODE',
     >              IOPCOD,1)
      call bad_exit
C
      END
