pro plot_fov, struct, selfov, ss, box=box, qstop=qstop, img=img, nocmd=nocmd, $
		skipfirst=skipfirst
;
;+
;NAME:
;	plot_fov
;PURPOSE:
;	To plot the locations of the PFI fields of views (FOV).
;	The routine accepts either ROADMAP or INDEX.SXT
;CALLING SEQUENCE:
;	plot_fov, index  
;	plot_fov, roadmap, sel, ss
;INPUT:
;	struct	- Either the ROADMAP or INDEX structure
;OPTIONAL OUTPUT:
;	selfov	- If present, the user is prompted to mark a box
;		  selecting the "window" of interest.  The value
;		  returned is an array of the same length as
;		  the input array with the selected datasets
;		  having a "1".  The way to use this value is
;		  something like the following:
;			ss = where(selfov)
;			ss = where(selfov and (struct.percentd eq 255))
;	ss	- Return the list of indicies that were selected.
;		  This should be used only if you do not want to 
;		  do other searches using the "where" function.
;OPTIONAL INPUT:
;	box	- If present, draw the size of the field of view.  
;		  The summation mode is reflected in the box size.
;	qstop	- If present, stop at the end (for debugging)
;	img	- If present, after plotting the line plot, display the
;		  image and the location of the PFI images on the sun
;		  It allows the user to check the offset being used.
;	nocmd	- If set, use the actual pointing information from the
;		  PNT file, not the S/C commanded value.
;HISTORY:
;	Written Oct-91 by M.Morrison
;	20-Oct-91 (MDM) - Added /box, /img, and /sun2 options
;	12-Nov-91 (MDM) - Added "ss" parameter option
;	16-Nov-91 (MDM) - Changed to use GT_FOV_CENTER so that index
;			  can be passed directly
;	20-Nov-91 (MDM) - Put a temporary fix in because of GETSXTFOV 
;			  error in OR PFIs
;	28-Jan-93 (MDM) - Modified to use the expanded GT_FOV_CENTER
;			  which does corrections done here before, and
;			  corrects now for commanded pointing changes.
;			- Removed SUN2 option
;	14-Jul-93 (MDM) - Corrected IMG option
;			- Use GT_CENTER instead of GT_FOV_CENTER
;			- Allowed NOCMD option to use PNT pointing info
;			- Use GT_SHAPE instead of GT_SHAPE_CMD
;			- Replaced fixed solar radius with a call to GET_RB0P
;	21-Jul-93 (MDM) - Added /OBS_REGION switch to GT_SHAPE so that the
;			  observing region shape is displayed
;	12-Sep-93 (SLF) - added skipfirst - if img and skipfirst, just do the
;			  second plot (img overlayed) and dont prompt
;-
;
dofirst= 1-keyword_set(skipfirst)

rr = get_rb0p(struct)
rad = total(rr(0,*))/60. / n_elements(struct)
;
xcir = cos(2*!pi*findgen(400)/399)
ycir = sin(2*!pi*findgen(400)/399)
;
;fov_center = gt_fov_center(struct)	;FOV values are arcminutes from sun center
fov_center = gt_center(struct, /angle, cmd=(1-keyword_set(nocmd)))/60.	;acrminutes from sun center
x = fov_center(0,*) 
y = fov_center(1,*)
;
if (n_elements(x) eq 1) then begin
    x = x*(fltarr(2)+1)	;make it into an array
    y = y*(fltarr(2)+1)	;make it into an array
end
;
sum = 2^gt_res(struct)
;shape_cmd = gt_shape_cmd(struct)
shape_cmd = gt_shape(struct, /obs_region)
xsiz = shape_cmd(0,*)*sum*2.45/60.		;size of the plot window in arcminutes
ysiz = shape_cmd(1,*)*sum*2.45/60.
;
xtitle = 'Arcminutes from Sun Center (Using GT_CENTER)'
if dofirst then plot, xcir*rad, ycir*rad, xrange=[-21,21], yrange=[-21,21], xstyle=1, ystyle=1, xtitle=xtitle
if dofirst then oplot, x, y, psym=1
;
if (keyword_set(box)) then begin
    for i=0,n_elements(struct)-1 do begin
	draw_boxcensiz, x(i), y(i), xsiz(i), ysiz(i), /data
    end
end
;
if (n_params(0) ge 2) then begin
    selfov = bytarr(n_elements(x))
    get_boxcorn, x0, y0, x1, y1, /data
    draw_boxcorn, x0, y0, x1, y1, /data
    print, 'X Range: ', x0, x1
    print, 'Y Range: ', y0, y1
    ss = where( (x ge x0) and (x le x1) and (y ge y0) and (y le y1))
    if (ss(0) ne -1) then selfov(ss) = 1
    print, 'There are ', strtrim(fix(total(selfov)),2), ' images selected'
end    
;
if (keyword_set(img)) then begin
    in = ' '
    if dofirst then read, 'Hit <CR> to continue', in
    ;
    cen = sxt_cen(struct, cmd=(1-keyword_set(nocmd)))
    xc = total(cen(0,*)) / n_elements(struct)	;center pixel address
    yc = total(cen(1,*)) / n_elements(struct)

    sumi = 1024 / n_elements(img(*,0))	;should be 2 or 4

    tvscl, img	
    x_cir = xcir*rad*60/2.45/sumi + xc/sumi
    y_cir = ycir*rad*60/2.45/sumi + yc/sumi	;in pixel units
    tvplot, x_cir, y_cir
    
    x2 = (xc + x*60/2.45)/sumi
    y2 = (yc + y*60/2.45)/sumi
    xsiz2 = xsiz*60/2.45/sumi
    ysiz2 = ysiz*60/2.45/sumi
    for i=0,n_elements(struct)-1 do begin
	draw_boxcensiz, x2(i), y2(i), xsiz2(i), ysiz2(i), /data
    end
end
;
if (keyword_set(qstop)) then stop
end
