      SUBROUTINE SCALE(END,FIRST,D2T,SCMAX,Y,NPT)
C
C   CHECK FOR NEGATIVE DATA POINTS, OFFSET ENTIRE DATA SET BY THE MOST 
C     NEGATIVE VALUE (FOR SPECPLOT), AND RESCALE PATTERN
C                                               
      DIMENSION Y(8001)
      YMIN=0.
      DO 200 I=1,NPT
      IF(Y(I).LT.YMIN)YMIN=Y(I)
200   CONTINUE
      YMIN=-YMIN
      DO 250 I=1,NPT
      Y(I)=Y(I)+YMIN
250   CONTINUE
      XX=Y(1)                                   
      DO 460  J=2,4001                                 
      IF (XX.LE.Y(J)) XX=Y(J)                              
  460 CONTINUE                                              
      SCAL=SCMAX/XX                               
      DO 500  J=1,4001                             
  500 Y(J)=Y(J)*SCAL                          
      RETURN
      END
