;+
; Project     : SOHO - CDS     
;                   
; Name        : GIS_IN_WINDOW()
;               
; Purpose     : Decide which GIS line_window cursor is in, if any.
;               
; Explanation : In the technical planning display, decide whether the current
;               wavelength falls within the bounds of any of the currently
;               defined GIS line windows.
;               
; Use         : IDL> hit = gis_in_window(line_structure, wavelength)
;    
; Inputs      : line_structure  - the data structure containing details of the
;                                 currently defined line windows list.  The 
;                                 structure is defined in tp_def_struct.
;
;               wavelength      - the wavelength to test
;               
; Opt. Inputs : None
;               
; Outputs     : The function return value is the number of the identified 
;               line-window.  A value of -1 is returned if the wavelength
;               is not within a window.
;               
; Opt. Outputs: None
;               
; Keywords    : None
;
; Calls       : None
;               
; Restrictions: Returns only the first line-window found, tough on overlapping
;               windows.
;               
; Side effects: None
;               
; Category    : Technical planning
;               
; Prev. Hist. :
;
; Written     : C D Pike, RAL, 11-Jun-93
;               
; Modified    : 
;
; Version     : Version 1, 11-Jun-1993
;-            

function gis_in_window, line, wave

;
;  check parameters
;
if n_params() lt 2 then begin
   print,'Use: IDL> n = gis_in_window(line_window_str, wavelength)
   return,-1
endif

;
;  In which GIS band is this wavelength?
;
b = which_gis_band(wave)

if b gt 0 then begin

   gb = 'G'+string(b,format='(i1)')

;
;  get start and end wavelengths for windows
;
   valid = where(which_gis_band(line.lam*line.order) eq b)
   if valid(0) ge 0 then begin
      wleft  = pix2wave(gb,(0 > line(valid).left  < 2047))
      wright = pix2wave(gb,(0 > line(valid).right < 2047))

;
;  in which window is the wavelength?
;
      hit = where( (wleft le wave) and (wright ge wave) )
   endif else begin
      hit = -1
   endelse

endif else begin
   hit = -1
endelse

;
;  only allow single value return, tough on overlapping windows
;
if hit(0) ge 0 then hit = valid(hit) else hit = -1
return,hit(0)


end
