;+
; Project     : SOHO - CDS     
;                   
; Name        : DISPLAY_NIS_WIN
;               
; Purpose     : Display NIS line-windows on the technical planning plot.
;               
; Explanation : On the technical planning page1 display, draw an outline of
;               the defined line windows, or if in display windows only mode
;               just display the data within the window. Any windows with 
;               invalid parameters are displayed in dashed line mode.
;               
; Use         : IDL> display_nis_win [,num, /dash]
;    
; Inputs      : None
;               
; Opt. Inputs : num  -  the number of the line to display.  If absent all are
;                       displayed.
;               
; Outputs     : None
;               
; Opt. Outputs: None
;               
; Keywords    : dash - if present the outline is drawn with a dashed line
;
; Calls       : None
;               
; Restrictions: Variable are transferred in the tp_page1 common blocks
;               
; Side effects: None
;               
; Category    : Technical planning.
;               
; Prev. Hist. :
;
; Written     : C D Pike, RAL, 14-May-1993
;               
; Modified    : Replace calls to NINT by ROUND.  CDP, 17-Jun-95  
;               Cater for choice of flag window modes (flag_state).
;                                                CDP, 18-oct-95
;               Fix bug in display of flag windows. CDP, 3-Nov-95
;
; Version     : Version 4, 3-Nov-95
;-            

pro display_nis_win, num, dash=dash

;
;  include tp common for display mode etc 
;
@tplan_com

;
;  if want dashed line then set line value level to be zero else 255
;
if keyword_set(dash) then offset=0 else offset=255


;
;  If the parameter num was specified, it is the window to display, 
;  otherwise do all of them.
;
;  Draw limits of the windows and put a block at top or bottom to aid
;  visibility if in "display all" mode, otherwise display the data within the 
;  window(s).
;
if n_elements(num) eq 0 then begin
   num = max(where(line_window.x_pos ge 0))
   for i=0,num do begin
      if flag_state eq 0 then begin
         if line_window(i).flag eq 1 then offset=0 else offset=255
      endif   
      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.0))
      if yt gt yb then begin
         vert_line = bytarr(1,yt-yb+1)+offset
      endif else begin
         vert_line = bytarr(1,120)+offset
         vert_line = dash_line(vert_line) 
      endelse
      if offset eq 0  then vert_line = dash_line(vert_line) 
      xl = line_window(i).left  > 0
      xr = line_window(i).right < 1023
      if xr gt xl then begin
         horiz_line = bytarr(xr-xl+1,1)+offset
      endif else begin
         horiz_line = bytarr(20,1)+offset
         horiz_line = dash_line(horiz_line) 
      endelse
      if offset eq 0 then horiz_line = dash_line(horiz_line)
      if window_mode eq 'ALL' then begin
         tv,(vert_line),xl,yb
         tv,(vert_line),xr,yb
         tv,(horiz_line),xl,yb
         tv,(horiz_line),xl,yt
         block = bytarr(xr-xl+1,8)+255
          if y eq 0 then tv,block,xl,0 else tv,block,xl,248
      endif else begin
         if (flag_state eq 1) or $
               ((flag_state eq 0) and (line_window(i).flag eq 0)) then begin
            tv,tp_bscale(VDS_image_data(xl:xr,yb:yt)),xl,yb
         endif
      endelse
   endfor
;
;  single line requested
;
endif else begin
      if keyword_set(dash) then begin
         if flag_state eq 0 then begin
            if line_window(num).flag eq 1 then offset=255 else offset=0
         endif  
      endif else begin
         if flag_state eq 0 then begin
            if line_window(num).flag eq 1 then offset=0 else offset=255
         endif  
      endelse 
      y = (line_window(num).y_pos gt 127)*128
      ys = y > 7
      yb = ys + 60 - fix(round(float(line_window(num).height)/4.0))
      yt = yb + fix(round(float(line_window(num).height)/2.0))
      if yt gt yb then begin
         vert_line = bytarr(1,yt-yb+1)+offset
      endif else begin
         vert_line = bytarr(1,120)+offset
         vert_line = dash_line(vert_line) 
      endelse
      if offset eq 0 then vert_line = dash_line(vert_line)
      xl = line_window(num).left  > 0
      xr = line_window(num).right < 1023
      if xr gt xl then begin
         horiz_line = bytarr(xr-xl+1,1)+offset
      endif else begin
         horiz_line = bytarr(20,1)+offset
         horiz_line = dash_line(horiz_line) 
      endelse
      if offset eq 0 then horiz_line = dash_line(horiz_line)
      if window_mode eq 'ALL' then begin
         tv,(vert_line),xl,yb
         tv,(vert_line),xr,yb
         tv,(horiz_line),xl,yb
         tv,(horiz_line),xl,yt
         block = bytarr(xr-xl+1,8)+255
         if y eq 0 then tv,block,xl,0 else tv,block,xl,248
      endif else begin
         tv,tp_bscale(VDS_image_data(xl:xr,yb:yt)),xl,yb
      endelse
endelse

end

