Viewing contents of file '../idllib/uit/pro/ctvrd.pro'
pro ctvrd,image,x0,y0,xsize,ysize,channel,order=order,true=true,words=words
;+
; NAME:
;	CTVRD
; PURPOSE:
;	Read an image displayed on the TV into an IDL variable.  It differs
;	from the function TVRD in three ways:
;		(1)  CTVRD is a procedure, wheras TVRD is a function
;		(2)  If a starting position X0,Y0 or image size XSIZE,YSIZE is
;			not supplied, CTVRD will use the values supplied by the
;		             last call to CTV or CTVRD
;		(3)  The default channel is the current window, rather than
;		window 0.
;
; CALLING SEQUENCE:
;	CTVRD, image, x0, y0, xsize, ysize, channel, ORDER = , TRUE = ,WORDS = 
;
; OPTIONAL INPUTS:
;	X0,Y0       - scalars giving the starting position on the TV display 
;		to be read.
;	XSIZE,YSIZE - scalars giving the X and Y size of the image to be read
;	CHANNEL     - the window to read.  Defaults to the current window.
;
; OPTIONAL KEYWORD INPUTS:
;	ORDER, TRUE, WORDS- These Keywords, if present, are passed directly 
;		to the TVRD routine.  See TVRD documentation for more details.
;
; OUTPUT:
;	IMAGE - 2-dimensional byte array read from the TV display
;
; NOTES:
;	The output image array of TVRD is unaffected by the current or roam or 
;	zoom in the window
;
; EXAMPLE:
;	Invert the image currently on the TV display
;	CTVRD,A            ;Read the current image into the IDL variable A
;	CTV,REVERSE(A,2)   ;Reverse the image, and display on the TV
;
; REVISION HISTORY:
;	Written for workstation use.  M. Greason, STX, June 1990.
;	Modified to also support IVAS and DeAnza   W. Landsman  STX Feb, 1991
;	Keywords added to act as TVRD keywords.  J. Offenberg STX Oct, 1991.
;-
 common tv,chan,zoom,xroam,yroam
 common images,x00,y00,x_size,y_size
;
 npar = N_params()
 if npar EQ 0 then begin
   print,'Syntax - CTVRD, image, [ x0, y0, xsize, ysize, channel]'
   return
 endif
 if ( !D.FLAGS and 128 ) NE 128 then message, $
    'ERROR -- Current device ' +strtrim(!D.NAME,2) + ' does not support TVRD'

 if npar LT 6 then channel = chan            ;Default is current channel

 if npar LT 2 then begin   ;Get starting pixel
   if N_elements(x00) NE 0 then begin
       x0 = x00(channel)>0 & y0 = y00(channel)>0
   endif else begin
       x0 = 0  &  y0 = 0
   endelse
 endif

 if npar lt 4 then begin   ;Get size of output image
    if N_elements(x00) NE 0 then begin
       xsize = x_size(channel) < !d.x_vsize  
       ysize = y_size(channel) < !d.y_vsize
   endif else begin
       xsize = !d.x_vsize
       ysize = !d.y_vsize
   endelse   
 endif

 IF not(keyword_set(ORDER)) then ORDER = 0
 IF not(keyword_set(TRUE )) then TRUE = 0
 IF not(Keyword_set(WORDS)) then WORDS = 0


 message,'Now reading '+strtrim(xsize,2) + ' x ' + strtrim(ysize,2) + $
         ' array from the TV',/INF
 windows = ((!D.FLAGS AND 256) EQ 256) 
 if windows then wset,channel
 image = tvrd(x0,y0,xsize,ysize,channel,ORDER=Order, TRUE = True, WORDS=Words)
 if windows then wset,chan

 return
 end