      SUBROUTINE POLPLT (XXX, YYY, M, N, INCTRL, IOCTRL, IZ)
      IMPLICIT NONE
C
C THE POLAR PLOTTING ROUTINE
C
      INTEGER M, N, INCTRL, IOCTRL
      REAL XXX(M,N), YYY(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:PLTPP.KOM
C
      INTEGER CHOICE, ICHOICE, I, J, MN
C
      REAL X(LINES,VECSIZ), Y(LINES,VECSIZ), XPL(VECSIZ), YPL(VECSIZ)
      COMMON /AREA/ X,Y,XPL,YPL
C
      CHARACTER*8 ICURS
      CHARACTER*4 ROWTAG
C
      DATA ICURS / 'Polar >>' /
      DATA ROWTAG / ' ROW' /
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
        LABPP(I) = CHAR(0)
25    CONTINUE
      DO 10 I = 1, 10
        SMSZPP(I) = 0
        NTSMPP(I) = 0
        ISMNPP(I) = 0
        LNSLPP(I) = 1
        LINXPP(I) = 0
        LINYPP(I) = 0
        FGRPPP(I) = I+1
10    CONTINUE
      LABEPP = 0
      MODE1A = 1
      MODE1B = 0
      MODE2A = 1
      MODEPP(2) = 1
      MODEPP(3) = 0
      MODEPP(4) = 1
      MODEPP(5) = -30
      MODEPP(7) = 2
      XSTPP = 0
      YSTPP = 0
      XFRCPP = 100
      YFRCPP = 100
      BGRPPP = 1
      IOCTRL = 0
      NLINPP = 0
      MN = M*N
C
C ***      CHOOSE THE PLOT MODE
      CALL CHKEND
7     CONTINUE
      CALL DSSTRN (' PLEASE CHOOSE THE POLAR PLOT MODE:', 1)
      CALL DSSTRN (' [1] R-THETA PLOT (TYPE REAL)', 1)
      CALL DSSTRN (' [2] COMPLEX (X+IY) PLOT', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, IDEFPP, 'I')
      GO TO (4, 4), IDEFPP
      CALL MENUER (2)
      GO TO 7
C
4     CONTINUE
      MODE1A = IDEFPP
      IDEFPP = IDEFPP + 2
C
C ***      DETERMINE WHETHER TO PLOT ALONG ROWS OR COLUMNS
      CALL PLTPRP (X, Y, M, N, XXX, YYY, ICURS, TAGPP, NLINPP,
     .             LINXPP, LINYPP, NPTSPP, IDEFPP)
C
C ***      DETERMINE THE CHOICES
100   CONTINUE
      CALL CHKEND
      CALL DSBLLN (2)
      CALL DSSTRN (' PLEASE CHOOSE AN OPTION', 1)
      CALL DSSTRN (' [1]  DEFINE THE PLOT LABEL', 1)
      CALL DSSTRN (' [2]  CHOOSE PLOT AXIS TYPE', 1)
      CALL DSSTRN (' [3]  CHOOSE LINE OPTIONS', 1)
      CALL DSSTRN (' [4]  CHOOSE PLOT AXIS AND TICK MARK OPTIONS', 1)
      CALL DSSTRN (' [5]  CHOOSE 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 POLAR PLOTS', 1)
      CALL DSCURS (ICURS)
      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 DSBLLN (2)
      CALL DSSTRN (' ENTER THE PLOT LABEL', 1)
      CALL DSCURS (ICURS)
      CALL GETLAB (LABPP)
      GO TO 100
C
C ***      SELECT THE DATA
300   CONTINUE
      CALL CHKEND
      CALL DSBLLN (2)
      CALL DSSTRN (' CHOOSE THE PLOT AXIS TYPE', 1)
      CALL DSSTRN (' [1] LINEAR RADIUS PLOT', 1)
      CALL DSSTRN (' [2] LOGARITHMIC RADIUS', 1)
      CALL DSSTRN (' [3] RETURN TO MAIN MENU', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, ICHOICE, 'I')
      GO TO (330, 340, 100), ICHOICE
      CALL MENUER (3)
      GO TO 300
C
330   CONTINUE
      MODE2A = 1
      GO TO 300
C
340   CONTINUE
      MODE2A = 2
      GO TO 300
C
C ***      LINE OPTIONS
400   CONTINUE
      CALL DSSTRN (' PLEASE CHOOSE A DATA LINE OPTION', 1)
      CALL DSSTRN (' [1] CHOOSE LINE COLOR', 1)
      CALL DSSTRN (' [2] CHOOSE LINE STYLE', 1)
      CALL DSSTRN (' [3] RETURN TO POLAR PLOT MENU', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, ICHOICE, 'I')
      GO TO (420, 443, 100), ICHOICE
      CALL MENUER (3)
      GO TO 400
C
420   CONTINUE
      DO 425 I = 1, NLINPP
        CALL DSSTRN (' FOR LINE NUMBER ', 0)
        CALL DSWDI (I, 1)
        CALL SETFG (FGRPPP(I), ICURS)
425   CONTINUE
      GO TO 400
C
443   CONTINUE
      CALL CHKEND
      CALL LNOPTS (NLINPP, SMSZPP, NTSMPP, ISMNPP, LNSLPP, ICURS)
      GO TO 400
C
C ***      AXIS AND TICK MARK OPTIONS
500   CONTINUE
      CALL CHKEND
      CALL DSSTRN (' SELECT AXIS OR TICK MARK OPTIONS', 1)
      CALL DSSTRN (' [1] NO AXIS, TICK MARKS, OR RANGE RINGS', 1)
      CALL DSSTRN (' [2] DRAW AXIS ONLY', 1)
      CALL DSSTRN (' [3] DRAW TICK MARKS', 1)
      CALL DSSTRN (' [4] DRAW RANGE RINGS', 1)
      CALL DSSTRN (' [5] RETURN TO MAIN MENU', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, ICHOICE, 'I')
      GO TO (510, 520, 530, 540, 100), ICHOICE
      CALL MENUER (5)
      GO TO 500
C
510   CONTINUE
      MODE1B = 2
      GO TO 500
C
520   CONTINUE
      MODE1B = 0
      GO TO 500
C
530   CONTINUE
      CALL DSSTRN (
     .    ' ENTER THE NUMBER OF DEGREES BETWEEN EACH TICK MARK', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, ICHOICE, 'I')
      MODEPP(5) = ICHOICE
534   CONTINUE
      CALL DSSTRN (' PLEASE CHOOSE AN OPTION', 1)
      CALL DSSTRN (' [1] INWARD POINTING TICK MARKS', 1)
      CALL DSSTRN (' [2] OUTWARD POINTING TICK MARKS', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, ICHOICE, 'I')
      GO TO (537, 538), ICHOICE
      CALL MENUER (2)
      GO TO 534
C
537   CONTINUE
      IF (MODEPP(5).GT.0) MODEPP(5) = -MODEPP(5)
      GO TO 500
C
538   CONTINUE
      IF (MODEPP(5).LT.0) MODEPP(5) = -MODEPP(5)
      GO TO 500
C
540   CONTINUE
      CALL DSSTRN (
     .    ' PLEASE ENTER THE NUMBER OF RANGE RINGS TO PLOT', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, ICHOICE, 'I')
      MODEPP(3) = ICHOICE
C
543   CONTINUE
      CALL DSSTRN (' PLEASE CHOOSE A RANGE RING LINE OPTION', 1)
      CALL DSSTRN (' [1] SOLID LINE', 1)
      CALL DSSTRN (' [2] LONG DASHED LINE', 1)
      CALL DSSTRN (' [3] SHORT DASHED LINE', 1)
      CALL DSSTRN (' [4] DOT-DASH LINE', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, ICHOICE, 'I')
      GO TO (546, 546, 546, 546), ICHOICE
      CALL MENUER (4)
      GO TO 543
C
546   CONTINUE
      MODEPP(4) = ICHOICE
      GO TO 500
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 (BGRPPP, ICURS)
      GO TO 100
C
C ***      SELECT THE PLOT SIZE
800   CONTINUE
      CALL CHKEND
      CALL MAKSIZ (ICURS, XSTPP, XFRCPP, YSTPP, YFRCPP)
      XSTPP = XSTPP*100.
      YSTPP = YSTPP*100.
      XFRCPP = XFRCPP*100.+XSTPP
      YFRCPP = YFRCPP*100.+YSTPP
      GO TO 100
C
C ***      END THE PLOT
899   CONTINUE
      IF (PLTST) THEN
        PLTST = .FALSE.
        CALL PLTFIN
      ENDIF
      GO TO 100
C
C ***      DO THE PLOT
900   CONTINUE
      CALL CHKEND
C
C ***      DETERMINE WHETHER THIS IS THE FIRST PLOT.
       IF (.NOT.PLTST) THEN
         PLTST = .TRUE.
         CALL BGNPLT
       ENDIF
       IF (SETBG) THEN
         SETBG = .FALSE.
         CALL SETBAK (BGRP)
       ENDIF
C
C ***      IF THIS IS A BATCH JOB:
      IF (INCTRL.NE.0) THEN
        DO 840 J = 1, NLINPP
          IF (TAGPP .EQ. ROWTAG) THEN
            DO 810 I = 1, N
              X(J,I) = XXX(LINXPP(J),I)
810         CONTINUE
          ELSE
            DO 820 I = 1, M
              X(J,I) = XXX(I,LINXPP(J))
820         CONTINUE
          ENDIF
          IF (TAGPP .EQ. ROWTAG) THEN
            DO 830 I = 1, N
              IF (MODE1A .EQ. 1) THEN
                Y(J,I) = XXX(LINYPP(J),I)
              ELSE
                Y(J,I) = YYY(LINYPP(J),I)
              ENDIF
830         CONTINUE
          ELSE
            DO 832 I = 1, M
              IF (MODE1A .EQ. 1) THEN
                Y(J,I) = XXX(I,LINYPP(J))
              ELSE
                Y(J,I) = YYY(I,LINYPP(J))
              ENDIF
832         CONTINUE
          ENDIF
840     CONTINUE
      ENDIF
C
C ***      FIND THE MAXIMUM RADIUS
      IF (INCTRL.EQ.0) THEN
        RMAX = -1
        DO 905 I = 1, NLINPP
        DO 905 J = 1, NPTSPP
          RMAX = AMAX1(RMAX, X(I,J))
905     CONTINUE
        IF (MODE1A.EQ.2) THEN
          DO 906 I = 1, NLINPP
          DO 906 J = 1, NPTSPP
            RMAX = AMAX1(RMAX, Y(I,J))
906       CONTINUE
        ENDIF
      ENDIF
C
      DO 920 J = 1, NPTSPP
        XPL(J) = X(1,J)
        YPL(J) = Y(1,J)
920   CONTINUE
      IF (INCTRL.EQ.0) THEN
        MODEPP(8) = LNSLPP(1)
        MODEPP(7) = FGRPPP(1)
        MODEPP(6) = BGRPPP
        MODEPP(1) = MODE1A + MODE1B
        MODEPP(2) = MODE2A
        CALL SAVPLT (5)
      ENDIF
C
      CALL MAPSIZ (XSTPP, XFRCPP, YSTPP, YFRCPP, LABEPP)
      CALL POLAR (RMAX, XPL, YPL, IZ, MODEPP, NPTSPP,
     .            ISMNPP(1), SMSZPP(1), NTSMPP(1), LABPP)
      IF (NLINPP.GT.1) THEN
C        WRITE (9, 4554)
C4554    FORMAT (' TAKING MULTI LINE BRANCH')
        MODEPP(1) = MODE1A+2
        MODEPP(3) = 0
        MODEPP(4) = 0
        MODEPP(5) = 0
        MODEPP(6) = 0
        DO 950 I = 2, NLINPP
          DO 940 J = 1, NPTSPP
            XPL(J) = X(I,J)
          YPL(J) = Y(I,J)
940       CONTINUE
          MODEPP(7) = FGRPPP(I)
          MODEPP(8) = LNSLPP(I)
          CALL POLAR (RMAX, XPL, YPL, IZ, MODEPP, NPTSPP,
     .                ISMNPP(I), SMSZPP(I), NTSMPP(I), LABPP)
950     CONTINUE
      ENDIF
C
      IF (INCTRL.EQ.0) GO TO 100
C
990   CONTINUE
      RETURN
      END
