; Project     :	SOHO - CDS
;
; Name        :	LIST_IEFWIN
;
; Purpose     :	Lists the available IEF window database entries.
;
; Explanation : Extracts the descriptions of all the flag generation windows
;               from the IEFWIN database. 
;
; Use         : <list_iefwin, list, n_found>
;
; Inputs      : None.
;
; Outputs     : list = an array of structures containing the IEF window database values.
;                  Tags are :
;                  .iefwin_id  = I*2    IEF window ID. 
;                                       If the requested IEF window is not found,
;				        then a simpler structure is returned, with
;				        this set to -1.
;                  .win_name   = C*40   Window name
;                  .ev_desc    = C*65   Description of event detection scheme employed
;                  .detector   = C*1    'N' = NIS, 'G' = GIS
;                  .win_def    = 4(I*2) Window definition ( xstart, ystart, xsize, ysize )
;                  .px_offset  = I*2    Pixel offset defining ROI around peak pixel.
;                  .exp_era    = 4(I*2) Expected values for each ERA in window.
;                  .dev_era    = 4(I*2) Deviations for each ERA in window.
;                  .wgt_era    = 4(I*2) Weights for each direct ERA in window.
;                  .wgt_dera   = 4(I*2) Weights for each differential ERA in window.
;
; Keywords    :
;       ERRMSG    = If defined and passed, then any error messages will be
;                   returned to the user in this parameter rather than
;                   depending on the MESSAGE routine in IDL.  If no errors are
;                   encountered, then a null string is returned.  In order to
;                   use this feature, ERRMSG must be defined first, e.g.
;
;                       ERRMSG = ''
;                       LIST_IEFWIN, ERRMSG=ERRMSG, ... 
;                       IF ERRMSG NE '' THEN ...

; Calls       :	dbopen, db_info, dbext, dbclose.
;                
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	None.
;
; Category    :	Command preparation.
;
; Prev. Hist. :	Adapted from get_datawin.
;
; Written     :	Version 0.0, Martin Carter, RAL, 27/11/95
;
; Modified    :	
;
; Version     :	Version 0.0, 27/11/95
;-
;**********************************************************

PRO list_iefwin, list, n_found, ERRMSG=errmsg

  ON_ERROR, 2

;  Define a null result.  If the routine is successful, this will be updated
;  later.
;
  n_found = 0

;
;  Check the number of parameters.
;
  IF N_PARAMS() NE 2 THEN BEGIN
    MESSAGE = 'Syntax:  LIST_IEFWIN, LIST, N_FOUND'
    GOTO, HANDLE_ERROR
  ENDIF

; open database for updating

  dbopen, 'iefwin'

; check database has some entries
; else dbfind will flag error

  nentries = db_info ( 'entries' )

;
;  If no entries were found, then return immediately.
;
  IF nentries(0) LT 1 THEN BEGIN
    MESSAGE = 'No IEF window tables found'
    GOTO, HANDLE_ERROR
  ENDIF

; read entries from database

  dbext, LINDGEN(nentries(0)), 'IEFWIN_ID,WIN_NAME,EV_DESC,DETECTOR,WIN_DEF,PX_OFFSET,EXP_ERA,DEV_ERA,WGT_ERA,WGT_DERA', $
                                iefwin_id,win_name,ev_desc,detector,win_def,px_offset,exp_era,dev_era,wgt_era,wgt_dera

  ; set up results

  n_found = nentries(0)

  ; form first element of structure array 

  list = { iefwin_id : iefwin_id(0), win_name:win_name(0), ev_desc:ev_desc(0),                      $
          detector:detector(0), win_def:win_def(*,0), px_offset:px_offset(0), exp_era:exp_era(*,0), $
          dev_era:dev_era(*,0), wgt_era:wgt_era(*,0), wgt_dera:wgt_dera(*,0) }

  ; form structure array

  list = REPLICATE ( list, n_found )

  ; set up structure array elements

  list.iefwin_id  = iefwin_id
  list.win_name   = win_name
  list.ev_desc    = ev_desc
  list.detector   = detector
  list.win_def    = win_def
  list.px_offset  = px_offset
  list.exp_era    = exp_era
  list.dev_era    = dev_era
  list.wgt_era    = wgt_era
  list.wgt_dera   = wgt_dera

  GOTO, FINISH
;
;  Error handling point.
;
HANDLE_ERROR:
	IF N_ELEMENTS(ERRMSG) NE 0 THEN ERRMSG = 'LIST_IEFWIN: ' + MESSAGE $
		ELSE MESSAGE, MESSAGE, /CONTINUE
;
;  Close the database, and return.
;
FINISH:
	dbclose, 'iefwin
;
	RETURN

END


