;+
; Project     : SOHO - CDS     
;                   
; Name        : CDSFOV
;               
; Purpose     : Plots given (x,y) in CDS Field Of View
;               
; Explanation : Illustrates location of intended (X,Y) pointing location
;               in current CDS FOV.  Any program wishing to know whether
;               an (X,Y) position is valid should use the GET_OPS_POINT
;               function.
;               
; Use         : IDL> cdsfov,solar_x,solar_y [,tit='My Object',range=[-1000,0]]
;    
; Inputs      : solar_x - X location in arcsecs from Sun centre 
;               solar_y - Y location in arcsecs from Sun centre.
;               
;               Both inputs can be scalar or arrays.
;               
; Opt. Inputs : None
;               
; Outputs     : None
;               
; Opt. Outputs: None
;               
; Keywords    : TITLE - set user title to plot. Default = 'CDS Field of View'
;               RANGE - 2 element array to set X/Y range of plot 
;                       (same in both axes)
;               SYM   - set plot symbol number (default 8)
;               OVER  - overplots some new data
;
; Calls       :
;
; Common      : fov_com   - saves database access
;               
; Restrictions: None
;               
; Side effects: None
;               
; Category    : Operations
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 28-Jun-96
;               
; Modified    : Shrink plot symbol if gt 9 locations to plot. CDP, 24-Mar-97
;               Sort 32K limit on loop, add SYM keyword.  CDP, 20-Jun-97
;               Add OVER keyword.  CDP, 10-Jul-97
;               Do not recreate window if already correct size.  
;                                                         CDP, 10-Jul-97
;               Tidy if sending to PS.  CDP, 21-Jan-99
;
; Version     : Version 6, 21-Jan-99
;-        
    
pro cdsfov,xp,yp,title=title,range=range,sym=sym,over=over

common fov_com, fovx1,fovx2,fovx3,fovx4, fovy1,fovy2,fovy3,fovy4


;
;  new plot or overplotting?
;
if not keyword_set(over) then begin

;
;  get window if appropriate
;
   if !d.name eq 'X' then begin
      if !d.window eq -1 then window,0
      if !d.x_size ne 640 or !d.y_size ne 630 then begin
         window,!d.window,xs=640,ys=630
      endif
   endif

;
;  set user inputs for title and scale
;
   if not keyword_set(title) then title = 'CDS Field Of View'
   if n_elements(range) eq 0 then range = [-3500,3500]

;
;  solar disk
;
   cs = 1.5
   if !d.name eq 'PS' then cs = 1.1
   a = findgen(499)  * (!PI*2/490.)
   rad = 960.
   plot,rad*sin(a),rad*cos(a),xr=range,yr=range,$
               xtit='Solar X (arcsec)',ytit='Solar Y (arcsec)',chars=cs,$
               tit=title,/xst,/yst

;
;  get (x,y) positions for latest OPS limits
;
   if n_elements(fovx1) eq 0 then begin
      ops_point,'240'x,'200'x,fovx1,fovy1
      ops_point,'240'x,'e00'x,fovx2,fovy2
      ops_point,'e00'x,'200'x,fovx3,fovy3
      ops_point,'e00'x,'e00'x,fovx4,fovy4
   endif

;
;  and plot them
;
   oplot,[fovx1,fovx2],[fovy1,fovy2]
   oplot,[fovx1,fovx3],[fovy1,fovy3]
   oplot,[fovx3,fovx4],[fovy3,fovy4]
   oplot,[fovx2,fovx4],[fovy2,fovy4]

;
;  label
;
   xyouts,fovx1-100,fovy1+100,'N',chars=2
   xyouts,fovx2+100,fovy2-100,'W',chars=2
   xyouts,fovx3-250,fovy3-100,'E',chars=2
   xyouts,fovx4-100,fovy4-300,'S',chars=2
endif 

;
;  finished setup so 
;  indicate the input (x,y) positions
;
if n_elements(xp) gt 9 then ss = 0.5 else ss = 1.5
if not keyword_set(sym) then sym = 8 
for i=0L,n_elements(xp)-1 do begin
   if valid_cds_point(xp(i),yp(i)) then begin
      circle_sym,/fill
      oplot,[xp(i),xp(i)],[yp(i),yp(i)],psym=sym,syms=ss
   endif else begin
      circle_sym
      oplot,[xp(i),xp(i)],[yp(i),yp(i)],psym=sym,syms=ss
   endelse
endfor

end
