PRO RH_W_DPCLEAN_Event, Event

  COMMON rh_wdpcl, i_clean, fac_seuil1, crit_arret, larg_2
  COMMON rh_dpcl_base, bicl, blarg2_ew, blarg2_ns  

  WIDGET_CONTROL,Event.Id,GET_UVALUE = Ev
  CASE Ev OF

  'help_im': BEGIN
	     rh_dp_aide, message, sujet = 'clean parameters'
             mes = DIALOG_MESSAGE(message, /INFORMATION, $
                   TITLE = 'Read Me : Clean parameters')
         END

  'clean' : i_clean = event.index

  'criteria': BEGIN
            tab_crit = ['residual becomes less than a given threshold',     $
                        'residual flux becomes less than a given threshold',$
                        'residual begins to increase',         $
                        'clean components change sign']
	    rh_selection,'Criteria for stopping iteration', $
                           tab_crit,crit_arret,group=event.top
             END
  'threshold': BEGIN
             fac_seuil1 = event.value
             print,'fac_seuil1',fac_seuil1
             END
  'largew':BEGIN
           larg_2(0) = event.value
           END
  'largns':BEGIN
           larg_2(1) = event.value
           END
  'std'   : BEGIN
            def_str_dp, str_dp
            i_clean     = str_dp.mode_clean
            crit_arret  = str_dp.crit_arret(0:3)
            fac_seuil1 = 1.
            larg_2       = str_dp.larg_2
            WIDGET_CONTROL, bicl, SET_DROPLIST_SELECT = i_clean
            WIDGET_CONTROL, blarg2_ew, SET_VALUE = larg_2(0)
            WIDGET_CONTROL, blarg2_ns, SET_VALUE = larg_2(1)
	 END


  'ok':  BEGIN
;         print,'ok',np, larg, period, iuv, i_clean, tab_sel_ext, mode_inter
         WIDGET_CONTROL,EVENT.TOP,/DESTROY   
         END
  ENDCASE
END


PRO RH_W_DPCLEAN

; modif 2004-oct : bug : ajout de /RETURN_EVENTS dans les appels a CW_FIELD
 
  COMMON rh_wdpcl, i_clean, fac_seuil1, crit_arret, larg_2
  COMMON rh_dpcl_base, bicl, blarg2_ew, blarg2_ns 
  if (xregistered('RH_W_DPCLEAN')) then begin     ; Don't make a second copy.
     print,' "Clean parameters " already in use'
     return
  end
;  IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0

  imBASE = WIDGET_BASE(COLUMN=1,$ 
             TITLE='Clean parameters', SPACE= 20, $
	    /BASE_ALIGN_CENTER)

  b = WIDGET_BUTTON( imBASE, UVALUE='help_im', VALUE='Read Me', $
      xs=4., ys=0.8, units = 2)

;  BASE = WIDGET_BASE(imbase, /COLUMN, SPACE= 15,/BASE_ALIGN_CENTER,/FRAME)
 
  ggbase = widget_base(imbase, /col, /frame)
;-------------- gbase1 ----------------------------
  gbase1 = widget_base(ggbase, /row)
  
  lcl = WIDGET_Label(gbase1,Value=' clean :')  
  tab = [' No clean','Clean','Clean without residual']
  bicl = WIDGET_DROPLIST( gBASE1, UVALUE='clean',    $
		value=tab)
  WIDGET_CONTROL, bicl, SET_DROPLIST_SELECT = i_clean
;-------------- gbase2 ----------------------------
  gbase2 = widget_base(ggbase, /row)
  lcl = WIDGET_Label(gbase2,Value=' Stopping iteration :')  
  bant = WIDGET_BUTTON( gBASE2, UVALUE='criteria', $
		VALUE='Criteria ', units = 2)

  bant = CW_FIELD( gBASE2, UVALUE='threshold', title='threshold factor', $
		value= fac_seuil1, /floating, /RETURN_EVENTS, XSIZE = 5)
;-------------- gbase3 ----------------------------
  gbase3 = widget_base(ggbase, /row)
 
  blarg2_ew = CW_FIELD( gBASE3, title= 'Width of final filter(#harmonics)    EW', $
               UVALUE='largew',value= larg_2(0), /RETURN_EVENTS, /integer, XSIZE = 4)
  blarg2_ns = CW_FIELD( gBASE3,title='  NS ', $
               UVALUE='largns',value= larg_2(1), /RETURN_EVENTS, /integer, XSIZE = 4)
;--------------------------------------------------
  b = WIDGET_BUTTON( imBASE, UVALUE='std',                        $
                     VALUE='Back to Local Standard Parameters', $
                     xs=10., ys=1, units=2)

   b = WIDGET_BUTTON( imBASE, UVALUE='ok', VALUE='ok',  $
      xs=2., ys=1, units = 2)

  WIDGET_CONTROL, imBASE, /REALIZE
  XMANAGER, 'RH_W_DPCLEAN', imBASE,/NO_BLOCK

END
