if .not.exist(self_mode) then
  @ d_selfcal
endif
!
!
begin procedure add_argument
  let  &1 '&1'" "'&2'
end procedure add_argument
!
begin procedure make_let_command
  define integer nloop
  let nloop size(&1)
  !
  define chara*256 long_string /global
  !
  let long_string "let &1"
  if (nloop.eq.0) then
    @ add_argument long_string '&1'
  else
    for i 1 to nloop
      @ add_argument long_string '&1[i]'
    next
  endif
  symbol &2  'long_string'
  delete /variab long_string
end procedure
!
@ make_let_command self_niter let_niter
@ make_let_command self_times let_times
@ make_let_command self_minflux let_minflux
!
gui\panel "Self Calibration (S.Guilloteau)" gag_scratch:selfcal.hlp
!
  gui\button "selfcal AMPLI"    "AMPLI"
  gui\button "selfcal PHASE"    "PHASE"
  gui\button "SIC\CONTINUE"  "Continue"
  gui\button "selfcal ?"        "INPUT"
  gui\button "selfcal SHOW"     "SHOW"
  gui\button "selfcal SUMMARY"  "SUMMARY"
  gui\button "@ selfcal_apply"  "APPLY"
  gui\button "selfcal flag"     "FLAG"
  gui\button "@ s_selfcal"      "SAVE"
  !
  let self_mode 'SELF_MODE' /choice PHASE AMPLI /Prompt "Mode"
  !
  let_niter /prompt "Number of clean components for each loop" /resize
  let_times /prompt "Integration time for each loop" /resize
  let_minflux  /prompt "Minimum brightness in Clean image for each loop" /resize
  !
  let self_channel 'self_channel[1]' 'self_channel[2]' /prompt "Channel range"
  let self_snr 'self_snr' /prompt "Minimum SNR"
  let self_flag 'self_flag' /prompt "Flag data with no solution"
  !
  say " "
  say "Display and Secondary criteria"
  let self_flux 'self_flux' /prompt "Maximum flux for display (0=>no plot)"
  let self_restore 'self_restore' /prompt "Use UV_RESTORE at end"
  let self_display 'self_display' /prompt "Display Clean map before each loop ?"
  let self_sname 'self_sname' /prompt "Phase solution table name"
  let self_refant 'self_refant' /prompt "Reference antenna"
  let self_snoise 'self_snoise' /prompt "Noise scaling factor"
  let self_precision 'self_precision' /prompt "Convergence precision" /range 0 0.05
  !
  say " "
  gui\button "            "  "CLEAN" "Clean parameters" gag_scratch:selfcal.hlp "Clean Parameters"
  let method 'method' /upper
  let method 'method' /prompt "Deconvolution Method" /choice HOGBOM CLARK SDI MULTI
  let clean_gain 'clean_gain' /prompt "Loop gain"
  let clean_ares 'clean_ares' /prompt "Max abs. residual"
  let clean_fres 'clean_fres' /prompt "Frac. abs. residual"
  let clean_niter 'clean_niter' /prompt "Max. number of iterations"
  let clean_nkeep 'clean_nkeep' /prompt "Convergence length"
  !
  say " "
  gui\button "selfcal SHOW"  "SHOW" "Display parameters" gag_scratch:selfcal.hlp "Display Parameters"
  let self_arange 'self_arange[1]' 'self_arange[2]' /prompt "Amplitude gain display range"
  let self_prange 'self_prange[1]' 'self_prange[2]' /prompt "Phase     gain display range"
  let self_trange 'self_trange[1]' 'self_trange[2]' /prompt "Time display range"
!
gui\go "SAY Use top buttons for actions" ! "selfcal"
