
PRO eis_write_wvl_select, wvl_select, outfile=outfile

;+
; NAME
;
;    EIS_WRITE_WVL_SELECT
;
; PROJECT
;
;    Hinode/EIS
;
; EXPLANATION
;
;    '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. This routine writes out the wvl_select structure to a text
;    file in a standard format.
;
;    A user will generally not be expected to run this routine
;    directly. It is intended that the user runs eis_wvl_select to
;    create wvl_select.
;
; INPUTS
;
;    WVL_SELECT  A wvl_select structure - see the routines
;                eis_read_wvl_select and eis_wvl_select for more
;                details. 
;
; OPTIONAL OUTPUTS
;
;    OUTFILE  The output filename has a default format (see below),
;             but the user can directly specify a name with OUTFILE. 
;
; OUTPUTS
;
;    Creates a text file containing the complete set of information
;    stored in wvl_select. The default format of the name is
;    'wvl_select_n_m.txt' where n is the raster ID for the data-set
;    and m the wavelength. E.g., a filename of
;    'wvl_select_365_19512.txt' indicates a raster ID of 365 and a
;    wavelength of 195.12.
;
; HISTORY
;
;    Ver.1, 7-Jan-2010, Peter Young
;-

wvl_int=round(average(wvl_select.limit)*100.)
wvl=trim(string(wvl_int))

IF n_elements(outfile) EQ 0 THEN outfile='wvl_select_'+ $
                                         trim(wvl_select.rast_id)+'_'+$
                                         wvl+'.txt'

openw,lout,outfile,/get_lun


printf,lout,format='("RAST_ID: ",i5)',wvl_select.rast_id
printf,lout,format='("Wavelength limits: ",2f9.4)',wvl_select.limit
n=wvl_select.n
printf,lout,format='("No. wavelength ranges: ",i3)',n
FOR i=0,n-1 DO BEGIN
  printf,lout,format='(i6,2f9.4)',i+1,wvl_select.min[i],wvl_select.max[i]
ENDFOR 

free_lun,lout

END
