      SUBROUTINE PLTPRP (X, Y, M, N, XXX, YYY, ICURS, TAG, NLINES,
     .                  LINX, LINY, NPTS, IDEF)
      IMPLICIT NONE
C
C ***      DETERMINES THE ORDERING AND NUMBER OF LINES ON THE PLOTS
C
C IDEF FLAG:
C      = 1 INDICATES IMPLICIT X MODE (CALLED FROM XYPLT),
C      = 2 INDICATES EXPLICIT X MODE (CALLED FROM XYPLT),
C      = 3 INDICATES THAT THE PLOT IS TYPE REAL (R-THETA) (CALLED FROM POLPLT),
C      = 4 INDICATES THE PLOT IS TYPE COMPLEX (X+IY) (CALLED FROM POLPLT).
C
      INCLUDE MATLAB$KOM:SIZEPARMS.INC
C
      INTEGER M, N, NLINES, LINX(LINES), LINY(LINES), NPTS, IDEF
      REAL X(LINES,VECSIZ), Y(LINES,VECSIZ), XXX(M,N), YYY(M,N)
      CHARACTER*8 ICURS
      CHARACTER*4 TAG
C
      INCLUDE MATLAB$KOM:IOP.KOM
      INCLUDE MATLAB$KOM:MATPLT.KOM
C
      CHARACTER*1 ANS
      CHARACTER*4 ROWTAG, COLTAG
      INTEGER INDEXY, INDEXX, I
C
      DATA ROWTAG /' ROW'/, COLTAG/' COL'/
C
C
6     CONTINUE
      CALL CHKEND
      CALL DSSTRN (' PLOTTING FROM A ', 0)
      CALL DSWDI (M, 0)
      CALL DSSTRN (' ROW BY ', 0)
      CALL DSWDI (N, 0)
      CALL DSSTRN (' COLUMN ARRAY.', 1)
      CALL DSSTRN ('  SHOULD WE PLOT ALONG ROWS OR COLUMNS?', 1)
      CALL DSCURS (ICURS)
      READ (RTE, 15) ANS
15    FORMAT (A1)
      IF (WIO.NE.0) WRITE (WIO, 16) ANS
16    FORMAT (1X, A1)
      IF (ANS.NE.'R' .AND. ANS.NE.'r' .AND.
     .    ANS.NE.'C' .AND. ANS.NE.'c') THEN
        CALL DSERR ('ERROR. PLEASE ANSWER WITH ROWS OR COLUMNS')
        GO TO 6
      ENDIF
      IF (ANS.EQ.'R' .OR. ANS.EQ.'r') THEN
        TAG = ROWTAG
        NPTS = N
      ELSE
        TAG = COLTAG
        NPTS = M
      ENDIF
C
C ***      FIND OUT HOW MANY PLOTS TO PREPARE
24    CONTINUE
      CALL DSSTRN (' HOW MANY LINES WILL BE ENTERED ON THIS PLOT?', 1)
      CALL DSCURS (ICURS)
      CALL VALGET (0, NLINES, 'I')
      IF (NLINES.GT.LINES) THEN
        CALL DSERR ('ERROR. MAXIMUM LINES PER PLOT VALUE EXCEEDED.')
        GO TO 24
      ENDIF
C
C ***      ASK ABOUT EACH SET OF PLOTS
      DO 100 INDEX = 1, NLINES
        IF (IDEF.EQ.2 .OR. IDEF.EQ.3 .OR. IDEF.EQ.4) THEN
26        CONTINUE
          CALL DSSTRN (' FOR LINE NUMBER ', 0)
          CALL DSWDI (INDEX, 1)
          CALL DSSTRN ('  ENTER THE', 0)
          CALL DSSTRN (TAG, 0)
          CALL DSSTRN (' NUMBER OF THE ', 0)
          IF (IDEF.EQ.2) THEN
            CALL DSSTRN ('X COMPONENT', 1)
          ELSEIF (IDEF.EQ.3) THEN
            CALL DSSTRN ('RADIAL COMPONENT', 1)
          ELSEIF (IDEF.EQ.4) THEN
            CALL DSSTRN ('COMPLEX VARIABLE', 1)
          ENDIF
          CALL DSCURS (ICURS)
C
          CALL VALGET (0, INDEXX, 'I')
          IF (TAG.EQ.COLTAG .AND. (INDEXX.GT.N .OR. INDEXX.LT.1)) THEN
            CALL MENUER (N)
            GO TO 26
          ELSEIF (TAG.EQ.ROWTAG .AND.
     .            (INDEXX.GT.M .OR. INDEXX.LT.1)) THEN
            CALL MENUER (M)
            GO TO 26
          ENDIF
          LINX(INDEX) = INDEXX
          IF (TAG.EQ.ROWTAG) THEN
            DO 50 I = 1, N
              X(INDEX,I) = XXX(INDEXX,I)
50          CONTINUE
          ELSE
            DO 52 I = 1, M
              X(INDEX,I) = XXX(I,INDEXX)
52          CONTINUE
          ENDIF
        ELSE
          LINX(INDEX) = 0
          IF (TAG.EQ.ROWTAG) THEN
            DO 53 I = 1, N
              X(INDEX,I) = FLOAT(I)
53          CONTINUE
          ELSE
            DO 54 I = 1, M
              X(INDEX,I) = FLOAT(I)
54          CONTINUE
          ENDIF
        ENDIF
        IF (IDEF.EQ.1 .OR. IDEF.EQ.2 .OR. IDEF.EQ.3) THEN
56        CONTINUE
          CALL DSSTRN (' FOR LINE NUMBER ', 0)
          CALL DSWDI (INDEX, 1)
          CALL DSSTRN ('  ENTER THE', 0)
          CALL DSSTRN (TAG, 0)
          CALL DSSTRN (' NUMBER OF THE ', 0)
          IF (IDEF.EQ.1 .OR. IDEF.EQ.2) THEN
            CALL DSSTRN ('Y COMPONENT', 1)
          ELSE
            CALL DSSTRN ('ANGULAR COMPONENT', 1)
          ENDIF
          CALL DSCURS (ICURS)
          CALL VALGET (0, INDEXY, 'I')
          IF (TAG.EQ.COLTAG .AND. (INDEXY.GT.N .OR. INDEXY.LT.1)) THEN
            CALL MENUER (N)
            GO TO 56
          ELSEIF (TAG.EQ.ROWTAG .AND.
     .            (INDEXY.GT.M .OR. INDEXY.LT.1)) THEN
            CALL MENUER (M)
            GO TO 56
          ENDIF
        ENDIF
        LINY(INDEX) = INDEXY
        IF (IDEF.NE.4) THEN
          IF (TAG.EQ.ROWTAG) THEN
            DO 80 I = 1, N
              Y(INDEX,I) = XXX(INDEXY,I)
80          CONTINUE
          ELSE
            DO 82 I = 1, M
              Y(INDEX,I) = XXX(I,INDEXY)
82          CONTINUE
          ENDIF
        ELSE
          IF (TAG.EQ.ROWTAG) THEN
            DO 90 I = 1, N
              Y(INDEX,I) = YYY(INDEXY,I)
90          CONTINUE
          ELSE
            DO 92 I = 1, M
              Y(INDEX,I) = YYY(I,INDEXY)
92          CONTINUE
          ENDIF
        ENDIF
C
100   CONTINUE
C
      RETURN
      END
