;+
; 
;             NAME : eis_get_iwin
; 
;          PURPOSE : To find the data window given the line id or the
;                    wavelength.
;
; CALLING SEQUENCE : iwin = eis_get_iwin(filename,wavelength) or
;                    iwin = eis_get_iwin(filename,line_id)
; 
;           INPUTS : The filename and the wavelength of interest. The
;                    does not have to be a full path to the file. The
;                    archive is searched for the file. The wavelength
;                    can be anywhere within the wavelength of
;                    interest.
; 
;  OPTIONAL INPUTS : none.
; 
;         KEYWORDS : none.
; 
;          OUTPUTS : The window number.
;
; OPTIONAL OUTPUTS : none.
;
;    COMMON BLOCKS : none.
; 
;          EXAMPLE : IDL> iwin = eis_get_iwin('eis_l0_20061214_192012',195)
;                    IDL> print,iwin
;                         4
;
;    SPECIAL CALLS : eis_get_wininfo.
;
;          WRITTEN : HPW : 08-MAY-2007
; 
;-

function eis_get_iwin,file,input

  ;; --- get information on the windows
  wininfo = eis_get_wininfo(file)
  if datatype(wininfo) ne 'STC' then begin 
    message,'FILE NOT FOUND '+file,/info
    return,-1
  endif

  if datatype(input) eq 'STR' then begin
    ;; --- look for match to line_id
    iwin = (where(wininfo.line_id eq input,c))[0]
    if c eq 0 then begin
      message,'LINE_ID NOT FOUND : '+input,/info
      return,-1
    endif
  endif else begin
    ;; --- look for wavelength
    prod = (wininfo.wvl_max-input)*(input-wininfo.wvl_min)
    iwin = (where(prod gt 0,c))[0]
    if c eq 0 then begin
      message,'WAVELENGTH NOT FOUND : '+trim(input,'(f10.2)'),/info
      return,-1
    endif
  endelse

return,iwin
end
