	SUBROUTINE RESCALE(ifile,status)
	INTEGER ifile,status
C   Rescales a data file
C   
	include 'cmpr.common'
	include '[-.shared]flabel.common'

	INTEGER CLI$GET_VALUE,CLI$PRESENT
	EXTERNAL CLI$_PRESENT,CLI$_DEFAULTED,CLI$_ABSENT,CLI$_NEGATED
	LOGICAL GET_NUMBER,flag,GET_FNUMBER

	CHARACTER*1	IANS

	REAL XOFF,XM,YOFF,YM
	LOGICAL XoffFL,XmultFL,YoffFL,YmultFL

	XoffFL = .false.	! true if /XOFF specified
	XmultFL = .false.	! true if /XMULT specified
	YoffFL = .false.	! true if /YOFF specified
	YmultFL = .false.	! true if /YMULT specified

C assume failure
	STATUS = .false.
	
C XOFF and XMULT qualifier
	IF (CLI$PRESENT('XOFFSET')) THEN
	  FLAG = GET_FNUMBER('XOFFSET',XOFF)
	  IF (.not. FLAG) XoffFL = .true.
	ENDIF
	IF (CLI$PRESENT('XMULT')) THEN
	  FLAG = GET_FNUMBER('XMULT',Xm)
	  IF (.not. FLAG) XmultFL = .true.
	ENDIF

C YOFF and YMULT qualifier
	IF (CLI$PRESENT('YOFFSET')) THEN
	  FLAG = GET_FNUMBER('YOFFSET',YOFF)
	  IF (.not. FLAG) YoffFL = .true.
	ENDIF
	IF (CLI$PRESENT('YMULT')) THEN
	  FLAG = GET_FNUMBER('YMULT',Ym)
	  IF (.not. FLAG) YmultFL = .true.
	ENDIF

C get x and y minima
	ymin = B(1,IFILE)
	ymax = B(1,IFILE)
	xmin = BX(1,IFILE)
	xmax = BX(1,IFILE)
	DO I=2,NPOINT(IFILE)
	  ymin = min(ymin,B(I,IFILE))
	  ymax = max(ymax,B(I,IFILE))
	  xmin = min(xmin,BX(I,IFILE))
	  xmax = max(xmax,BX(I,IFILE))
	ENDDO

	write (lo,'(A,g12.5,a,g12.5,1x,a)') ' X axis range: ',xmin,
	1	' to ',xmax,XLABL(FXTYP(IFILE))
	write (lo,'(A,g12.5,a,g12.5,1x,a)') ' Y axis range: ',ymin,
	1	' to ',ymax,YLABL(FYTYP(IFILE))

	IF (YMAX .EQ. YMIN .or. XMAX .EQ. XMIN) THEN
	  WRITE (lo,'(A)') ' Illegal range of data'
	  goto 999
	ENDIF

	IF (.not. (XoffFL .or. XmultFL .or. YoffFL .or. YmultFL)) THEN
	  XOFF = 0.0
	  WRITE (lo,'(/a,g10.3,a)') 
	1	'$Enter an offset to be added to the X-values [default=',
	1	XOFF,']: '
	  read (li,'(Q,F10.0)') I,tmp
	  IF (I .gt. 0) XOFF = tmp

	  Xm = 1.0
	  WRITE (lo,'(/a,g10.3,a)') 
	1	'$Enter a multiplier for the X-values [default=',
	1	Xm,']: '
	  read (li,'(Q,F10.0)') I,tmp
	  IF (I .gt. 0)  Xm = tmp

	  YOFF = 0.0
	  WRITE (lo,'(/a,g10.3,a)') 
	1	'$Enter an offset to be added to the Y-values [default=',
	1	YOFF,']: '
	  read (li,'(Q,F10.0)') I,tmp
	  IF (I .gt. 0)  YOFF = tmp

	  Ym = 1.0
	  WRITE (lo,'(/a,g10.3,a)') 
	1	'$Enter a multiplier for the Y-values [default=',
	1	Ym,']: '
	  read (li,'(Q,F10.0)') I,tmp
	  IF (I .gt. 0) Ym = tmp
	ENDIF	

C any changes?
	IF (XM .eq. 1. .and. XOFF .eq. 0. .and. 
	1	YM .eq. 1 .and. YOFF .eq. 0) goto 999

	IF (XM .ne. 1. .or. XOFF .ne. 0.) THEN
	  write (lo,'(/A,g12.5,a,g12.5,a)') ' X(new) = (X(old) + ',
	1	xoff,' ) * ',xm
	  write (lo,'(A,g12.5,a,g12.5)') ' Old X axis range: ',xmin,
	1	' to',xmax
	  write (lo,'(A,g12.5,a,g12.5)') ' New X axis range: ',
	1	xm*(xmin+xoff),' to',xm*(xmax+xoff)
	  IF (.not. DEFAULT) THEN
	    write (lo,'(A)') '$Is this acceptable? ([Y]/N): '
	    read (li,'(A)') IANS
	    IF (ians .eq. 'N' .or. ians .eq. 'n') goto 3
	  ENDIF
	  START(IFILE) = XM*(START(IFILE) + XOFF)
	  DELTA(IFILE) = XM*(DELTA(IFILE))
	  FINISH(IFILE) = XM*(FINISH(IFILE) + XOFF)
	  DO I=1,NPOINT(IFILE)
	    BX(I,IFILE) = XM * (BX(I,IFILE) + XOFF)
	  ENDDO
	  DO J=1,NPKS(IFILE)
	    TT(J,IFILE) = XM*(TT(J,IFILE) + XOFF)
	  ENDDO
	  DO J=1,NBKGP(nfil)
	    xbkg(J,IFILE) = XM*(xbkg(J,IFILE) + XOFF)
	  ENDDO
C change label after a multiplication operation
	  IF (XM .ne. 0) FXTYP(IFILE) = XTYP_ARB 
	ENDIF


	IF (YM .ne. 1 .or. YOFF .ne. 0) THEN
	  write (lo,'(/A,g12.5,a,g12.5,a)') ' Y(new) = (Y(old) + ',
	1	Yoff,' ) * ',Ym
	  write (lo,'(A,g12.5,a,g12.5)') ' Old Y axis range: ',Ymin,
	1	' to',Ymax
	  write (lo,'(A,g12.5,a,g12.5)') ' New Y axis range: ',
	1	Ym*(Ymin+Yoff),' to',Ym*(Ymax+Yoff)

	  IF (.not. DEFAULT) THEN
	    write (lo,'(A)') '$Is this acceptable? ([Y]/N): '
	    read (li,'(A)') IANS
	    IF (ians .eq. 'N' .or. ians .eq. 'n') goto 3
	  ENDIF
	  DO I=1,NPOINT(IFILE)
	    B(I,IFILE)  = YM * (B(I,IFILE) + YOFF)
	    BESD(I,IFILE) = YM * BESD(I,IFILE)
	  ENDDO
	  DO J=1,NPKS(IFILE)
	    PKHT(J,IFILE) = YM*(PKHT(J,IFILE) + YOFF)
	    FINTEG(J,IFILE) = YM*(FINTEG(J,IFILE) + YOFF)
	  ENDDO
	  DO J=1,NBKGP(nfil)
	    ybkg(J,IFILE) = XM*(ybkg(J,IFILE) + XOFF)
	    ybkgdel(J,IFILE) = XM*(ybkgdel(J,IFILE) + XOFF)
	  ENDDO

	  IF (YM .ne. 0) FYTYP(IFILE) = YTYP_scl 
	ENDIF

	STATUS = .true.
	RETURN
C-----------------------------------------------------------------------------
998	Type *,'*** Unable to prompt for required input ***'
999	Type *,'*** Ignoring SCALE command ***'
3	STATUS = .FALSE.
	RETURN 
	END
