C-------------------------------------------------------------------
C  GRF3F1  CONTROL ROUTINE, VARIOUS PLOTS OF F(X,T)
C
C  BASED ON OLD GRF3, WITH STREAMLINED INTERFACE, CHARACTER*(*)
C  LABEL PASSING MECHANISM, AND GRF3OP MENU SUBROUTINE
C
      SUBROUTINE GRF3F1(X,Z,Y,WK,NX,NY,NZ1,
     >                    XLAB,ZLAB,YLAB,
     >                    XUN,ZUN,YUN,
     >                    ZTITLE,ZLABEL,IPROC)
      implicit none
C
      LOGICAL, EXTERNAL :: LCHAR,LXOUT,LYES,LYESC
C
      integer npagec
      COMMON/GRF3PG/ NPAGEC
C
      integer NX,NY,NZ1
      REAL X(NX)	! 1ST INDEP. COORD OF FCN TO BE PLOTTED
      REAL Z(NZ1,NY)	! FCN TO BE PLOTTED
      REAL Y(NY)	! 2ND INDEP. COORD OF FCN TO BE PLOTTED
      REAL WK(NY)	! ** WORKSPACE ** MUST BE PROVIDED
C
C  X AND Y MUST BE IN ASCENDING ORDER.
C  CAREFULLY NOTE DIMENSIONING OF Z
C
C  WK WILL BE OVERWRITTEN ON CALL TO THIS ROUTINE
C
C  RECOMMENDED NOT LONGER THAN CA. 30 CHARACTERS...
      CHARACTER*(*) XLAB  ! LABEL FOR 1ST INDEP. COORDINATE
      CHARACTER*(*) ZLAB  ! LABEL FOR FCN BEING PLOTTED
      CHARACTER*(*) YLAB  ! LABEL FOR 2ND INDEP. COORDINATE
C
C  RECOMMENDED NOT LONGER THAN CA. 20 CHARACTERS...
      CHARACTER*(*) XUN   ! UNITS LABEL FOR 1ST INDEP COORDINATE
      CHARACTER*(*) ZUN   ! UNITS LABEL FOR FCN BEING PLOTTED
      CHARACTER*(*) YUN   ! UNITS LABEL FOR 2ND INDEP. COORDINATE
C
C  RECOMMENDED NOT LONGER THAN CA. 45 CHARACTERS...
      CHARACTER*(*) ZTITLE	! TITLE LABEL FOR PLOTS
C
C  RECOMMENDED NOT LONGER THAN CA. 15 CHARACTERS
      CHARACTER*(*) ZLABEL	! GENERIC LABEL FOR PLOTS
C
C  PROCESSING FLAG (FOR LABELING ONLY)
      INTEGER IPROC	    ! 0=NOTHING, 1=AVG'D, 2=SMOOTHED, ETC...
C
      logical :: lxvt = .FALSE.
C---------------------------------
C
C  THIS ROUTINE PRESENTS AN INTERACTIVE (UREAD) MENU VIA SUBROUTINE
C  GRF3OP, ALLOWING THE USER TO SELECT
C    1)  3D ISOMETRIC PLOTS
C    2)  2D SIMPLE SLICE PLOTS
C    3)  CONTOUR PLOTS
C    4)  2D SLICE MULTIPLOTS
C  OF THE PASSED LABELED DATA.
C
C  NOTE THE WORKSPACE ARRAY IS NEEDED TO BUILD SOME SLICE PLOTS AND
C  WILL BE OVERWRITTEN ON CALL TO THIS ROUTINE
C
C  ALL OTHER ARGUMENTS TO THIS ROUTINE ARE INPUT ONLY
C
C  ALL LABELS ARE OF ELASTIC LENGTH; HOWEVER, FOR SOME NONBLANK LENGTH
C  THE LABELS WILL START TO NOT FIT IN THE GENERATED TEKTRONIX DISPLAYS
C  WITHOUT LINE WRAPPING
C
C---------------------------------
C  LOCAL
C
      CHARACTER*25 ZLPROC
C
      CHARACTER*132 MNLAB(3)
C
      CHARACTER*12 ZENCOD
C
      integer LUNTRM,LNOUT, IMAIN,ISUB,IFUN, IRET, IMIN
      integer isel,  iert,  i
      real    YFIX, XFIX, FDCOD, DYMIN, DY, dxmin, dx  
C
C---------------------------------
C  EXECUTABLE CODE -- SET UP PROCESSING LABEL
C
      ZLPROC=' '
      IF(IPROC.EQ.1) THEN
        ZLPROC(2:)='(AVERAGED)'
      ELSE IF(IPROC.EQ.2) THEN
        ZLPROC(2:)='(SMOOTHED)'
      ELSE IF(IPROC.EQ.3) THEN
        ZLPROC(2:)='(AVERAGED, SMOOTHED)'
      ELSE IF(IPROC.EQ.4) THEN
        ZLPROC(2:)='(PROCESSED)'
      ENDIF
C
C  TTY LUN
C
      LUNTRM=LNOUT(0)
C
C-------------------
#ifdef __DEBUG
      write(6,*) ' ===>(trgraf debug)'
      write(6,*) ' nx= ',nx,' ny= ',ny,' nz1= ',nz1
      write(6,*) ' x(1)=',x(1),' x(nx)=',x(nx)
      write(6,*) ' y(1)=',y(1),' y(ny)=',y(ny)
      write(6,*) ' z(1,1)=',z(1,1),' z(nx,ny)=',z(nx,ny)
      write(6,*) ' (end trgraf debug)'
#endif
C
C  USER OPTION MENU
C
 10   CONTINUE
C
      CALL GRF3OP(ZLABEL,ZTITLE,
     >    XLAB,ZLAB,' ',YLAB,' ',IMAIN,ISUB,1,IFUN)
C
C  BRANCH
C
      GO TO (100,200,300,400,500,600,700,800) IMAIN
C
C-------------------
C
 100  CONTINUE
C
C  3D ISOMETRIC PLOT
C
      CALL TGRF3D(X,Z,Y,NX,NY,NZ1,
     >    XLAB,YLAB,ZLAB,
     >    XUN,YUN,ZUN,
     >    ZTITLE,IPROC,
     >    ZLABEL,0,' ',
     >    NPAGEC,' ',' ',0.0,IRET)
C
      IF(IRET.EQ.1) GO TO 400
C
      GO TO 10
C
C-------------------
C
C  2D GRAPH OF VARIABLE VS. 1ST INDEPENDANT VARIABLE, 2ND IN-
C  DEPENDANT VARIABLE HELD CONSTANT TO USER SPECIFIED
C  VALUE.
C
 200  CONTINUE
C
C  GET USER SPECIFIED Y VALUE
C
 1200 FORMAT('  ...PLOT VS ',A/'  AT FIXED ',A,', ',A)
C
      IF(LXOUT(0)) WRITE(LUNTRM,1200) XLAB,YLAB,YUN
      CALL UREAD(' GRF3SG:  ENTER FIXED PARAMETER:$$')
      IF(LCHAR('Q')) GOTO 10
C
      YFIX=FDCOD(IERT)
      IF(IERT.NE.0) GO TO 200
C
      DYMIN=ABS(YFIX-Y(1))
      IMIN=1
C
      DO 210 I=1,NY
        DY=ABS(YFIX-Y(I))
        IF(DY.GT.DYMIN) GO TO 210
        IMIN=I
        DYMIN=DY
 210  CONTINUE
C
C  SPECIFY FIXED PT DATA IN PLOT LABEL
C
      WRITE(ZENCOD,'(1PE12.5)') Y(IMIN)
C
C  MAKE GRAPH  (GRFAH0 WILL SET SCALE, ETC.)
C
      CALL GRAFX1(X,Z(1,IMIN),NX,XUN,ZUN,
     >    trim(ZLABEL)//' '//trim(ZTITLE),
     >    'FIXED: '//trim(YLAB)//' = '//trim(ZENCOD)//' '//trim(YUN),
     >    trim(ZLAB)//' '//trim(ZLPROC)//' VS '//trim(XLAB))
C
      GO TO 10
C
C------------------
C
C  2D GRAPH OF DEPENDANT VARIABLE VS. 2ND INDEPENDANT VARIABLE
C  WITH USER SPECIFYING FIXED VALUE FOR 1ST INDEPENDANT VARIABLE.
C
 300  CONTINUE
C
C   GET USER SPECIFIED X VALUE
C
      IF(LXOUT(0)) WRITE(LUNTRM,1200) YLAB,XLAB,XUN
      CALL UREAD(' GRF3SG:  ENTER FIXED PARAMETER:$$')
      IF(LCHAR('Q')) GOTO 10
C
      XFIX=FDCOD(IERT)
      IF(IERT.NE.0) GO TO 300
C
      DXMIN=ABS(X(1)-XFIX)
      IMIN=1
C
      DO 310 I=1,NX
        DX=ABS(X(I)-XFIX)
        IF(DX.GT.DXMIN) GO TO 310
        DXMIN=DX
        IMIN=I
 310  CONTINUE
C
C  WILL PLOT COLUMN OF Z POINTS CLOSEST TO SPECIFIED X
C  VALUE.  USE WK ARRAY: GRFADH REQUIRES POINTS BEING GRAPHED
C  TO BE IN CONTIGUOUS CORE SPACE
C
      DO 315 I=1,NY
        WK(I)=Z(IMIN,I)
 315  CONTINUE
C
C  SPECIFY FIXED PT DATA IN PLOT LABEL
C
      WRITE(ZENCOD,'(1PE12.5)') X(IMIN)
C
C  MAKE GRAPH  (GRFAH0 WILL SET SCALE, ETC.)
C
      CALL GRAFX1(Y,WK,NY,YUN,ZUN,
     >    trim(ZLABEL)//' '//trim(ZTITLE),
     >    'FIXED: '//trim(XLAB)//' = '//trim(ZENCOD)//' '//trim(XUN),
     >    trim(ZLAB)//' '//trim(ZLPROC)//' VS '//trim(YLAB))
C
C
      GO TO 10
C
C------------------------------
C  ** EXIT
 400  CONTINUE
C
      RETURN
C
C------------------------------
C  ** CONTOUR PLOTTING
C
 500  CONTINUE
C
      IF(ISUB.EQ.0) THEN
        CALL CONCTR(X,Z,Y,NX,NZ1,NY,
     >           XLAB,ZLAB,YLAB,XUN,ZUN,YUN,ZLABEL,
     >           0,IPROC,NPAGEC)
      ELSE
        CALL CONCTS(X,Z,Y,NX,NZ1,NY,
     >           XLAB,ZLAB,YLAB,XUN,ZUN,YUN,ZLABEL,
     >           0,IPROC,NPAGEC,1,1,1)
      ENDIF
C
      GO TO 10
C
C------------------------------
C  CHANGE DEFAULT PLOT TYPE
C
 600  CONTINUE
      CALL GAXSET(ISEL,1)
      GO TO 10
C
C------------------------------
C  CHANGE SCALING DEFAULTS
C
 700  CALL GSCDEF
      GO TO 10
C
C------------------------------
C
C  SLICE MULTIPLOTS--
C
 800  CONTINUE
C
      MNLAB(1)=ZLABEL//' '//ZLPROC
C
      MNLAB(2)=ZTITLE
C
      MNLAB(3)=' '
C
C  USER CHOOSE X AXIS, SET OF FIXED Y, AND MAKE GRAPH
      CALL G3MSEL(Z,NZ1,X,NX,Y,NY,WK,
     >     XLAB,XUN,YLAB,YUN,ZLAB,ZUN,MNLAB)
C
      GO TO 10
C
      	END
