PRO  STEPPER,DATA,XSIZE=XSIZE,YSIZE=YSIZE,START=START,INFO_ARRAY=INFO_ARRAY,$
	     NOSCALE=NOSCALE,SUBSCRIPT=SUBSCRIPT,MOVIE=MOVIE,INTERP=INTERP
;+							(29-apr-92)
;  NAME:
;	STEPPER
;  PURPOSE:
;	Step through individual images a single frame at a time.
;  CALLING SEQUENCE:
;  STEPPER,DATA [,XSIZE=XSIZE,YSIZE=YSIZE,START=START,INFO_ARRAY=INFO_ARRAY,$
;	     /NOSCALE,SUBSCRIPT=SUBSCRIPT,/MOVIE,/INTERP]
;  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.
;	MOVIE	    = If present and =1, will initiate movie mode when called
; 	INTERP      = Controls how REBIN is done.  If present and set to 1,
;		      /INTERP ==> REBIN(A,xsize,ysize)
;		      else    ==> REBIN(A,xsize,ysize,/sample)
;
;  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 15-dec-91, slf;  Replaced get_kbrd calls with get_kbrd2
;				 to work around SGI anomoly
;	Updated 16-apr-92, slf;  To work with single image
;	Updated 28-apr-92, JRL:  Break text if strlen(info) > 38 
;	Updated 29-apr-92, JRL:  Added the INTERP keyword
;-
on_error,2		; Return to caller
ans= ''

;  If no arguments, show the caller the sequence:

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

ss = size(DATA)

; slf 26-apr-92, Allow single image in addition to data cube
case ss(0) of
   2: begin
         nx=ss(1) & ny=ss(2) & nimg=1
      endcase    
   3: begin
         nx = ss(1) & ny = ss(2) & nimg = ss(3)
      endcase
   else: begin & message,'Image or Image cube required' & return & endelse
endcase

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)
  if keyword_set(interp) then sample=0 else sample=1	; if interp=1, sample=0
  print,'sample=',sample			;***
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 						; rebinn,noscale
	  0: tv,data(*,*,j)					;    0  ,   0
	  1: tv,rebin(data(*,*,j),xsize,ysize,sample=sample)	;    1  ,   0
	  2: tvscl,data(*,*,j)					;    0  ,   2
	  3: tvscl,rebin(data(*,*,j),xsize,ysize,sample=sample)	;    1  ,   2
	endcase
	break_point = 38	; Break point
	if strlen(info_array(j)) le break_point then begin
 	  xyouts,0,10,info_array(j),charsize = 1.26,/device
	endif else begin
	  str0 = strmid(info_array(j),0,break_point)
	  str1 = strmid(info_array(j),break_point,strlen(info_array(j)))
	  xyouts,10,10,str1,charsize = 1.26,/device
	  xyouts, 0,23,str0,charsize = 1.26,/device
	endelse

; slf, December 16 - changed references from get_kbrd to get_kbrd2
; since SGI behaves diffently (solicits bogus 255 from XClients)
	if movie_resp eq 1 then begin
	  ans = get_kbrd2(0)			; don't wait for response
	  if ans ne '' then movie_resp = 0
	endif else begin
	ans = get_kbrd2(1)			; Wait for response
	endelse
	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

