      SUBROUTINE XYPLT(X,Y,N,XSCL,YSCL, ILB,NCOL,NLINE)
C
C        X AND Y ARE VECTORS TO BE PLOTTED,N ITEMS IN EACH( NOTE-VALUES
C             OF X AND Y RETURNED TO MAIN PROGRAM ARE ARRANGED SO
C             THAT THE Y'S ARE IN DESCENDING ORDER) .
C        XSCL AND YSCL ARE X AND Y SCALE VALUES ( IN TERMS OF UNITS PER
C             COLUMN OR LINE ) , IF EITHER OR BOTH ARE SET TO ZERO, THE
C             SCALE FACTOR IS COMPUTED BY THE SUBPROGRAM.
C        ILB IS A VECTOR OF N LENGTH CONTAINING THE CHARACTERS TO BE
C             PLOTTED AT A PARTICULAR (X,Y) ( EG.READ UNDER A1 FMT ).
C        NCOL IS NUMBER OF COLUMNS FOR XY PLOT, MAXIMUN IS 100.
C        NLINE IS NUMBER OF LINES FOR XY SURFACE, IF SET EQUAL TO 0 THEN
C             NLINE IS SET TO 50, IF GREATER THAN ZERO, THE PLOT SPANS
C             NLINE NUMBER OF LINES AND DRAWS A BOX AROUND THE PLOT,
C             AND IF LESS THAN ZERO THE BOX IS DELETED ( ALL ELSE THE
C             SAME AS BEFORE) .
C
      DIMENSION X(1),Y(1),LINE(102),ILB(1),XPR(10),IAA(2),ISCL(2)
      DATA NO,IBAR,IPLS,IEYE,ISTAR,IBLK/3,24672,20046,-14016,23644,
     1 16448/
C
C        INITIALIZE VALUES.
C
      IAA(1)=IBLK
      IZ=2
C
C        IF NLINE=0, SET NLINE=50 ELSE IF NLINE<0, DELETE TOP AND RIGHT
C
      IF(NLINE)23,20,25
   20 NLINE=50
   25 DO 5 I=1,NCOL
      LINE(I)=IPLS
    5 CONTINUE
      DO 10 I= 1,NCOL,10
      LINE(I)=IEYE
   10 CONTINUE
      WRITE(NO,15)(LINE(I),I=1,NCOL)
   15 FORMAT(15X,102A1)
      GO TO 24
   23 NLINE=-1*NLINE
      IZ=1
   24 CONTINUE
C
C     FIND MIN AND MAX X VALUE.
C
      XMX=X(N)
      DO 26 I=1,N
      IF(XMX-X(I))27,26,26
   27 XMX=X(I)
   26 CONTINUE
      XMN=X(1)
      DO 28 I=1,N
      IF(X(I)-XMN)29,28,28
   29 XMN=X(I)
   28 CONTINUE
C
C        XRNG=X-RANGE, XB=MINIMUM X-VALUE.
C
      XRNG=XMX-XMN
      XB=XMN
C
C     RANK Y VALUES, HIGH-->LOW, MAINTAIN ORDER OF X AND ILB VECTORS.
C
      NM=N-1
      DO 53 I=1,NM
      IQ=1
      J=N-I
      DO 30 K=1,J
      KK=K+1
      IF(Y(K)-Y(KK))35,30,30
   35 YMX=Y(KK)
      Y(KK)=Y(K)
      Y(K)=YMX
      XMX=X(KK)
      X(KK)=X(K)
      X(K)=XMX
      LBMX=ILB(KK)
      ILB(KK)=ILB(K)
      ILB(K)=LBMX
      IQ=2
   30 CONTINUE
      GO TO (52,53),IQ
   53 CONTINUE
C
C     CALCULATE RANGE OF Y VALUES
C        IF EITHER YSCL OR XSCL IS GIVEN, ADJUST XB AND/OR YB,YU FOR
C             THE EXTENDED RANGE.
C
   52 YRNG=Y(1)-Y(N)
      YB=Y(1)
      YU=Y(N)
C        FIND X AND Y SCALE.
C
      IF(XSCL)40,40,41
   40 XSCL=XRNG/(NCOL-1)
      GO TO 43
   41 XB=XB-ABS(XSCL*NCOL-XRNG)/2.0
   43 IF(YSCL)45,45,50
   45 YSCL=YRNG/(NLINE-1)
      GO TO 46
   50 YDIF=    YSCL*(NLINE-1)-YRNG
      YU=YU-YDIF
   46 ISCL(1)=ALOG(XMX)*.4329
      ISCL(2)=ALOG( YB)*.4329
      DO 37 J=1,2
      IF(ISCL(J)-1)32,33,33
   32 ISCL(J)=-1*ISCL(J)+1
      GO TO 37
   33 IF(ISCL(J)-6)36,34,34
   34 ISCL(J)=ISCL(J)-7
      GO TO 37
   36 ISCL(J)=0
   37 CONTINUE
C
      II=1
C
C        BEGIN LINE PRINT LOOP.
C
      DO 135 IL=1,NLINE
      IA=IBAR
      DO 55 I=1,NCOL
      LINE(I)=IBLK
   55 CONTINUE
      YLN=YB-YSCL*(IL-1)
      IF(II-N)65,65,85
   65 IF(IL-1)60,99,60
   60 IF(IL-NLINE)70,115,70
   70 DO 75 I=II,N
      JX=((X(I)-XB)/XSCL)+1
      IF(YLN-Y(I))80,80,85
   80 LINE(JX)=ILB(I)
      IA=IPLS
      II=II+1
   75 CONTINUE
   85 IAA(2)=IA
C
C        WRITE LINE.
C
      YLN=YLN*10**ISCL(2)
      WRITE(NO,95)YLN,IA,(LINE(M),M=1,NCOL),IAA(IZ)
   95 FORMAT(' ',1X,F10.2,2X,102A1)
      GO TO 135
C
C        IF Y(I) GT. YB, THEN PRINT A STAR.
C
   99 DO 100 I=1,N
      JX=((X(I)-XB)/XSCL)+1
      IF(Y(I)-YB)100,105,110
  110 LINE(JX)=ISTAR
      IA=IPLS
      II=II+1
      GO TO 100
  105 LINE(JX)=ILB(I)
      IA=IPLS
      II=II+1
  100 CONTINUE
      GO TO 85
C
C        IF Y(I) LT. YU, THEN PRINT A STAR.
C
  115 DO 120 I=II,N
      JX=((X(I)-XB)/XSCL)+1
      IF(Y(I)-YU)130,125,125
  130 LINE(JX)=ISTAR
      IA=IPLS
      GO TO 120
  125 LINE(JX)=ILB(I)
      IA=IPLS
  120 CONTINUE
      GO TO 85
  135 CONTINUE
C
C        END OF LOOP.
C
      DO 140 I=1,NCOL
      LINE(I)=IPLS
  140 CONTINUE
      DO 145 I= 10,NCOL,10
      LINE(I)=IEYE
  145 CONTINUE
C
C        WRITE LOWER X-AXIS BORDER WITH X VALUES AT EVERY 10TH COLUMN.
C
      WRITE(NO,15)(LINE(I),I=1,NCOL)
      XB=XB-XSCL
      JCOL=NCOL/10
      DO 150 J=1,JCOL
      XPR(J)=(XB+XSCL*10.*J)*10.**ISCL(1)+0.005
  150 CONTINUE
      WRITE(NO,165)(XPR(I),I=1,JCOL)
  165 FORMAT(' ',16X,10F10.2/)
      WRITE(NO,170)ISCL(2),ISCL(1)
  170 FORMAT(' ',T9,I2,T39,I2/' ',T4,'Y * 10',T34,'X * 10')
      RETURN
      END
