PRO RH_W_DPHARMONIC_Event, Event

  COMMON rh_wdphar, i_redond, tab_sel_ext, tab_sel_ant, iuv, $
                   i_recentrage, x_centrage, y_centrage
  COMMON rh_dphar_base, biuv, bredond, $
                       bmode_centr, bx_centr, by_centr, hbase2, hbase3 

  @rh_common.inc

  WIDGET_CONTROL,Event.Id,GET_UVALUE = Ev

  CASE Ev OF

  'help_har': BEGIN
	     rh_dp_aide, message, sujet = 'selection of harmonics'
             mes = DIALOG_MESSAGE(message, /INFORMATION, $
                   TITLE = 'Read Me : selection of harmonics ')
	  END


  'extensions': BEGIN
              tab_ext = ['IE0_ew  ' ,   $      ; / 1
                         'IE0_ns  ' ,   $      ; / 0
                         'IE1_ew  ' ,   $      ; / 1
                         'IE2_ew  ' ,   $      ; / 1
                         'IE2_ns  ' ,   $      ; / 1
                         'INS45_ew' ,   $      ; / 1               
                         'INS45_ns'     ]      ; / 1  

	      rh_selection,'Extension Antennas',tab_ext,tab_sel_ext,$
                           /sel_qcq, group=event.top
          END
  'redondant': BEGIN 
               CASE event.index OF
               0: i_redond = 0
               1: i_redond = 1
               ENDCASE
               END
  'suppr_ant': BEGIN
              nb_ant = entfi.nbant
              tab_ant = rh_antenne(nb_ant)
              tab_temp = tab_sel_ant(0:nb_ant-1)
	      rh_selection,'Antennas', tab_ant,tab_temp, $
                           /sel_qcq, group=event.top
                                ; on veut garder la dimension de 48 a
                                ; tab_sel_ant pour le common
              tab_sel_ant(0:nb_ant-1) = tab_temp
              if (nb_ant eq 44)then begin
                  tab_sel_ant(44:47)=1     ; 1 si on enchaine avec 48 antennes
              endif
;print,'rh_w_dpharmonic : tab_sel_ant :',tab_sel_ant
          END
  'uv'    : BEGIN
               CASE event.index OF
               0:  BEGIN
                   iuv = 0
                   WIDGET_CONTROL, hbase2, SENSITIVE = 0
                   END
               1:  BEGIN
                   iuv = 1
                   WIDGET_CONTROL, hbase2, SENSITIVE = 1
                   END
               ENDCASE
;               print,'iuv',iuv
           END
  'mode_centr': BEGIN
                i_recentrage = event.index
                if i_recentrage eq 2 then $
                   WIDGET_CONTROL, hbase3, SENSITIVE = 1 $
                else WIDGET_CONTROL, hbase3, SENSITIVE = 0
           END
  'x_centr'   : x_centrage = event.value
  'y_centr'   : y_centrage = event.value

  'std'   : BEGIN
            def_str_dp, str_dp
            i_redond    = str_dp.i_redond
            tab_sel_ext(0) = str_dp.ie0_ew 
            tab_sel_ext(1) = str_dp.ie0_ns 
            tab_sel_ext(2) = str_dp.ie1_ew 
            tab_sel_ext(3) = str_dp.ie2_ew 
            tab_sel_ext(4) = str_dp.ie2_ns 
            tab_sel_ext(5) = str_dp.ins45_ew
            tab_sel_ext(6) = str_dp.ins45_ns
            tab_sel_ant = str_dp.sel_ant
            iuv         = str_dp.i_pave_plein
            i_recentrage = str_dp.i_recentrage
            x_centrage = str_dp.x_centrage
            y_centrage = str_dp.y_centrage

            WIDGET_CONTROL, biuv, SET_DROPLIST_SELECT = iuv
            WIDGET_CONTROL, bredond, SET_DROPLIST_SELECT = i_redond
            WIDGET_CONTROL, bmode_centr, SET_DROPLIST_SELECT = i_recentrage
            WIDGET_CONTROL, bx_centr, SET_VALUE = x_centrage
            WIDGET_CONTROL, by_centr, SET_VALUE = y_centrage
            WIDGET_CONTROL, hbase3, SENSITIVE = 0
	 END
  'ok':  BEGIN
;         print,'ok',np, larg, period, iuv, i_clean, tab_sel_ext, mode_inter, $
;        i_recentrage, x_centrage, y_centrage    
         WIDGET_CONTROL,EVENT.TOP,/DESTROY   
         END
  ENDCASE
END


PRO RH_W_DPHARMONIC

  COMMON rh_wdphar, i_redond, tab_sel_ext, tab_sel_ant, iuv, $
                   i_recentrage, x_centrage, y_centrage
  COMMON rh_dphar_base, biuv, bredond , $
                       bmode_centr, bx_centr, by_centr, hbase2, Hbase3  


  if (xregistered('RH_W_DPHARMONIC')) then begin     ; Don't make a second copy.
     print,' " SELECTION OF HARMONICS " already in use'
     return
  end

;  IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0

  imBASE = WIDGET_BASE(COLUMN=1,$ 
             TITLE='selection of harmonics', SPACE= 20, $
	    /BASE_ALIGN_CENTER)

  BASE = WIDGET_BASE(imbase, /COLUMN, SPACE= 15,/BASE_ALIGN_CENTER,/FRAME)

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

  ggbase = widget_base(base, /col, /frame)
;----------------gbase1--------------------------------------
  gbase1 = widget_base(ggbase, /row)
  bant = WIDGET_BUTTON( gBASE1, UVALUE='extensions', $
		VALUE='Extension Antennas ', $
		xs=5., ys=0.8, units = 2)

  tab_red = [' No','Yes']
  lredond = WIDGET_Label(gbase1,Value=' Add Redund Harmonics:')  
  bredond = WIDGET_DROPLIST( gBASE1, UVALUE='redondant', $
		VALUE=tab_red)
  WIDGET_CONTROL, bredond, SET_DROPLIST_SELECT = i_redond
;----------------gbase2--------------------------------------
  gbase2 = widget_base(ggbase, /row)
  bant = WIDGET_BUTTON( gBASE2, UVALUE='suppr_ant',          $
		VALUE='Suppression of antennas (if spoilt)', $
		xs=10., ys=0.8, units = 2)
;----------------hbase1-------------------------------------- 
  hhbase = widget_base(base, /col, /frame )
  hbase1 = widget_base(hhbase, /row)
  tab = [' No','Yes']
  liuv = WIDGET_Label(hbase1,Value=' Interpole odd EW harm. :')  
  biuv = WIDGET_DROPLIST( hBASE1, UVALUE='uv',	$
		value=tab)
  WIDGET_CONTROL, biuv, SET_DROPLIST_SELECT = iuv
;-------------- hbase2 ----------------------------
  hbase2 = widget_base(hhbase, /row, sensitive = 0) 
  
  tab = [' No','On maximum', ' On X,Y']
  lmode_centr = WIDGET_Label(hbase2,Value=' Re-center the image :')  
  bmode_centr = WIDGET_DROPLIST( hbase2, UVALUE='mode_centr', $
		value=tab)
  WIDGET_CONTROL, bmode_centr, SET_DROPLIST_SELECT = i_recentrage
;-------------- hbase3 ----------------------------
  hbase3 = widget_base(hhbase, /row, sensitive = 0)
  
  bx_centr = CW_FIELD( hBASE3, title= 'units of 0.01SR  X', $
               UVALUE='x_centr',value= x_centrage, /RETURN_EVENTS, /integer, XSIZE = 4)
  by_centr = CW_FIELD( hBASE3,title='  Y', $
               UVALUE='y_centr',value= y_centrage, /RETURN_EVENTS, /integer, XSIZE = 4)
;------------------------------------------------------------
  b = WIDGET_BUTTON( BASE, UVALUE='std',                        $
                     VALUE='Back to Local Standard Parameters', $
                     xs=10., ys=1, units=2)

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

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

END
