; $Id: rdpix.pro,v 1.4 1998/01/15 18:43:38 scottm Exp $
;
; Copyright (c) 1989-1998, Research Systems, Inc.  All rights reserved.
;       Unauthorized reproduction prohibited.

;Pro RdpixN, Image,X0, Y0	;Read the value of the pixel under the cursor
			;Display x,y and the pixel value under the cursor
Pro RdpixN, Image,Image1,Image2,Image3,Image4,Image5,Image6,Image7
;+
; NAME:
;	RDPIX
;
; PURPOSE:
;	Interactively display the X position, Y position, and pixel value
;	of the cursor.
;
; CATEGORY:
;	Image display.
;
; CALLING SEQUENCE:
;	RDPIX, Image [, X0, Y0]
;
; INPUTS:
;	Image:	The array that represents the image being displayed.  This
;		array may be of any type.  Rather reading pixel values from
;		the display, they are taken from this parameter, avoiding
;		scaling difficulties.
;
; OPTIONAL INPUT PARAMETERS:
;	X0, Y0:	The location of the lower-left corner of the image area on
;		screen.  If these parameters are not supplied, they are
;		assumed to be zero.
;
; OUTPUTS:
;	None.
;
; COMMON BLOCKS:
;	None.
;
; SIDE EFFECTS:
;	The X, Y, and value of the pixel under the cursor are continuously
;	displayed.
;
; RESTRICTIONS:
;	None.
;
; PROCEDURE:
;	Instructions are printed and the pixel values are printed as the
;	cursor is moved over the image.
;
;	Press the left or center mouse button to create a new line of output,
;	saving the previous line.
;
;	Press the right mouse button to exit the procedure.
;
; MODIFICATION HISTORY:
;	DMS, Dec, 1987.
;	Rob Montgomery (rob@hao.ucar.edu), 9/21/92;
;		Correct indices for case of !order = 1
;
;-
;print,'Press left or center mouse button for new output line.... right mouse button to exit.'
on error,2              ;Return to caller if an error occurs
;print,'HAÆÌÈÒÅ ËÅÂÓÞ ÈËÈ ÖÅÍÒÐÀËÜÍÓÞ ÊËÀÂÈØÓ ÌÛØÈ ÄËß ÇÀÏÈÑÈ ÑÒÐÎÊÈ>> <<  ÏÐÀÂÓÞ ÊËÀÂÈØÓ ÄËß ÂÛÕÎÄÀ'

image=image
if total(size(image1)) gt 0 then image=[[[image]],[[image1]]]
if total(size(image2)) gt 0 then image=[[[image]],[[image2]]]
if total(size(image3)) gt 0 then image=[[[image]],[[image3]]]
if total(size(image4)) gt 0 then image=[[[image]],[[image4]]]
if total(size(image5)) gt 0 then image=[[[image]],[[image5]]]
if total(size(image6)) gt 0 then image=[[[image]],[[image6]]]
if total(size(image7)) gt 0 then image=[[[image]],[[image7]]]
!err=0
;if n elements(x0) le 0 then x0 = 0
;if n elements(y0) le 0 then y0 = 0
s = size(image)
s[1] = s[1]-1		;To n-1
s[2] = s[2]-1
if s[s[0]+1] ge 4 then begin
  form = 'G14.5'
  form1 = 'F'
endif else begin
  form = 'I'
endelse

if s[0] eq 2 then repeater = 1 else repeater = string(s[3])
cr = string(15b)	;this codes a newline
if s[0] eq 2 then form="("+form+", '   x=',i4,' y=',i4)" else $
form="("+repeater+form+", '   x=',i4,' y=',i4)"
buf=bytarr(s[1],15)
while !err ne 4 do begin
	CURSOR,x,y,2,/dev
	if (!err and 3) ne 0 then begin	;New line?
	  if s[0] eq 2 then 	  print,format = form, Image[x,yy], x,y else $
	   print,format = form, Image[x,yy,*], x,y
	   while (!err ne 0) do begin wait,.1 & CURSOR,x,y,0,/dev & end
	  endif

	;x = x-x0 & ;y = y - y0
	if (x le s[1]) and (y le s[2]) and (x ge 0) and (y ge 0) then begin
	   if (!order eq 1) then yy = s[2] - y else yy = y
	   tv, buf, 0,s[2]-12,/DEVICE
	   if s[0] eq 2 then out=string(format = form, Image[x,yy],x,y) else $
	   	out=string(format = form, Image[x,yy,*],x,y)
  	   xyouts,0,s[2]-10, out,/DEVICE
  	   ;print, out

	endif
endwhile
;print,form="(/)"
end

