      SUBROUTINE CONTUR (XXX, M, N, INCTRL, IOCTRL, IZ)
      IMPLICIT NONE
C
C ***      CONTOUR PLOTTING
C
      INTEGER M, N, INCTRL, IOCTRL
      REAL XXX(M,N)
C
      INCLUDE MATLAB$KOM:SIZEPARMS.INC
C
      CHARACTER*1 IZ(VARSIZE)
C
      INCLUDE MATLAB$KOM:IOP.KOM
      INCLUDE MATLAB$KOM:MATPLT.KOM
      INCLUDE MATLAB$KOM:PLTCP.KOM
C
      INTEGER CHOICE, I, LABSIZ, IERR, MN
      REAL XMAX, YMAX, ZMIN, ZMAX
      CHARACTER*8 ICURS
C
C ***      FUNCTIONS
      REAL GSXLCM, GSYLCM
C
      DATA ICURS / 'Contor>>' /
C
C
C ***      FIGURE OUT WHO CALLED US AND
C ***        IF SO INDICATED JUMP DIRECTLY TO THE PLOT
      IF (INCTRL.NE.0) GO TO 900
C
C ***      SET UP THE DEFAULTS
      DO 25 I = 1, 80
        XLABCP(I) = Z'20'
        YLABCP(I) = Z'20'
        LABCP(I) = Z'20'
25    CONTINUE
      LABECP = 0
      XSTCP = 0
      YSTCP = 0
      XFRCCP = 100
      YFRCCP = 100
      FGRPCP = 1
      IOCTRL = 0
      X1CP = 0
      XMXCP = M
      Y1CP = 0
      YMXCP = N
      IOPTCP = 0
      IOP2CP = 0
      ICNNCP = 20
      XMAX = GSXLCM ()
      YMAX = GSYLCM ()
      MN = M*N
      CALL MINMAX (XXX, MN, ZMIN, ZMAX)
      DO 55 I = 1, 20
        CNLCP(I) = ZMIN + (ZMAX-ZMIN)*(FLOAT(I)-1)/20
55    CONTINUE
C
C ***      DETERMINE THE CHOICES
100   CONTINUE
      CALL CHKEND
      CALL DSBLLN (2)
      CALL DSSTRN (' PLEASE CHOOSE AN OPTION', 1)
      CALL DSSTRN (' [1]  CHOOSE PLOT LABELS', 1)
      CALL DSSTRN (' [2]  CHOOSE PLOT VALUES', 1)
      CALL DSSTRN (' [3]  CHOOSE NUMBER OF CONTOURS', 1)
      CALL DSSTRN (' [4]  CHOOSE CONTOUR LEVELS', 1)
      CALL DSSTRN (' [5]  SET THE BACKGROUND COLOR', 1)
      CALL DSSTRN (' [6]  CHOOSE PLOT COLOR', 1)
      CALL DSSTRN (' [7]  CHOOSE PLOT SIZE', 1)
      CALL DSSTRN (' [8]  DO THE PLOT', 1)
      CALL DSSTRN (' [9]  END THE CURRENT PLOT', 1)
      CALL DSSTRN (' [10] EXIT CONTOUR PLOTS', 1)
      CALL DSCURS (ICURS)
C
      CALL VALGET (0, CHOICE, 'I')
      GO TO (200, 300, 400, 500, 600, 700, 800, 900, 899, 990), CHOICE
      CALL MENUER (10)
      GO TO 100
C
C ***      SELECT THE LABELS
200   CONTINUE
      CALL CHKEND
      CALL DSSTRN (' ENTER THE X AXIS LABEL', 1)
      CALL DSCURS (ICURS)
      CALL GETLAB (XLABCP)
      CALL DSSTRN (' ENTER THE Y AXIS LABEL', 1)
      CALL DSCURS (ICURS)
      CALL GETLAB (YLABCP)
      CALL DSSTRN (' ENTER THE PLOT LABEL', 1)
      CALL DSCURS (ICURS)
      CALL GETLAB (LABCP)
      CALL DSSTRN (' ENTER THE SIZE OF THE LABELS (CM)', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (LABSIZ, 0, 'F')
      IF (LABSIZ.NE.0) LABECP = LABSIZ
      GO TO 100
C
C ***      SELECT THE DATA
300   CONTINUE
      CALL CHKEND
      CALL DSSTRN (' ENTER THE MINIMUM VALUE OF X', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (X1CP, 0, 'F')
      CALL DSSTRN (' ENTER THE MAXIMUM VALUE OF X', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (XMXCP, 0, 'F')
      CALL DSSTRN (' ENTER THE MINIMUM VALUE OF Y', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (Y1CP, 0, 'F')
      CALL DSSTRN (' ENTER THE MAXIMUM VALUE OF Y', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (YMXCP, 0, 'F')
      GO TO 100
C
C ***      DEFINE THE NUMBER OF CONTOURS
400   CONTINUE
      CALL CHKEND
      CALL DSSTRN (' ENTER THE NUMBER OF CONTOURS TO BE MAPPED', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, ICNNCP, 'I')
      IF (ICNNCP.GT.20) ICNNCP = 20
      DO 455 I = 1, ICNNCP
        CNLCP(I) = ZMIN + (ZMAX-ZMIN)*(FLOAT(I)-1)/20
455   CONTINUE
      GO TO 100
C
C ***      CHOOSE THE CONTOUR LEVELS
500   CONTINUE
      CALL CHKEND
      GO TO 100
C
C ***      SET THE BACKGROUND COLOR
600   CONTINUE
      CALL CHKEND
      CALL CHBACK (ICURS)
      GO TO 100
C
C ***      SELECT THE PLOT COLOR
700   CONTINUE
      CALL CHKEND
      CALL SETFG (FGRPCP, ICURS)
      GO TO 100
C
C ***      SELECT THE PLOT SIZE
800   CONTINUE
      CALL CHKEND
      CALL MAKSIZ (ICURS, XSTCP, XFRCCP, YSTCP, YFRCCP)
      XSTCP = XSTCP*100.
      YSTCP = YSTCP*100.
      XFRCCP = XFRCCP*100.+XSTCP
      YFRCCP = YFRCCP*100.+YSTCP
      GO TO 100
C
C ***      END THE PLOT
899   IF (PLTST) THEN
        PLTST = .FALSE.
        CALL PLTFIN
      ENDIF
      GO TO 100
C
C ***      DO THE PLOT
900   CONTINUE
      CALL CHKEND
C
C ***      SAVE THE PLOT SETTINGS, UNLESS WE ARE WORKING FROM A SAVED FILE
      IF (INCTRL.EQ.0) CALL SAVPLT (4)
      IF  (.NOT.PLTST) THEN
        PLTST = .TRUE.
        CALL BGNPLT
      ENDIF
      IF (SETBG) THEN
        SETBG = .FALSE.
        CALL SETBAK (BGRP)
      ENDIF
      CALL GSCOLR (FGRPCP, IERR)
      CALL MAPSIZ (XSTCP, XFRCCP, YSTCP, YFRCCP, LABECP)
      CALL MAPIT (X1CP, XMXCP, Y1CP, YMXCP, XLABCP, YLABCP, LABCP,
     .            IOPTCP)
      CALL CONTOR (XXX, M, IZ, M, N, X1CP, XMXCP, Y1CP, YMXCP,
     .             ICNNCP, CNLCP)
      IF (INCTRL.EQ.0) GO TO 100
C
990   CONTINUE
      RETURN
      END
