PRO  STP,DATA,XSIZE=XSIZE,YSIZE=YSIZE,START=START,INFO_ARRAY=INFO_ARRAY,$
		NOSCALE=NOSCALE,SUBSCRIPT=SUBSCRIPT,MOVIE=MOVIE,color=color
;+							(2-dec-91)
;  NAME:
;	STEPPER
;  PURPOSE:
;	Step through individual images a single frame at a time.
;  INPUTS:
;	DATA = Three-dimensional array
;  OPTIONAL INPUT PARAMETERS:
;	XSIZE,YSIZE = If present, the routine will use rebin to using the
;			the /sample option.  If only XSIZE is present, YSIZE
;			will be set equal to XSIZE.
;	START	    = Index of starting image
;	INFO_ARRAY  = String array containing descriptive text
;	NOSCALE	    = If set, will turn off tvscale
;	SUBSCRIPT   = Subset of array is displayed.
;
;  VERSION:
;	V1.1    24-sep-91
;  HISTORY:
;	Written 20-sep-91, JRL and LWA
;	Updated 21-sep-91, JRL:  Added xloadct and zoom options.
;	Updated 24-sep-91, JRL:  Added SUBSCRIPT and MOVIE options.
;	Updated  2-dec-91, JRL:  Break the text string into two lines if
;				 info_array is > 44
;	Updated 24-apr-92, LWA:  Break test string a bit differently in
;				 order to put more info on 256x256 window
;-
on_error,2		; Return to caller
ans= ''

;  If no arguments, show the caller the sequence:

if n_params() eq 0 then begin
  print,'STEPPER,DATA [,XSIZE=XSIZE,YSIZE=YSIZE,START=START,INFO=INFO_ARRAY, $'
  print,'               SUBSCRIPT=SUBSCRIPT,/NOSCALE,/MOVIE]'
  return
endif

if n_elements(color) eq 0 then color=255

ss = size(DATA)
if ss(0) ne 3 then begin
   help,DATA 
   print,'Input array must be 3-dimensional
   return
endif

nx = ss(1) & ny = ss(2) & nimg = ss(3)
if n_elements(subscript) eq 0 then subscript = indgen(nimg)
n_sel = n_elements(subscript)

;  See if we need to rebing or not

if n_elements(xsize) eq 0 then rebinnn = 0 else begin
  rebinnn = 1				; Must rebin
  if n_elements(ysize) eq 0 then ysize = xsize/nx*ny
  print,'Will rebin to XSIZE=',strtrim(string(xsize),2),  $
		    ', YSIZE=',strtrim(string(ysize),2)
endelse

;  See if we should turn off the tvscl option:
if keyword_set(noscale) then nosc = 0 else nosc = 2

DISP = rebinnn + nosc

;  Set up info_array if it does not exist already:

if n_elements(info_array) eq 0 then $
	info_array = strtrim(string(indgen(nimg))+' :',2)

;  Print informational message:

print,'There are ',strtrim(string(nimg),2),' images in the array'
print,'There are ',strtrim(string(n_sel),2),' images selected'
print,'Enter q to quit; b to go back; s to select new start index;'
print,'      x for xloadct; z for zoom; m for movie'

if n_elements(start) eq 0 then stt=0 else stt=start	; Starting image
stt = min(abs(stt-subscript)) & stt=!c & !c=0		; Get closest index
i = stt
if keyword_set(movie) then begin
  movie_resp = 1 
  print,'Type anything to abort movie mode'
endif else movie_resp = 0 
while i lt n_sel do begin

	j = subscript(i)				; Get selected images
        case DISP of 
	  0: tv,data(*,*,j)				; rebinn=0, noscale=0
	  1: tv,rebin(data(*,*,j),xsize,ysize,/sample)	; rebinn=1, noscale=0
	  2: tvscl,data(*,*,j)				; rebinn=0, noscale=2
	  3: tvscl,rebin(data(*,*,j),xsize,ysize,/sample);rebinn=1, noscale=2
	endcase
	if strlen(info_array(j)) le 44 then begin
 	  xyouts,0,10,info_array(j),charsize = 1.26,/device,color=color
	endif else begin
	  str0 = strmid(info_array(j),0,38)
	  str1 = strmid(info_array(j),38,strlen(info_array(j)))
	  xyouts, 10,10,str1,charsize = 1.26,/device,color=color
	  xyouts, 0,23,str0,charsize = 1.26,/device,color=color
	endelse

	if movie_resp eq 1 then begin
	  ans = get_kbrd(0)			; don't wait for response
	  if ans ne '' then movie_resp = 0
	endif else ans = get_kbrd(1)			; Wait for response
	ans = strlowcase(ans)				; Convert to lower case

	if ans eq 'b' then begin			; Go back
	  i = i-1 & if i lt 0 then i=n_sel-1
	endif else if ans eq 'q' then i=n_sel $
	else if ans eq 's' then begin			; New start index
	  print,'* Enter the requested start image number',format='($,a)'
	  read,i
	  i=min(abs(i-subscript)) & i=!c & !c=0
	endif else if ans eq 'x' then xloadct $
	else if ans eq 'z' then zoom $
	else if ans eq 'm' then begin			; enter movie mode
	   print,'Type anything to abort movie mode'
	   movie_resp = 1
	endif else begin			; Advance by one (default)
	  i = i + 1
	  if i ge n_sel then i = 0
	endelse
endwhile	 

return
end
