
PRO eis_read_wvl_select, infile, wvl_select

;+
; NAME
;
;    EIS_READ_WVL_SELECT
;
; PROJECT
;
;    Hinode/EIS
;
; EXPLANATION
;
;    Reads a text file generated by the routine eis_write_wvl_select
;    into an IDL structure. See also the widget routine
;    eis_wvl_select.pro. 'wvl_select' is an IDL structure that
;    contains information about which wavelength regions are to be
;    used by EIS_AUTO_FIT_NEW when fitting Gaussians to EIS spectral
;    data. 
;
; INPUTS
;
;    INFILE  A text file containing the wvl_select information.
;
; OUTPUTS
;
;    WVL_SELECT  An IDL structure containing information about the
;                selected wavelength regions. The tags are given below
;                in the programming notes section.
;
; PROGRAMMING NOTES
;
;     The tags of WVL_SELECT are:
;
;     .rast_id   The raster ID of the raster from which WINDATA is
;                obtained. 
;
;     .n         The number of selected regions. From the example
;                described above, this will be 2 (for 195.0 to 195.8
;                and 195.9 to 196.0). 
;
;     .min       Fltarr(10). Contains the minimum wavelength for each
;                of the selected regions. From the example above,
;                these will be 195.0 and 195.9 with the others set to
;                zero. 
;
;     .max       Fltarr(10). Contains the maximum wavelength for each
;                of the selected regions. From the example above,
;                these will be 195.8 and 196.0 with the others set to
;                zero. 
;
;     .limit     Fltarr(2). Contains the minimum and maximum
;                wavelengths from the complete set of wavelengths,
;                i.e., min(windata.wvl-offset) and
;                max(windata.wvl+offset). 
;
; HISTORY
;
;    Ver.1, 7-Jan-2010, Peter Young
;-


list=file_search(infile)

IF list[0] EQ '' THEN BEGIN
  print,'%EIS_READ_WVL_SELECT: file not found. Returning...'
  return
ENDIF

wvl_select={rast_id: 0, n: 1, min: fltarr(10), max: fltarr(10), limit: fltarr(2) }


openr,lin,infile,/get_lun

readf,lin,format='(9x,i5)',rast_id
wvl_select.rast_id=rast_id

readf,lin,format='(19x,2f9.0)',aa,bb
wvl_select.limit=[aa,bb]

n=0
readf,lin,format='(23x,i3)',n
wvl_select.n=n

FOR i=0,n-1 DO BEGIN
  readf,lin,format='(6x,2f9.0)',aa,bb
  wvl_select.min[i]=aa
  wvl_select.max[i]=bb
ENDFOR

free_lun,lin

END
