;+
; Project     : SOHO - CDS     
;                   
; Name        : TP_DRAW_VWIN
;               
; Purpose     : Plot the data in the extraction windows in a raster.
;               
; Explanation : Plots the data extraction windows used in a raster for
;               illustrative purposes.  Works from the observation 
;               definition structure used in MK_RASTER.
;               
; Use         : IDL> tp_draw_vwin, obs_str
;    
; Inputs      : obs_str  - a valid TPLAN data structure.
;                   
; Opt. Inputs : None
;               
; Outputs     : Just plots the results.
;               
; Opt. Outputs: None
;               
; Keywords    : HARD - for hardcopy plot
;
; Calls       : None
;
; Common      : None
;               
; Restrictions: None
;               
; Side effects: None
;               
; Category    : Planning, technical
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 04-Mar-96
;               
; Modified    : Adjust for slit and exposure time.  CDP, 05-May-99
;
; Version     : Version 2, 06-May-99
;-            

pro tp_draw_vwin, input, hard=hard

;
;  common for variables associated with widget mode
;
@tplan_com



;
;  record plot setup, assumed on entry to be that for the main plot
;  area
;
savep = !p  & savex = !x & savey = !y
if keyword_set(hard) then begin
   pwin_start = last_vwin_plot
endif else begin
   last_vwin_plot = pwin_start
endelse

if not keyword_set(hard)  then begin
   if not xregistered('tp_plot_vds') then begin
      window,xs=512,ys=512,xpos=0,ypos=512,$
                           title='CDS VDS Data Windows'
   endif else begin
      widget_control, vdsp_image, get_val=wind
      wset,wind
   endelse
endif

;
;  hard copy preparation
;
if keyword_set(hard) then ps
!p.multi= [0,2,2]


;
;  set titles
;
if pvds_pl eq 0 then xtit = 'Pixels' else xtit = 'Wavelength'

;
;  total number of windows
;
num = max(where(line_window.x_pos gt 0))

plotted = 0
last = 0
for i=pwin_start,num do begin
   if plotted le 3 then begin
      if line_window(i).x_pos le 1023 then begin
       y = (line_window(i).y_pos gt 127)*128
       ys = y > 7
       yb = ys + 60 - fix(round(float(line_window(i).height)/4.0))
       yt = yb + fix(round(float(line_window(i).height)/2.))
       xl = line_window(i).left  > 0
       xr = line_window(i).right < 1023
       wdata = VDS_image_data(xl:xr,(yb+yt)/2)
;
;  adjust according to exposure time and slit
;
       if current_zone eq -4 then begin
          wdata = wdata/1000.*float(curr_etime)
       endif
       if current_zone eq -5 then begin
          wdata = wdata/100.*float(curr_etime)
       endif
       if input.raster_p.slit_num eq 5 then wdata = wdata*2.

       xdat = indgen(n_elements(wdata)) + xl
       if yb ge 128 then begin
          if same_data(nis_pdef,[1,0,0]) or same_data(nis_pdef,[0,0,1]) then begin
             if pvds_pl eq 1 then xdat = pix2wave('N1',xdat)
             plot,xdat,wdata,psym=10,xtit=xtit
             plotted = plotted + 1
          endif
       endif else begin
          if same_data(nis_pdef,[0,1,0]) or same_data(nis_pdef,[0,0,1]) then begin
             if pvds_pl eq 1 then xdat = pix2wave('N2',xdat)
             plot,xdat,wdata,psym=10,xtit=xtit
             plotted = plotted + 1
          endif
       endelse
      endif
      last = i
   endif
endfor

;
;  Move onto next group.  recycle if at end
;
if last eq  num then pwin_start=0 else pwin_start = last + 1

;
; print hardcopy
;
if keyword_set(hard) then psplot
!p.multi = 0


;
;  return plot set up to standard
;
if not keyword_set(hard) then begin
   if xregistered('tp_plot_vds') then begin
      widget_control, image_area, get_val=wind
      wset,wind
      !p = savep & !x = savex & !y = savey
   endif
endif 


end
