if .not.exist(kepler_vmass) then
  kepler init
  if file("memory-kepler.ima") @ memory-kepler
endif
begin procedure xsub_kepler
  if kepler_usevdisk then
    kepler  /vsyst 'kepler_vdisk'
  else
    kepler 
  endif
end procedure
define char*64 hlptxt
let hlptxt "gag_doc:hlp/kepler-help.hlp"
!
gui\panel "Kepler Disk Alignment Tool" 'hlptxt' 
!
gui\button "KEPLER INIT"     INIT  "Re-initialize KEPLER parameters" 'hlptxt' "Init"
gui\button "@ kepler-save"   SAVE  "Save KEPLER parameters" 'hlptxt' "Save"
!
gui\button "@ xsub_kepler"     COMPUTE "Align Spectra" 'hlptxt' "Compute"
let KEPLER_VDISK 'kepler_vdisk' /Prompt "Disk Systemic Velocity" 
let KEPLER_USEVDISK 'kepler_usevdisk' /Prompt "Use Disk Velocity" 
let KEPLER_AZIMUT 'kepler_azimut[1]' 'kepler_azimut[2]' /Prompt "Azimut Range (°)"
let KEPLER_THETA 'kepler_theta' /Prompt "Max Angle from Major axis (°)"
let KEPLER_DIST 'kepler_dist' /Prompt "Distance (pc)"
let KEPLER_STEP 'kepler_step' /Prompt "Radial Step (au)" 
let KEPLER_RINT 'kepler_rint' /Prompt "Inner disk radius (au)"
let KEPLER_ROUT 'kepler_rout' /Prompt "Outer disk radius (au)"
let KEPLER_RMIN 'kepler_rmin' /Prompt "Minimum radius (au)"
if exist(kepler_rmax)  let KEPLER_RMAX 'kepler_rmax' /Prompt "Maximum radius (au)"
let KEPLER_VMASS 'kepler_vmass' /Prompt "Rotation Velocity at 100 au"
let KEPLER_INCLI 'kepler_incli' /Prompt "Inclination (°)"
let KEPLER_ROTA 'kepler_rota' /Prompt "Orientation (°)"
let KEPLER_X0 'kepler_x0' /Prompt "RA Offser ("")"
let KEPLER_Y0 'kepler_y0' /Prompt "Dec Offser ("")"
!
gui\button "KEPLER SHOW ALL" SHOW "Show Results" 'hlptxt' "Show Results"
!
let KEPLER_SHOW%LAYOUT 'kepler_show%layout' /Prompt "Layout"
let KEPLER_SHOW%PV 'kepler_show%pv' /Prompt "Show Position-Velocity ?"
let KEPLER_SHOW%PROF 'kepler_show%prof' /Prompt "Show Radial Profile ?"
let KEPLER_SHOW%SPEC 'kepler_show%spec' /Prompt "Show Integrated Spectrum ?"
let KEPLER_SHOW%V 'kepler_show%v[1]' 'kepler_show%v[2]' /Prompt "Velocity Range"
let KEPLER_SHOW%R 'kepler_show%r[1]' 'kepler_show%r[2]' /Prompt "Radius Range"
let KEPLER_SHOW%T 'kepler_show%t[1]' 'kepler_show%t[2]' /Prompt "Temperature Range"
let KEPLER_SHOW%F 'kepler_show%f[1]' 'kepler_show%f[2]' /Prompt "Flux Range"
gui\button "KEPLER SHOW PROFILE" PROFILE "Profile"  'hlptxt' "Show Profile"
let KEPLER_SHOW%R 'kepler_show%r[1]' 'kepler_show%r[2]' /Prompt "Radius Range"
let KEPLER_SHOW%T 'kepler_show%t[1]' 'kepler_show%t[2]' /Prompt "Temperature Range"
gui\button "KEPLER SHOW PV" "R-V"   "Show R-V" 'hlptxt' "R-V Diagram"
let KEPLER_SHOW%V 'kepler_show%v[1]' 'kepler_show%v[2]' /Prompt "Velocity Range"
let KEPLER_SHOW%R 'kepler_show%r[1]' 'kepler_show%r[2]' /Prompt "Radius Range"
let KEPLER_SHOW%T 'kepler_show%t[1]' 'kepler_show%t[2]' /Prompt "Temperature Range"
let KEPLER_SHOW%F 'kepler_show%f[1]' 'kepler_show%f[2]' /Prompt "Flux Range"


gui\button "KEPLER SHOW SPECTRUM" SPECTRUM "Show Spectrum" 'hlptxt' "Show Spectrum"
let KEPLER_SHOW%V 'kepler_show%v[1]' 'kepler_show%v[2]' /Prompt "Velocity Range"
let KEPLER_SHOW%F 'kepler_show%f[1]' 'kepler_show%f[2]' /Prompt "Flux Range"
gui\button "KEPLER SHOW VELO" FIELD "Show Velocity Field" 'hlptxt' "Velocity Field"
let size 'size[1]' 'size[2]' /Prompt "Field Size ("")" 
gui\go
!
begin procedure kepler-save
sic output memory-kepler.ima
say "let KEPLER_VDISK "'kepler_vdisk' ! /Prompt "Disk Systemic Velocity" 
say "let KEPLER_USEVDISK "'kepler_usevdisk' ! /Prompt "Use Disk Velocity" 
say "let KEPLER_AZIMUT "'kepler_azimut[1]' 'kepler_azimut[2]' ! /Prompt "Azimut Range (°)"
say "let KEPLER_THETA "'kepler_theta' ! /Prompt "Max Angle from Major axis (°)"
say "let KEPLER_DIST "'kepler_dist' ! /Prompt "Distance (pc)"
say "let KEPLER_STEP "'kepler_step' ! /Prompt "Radial Step (au)" 
say "let KEPLER_RINT "'kepler_rint' ! /Prompt "Inner disk radius (au)"
say "let KEPLER_ROUT "'kepler_rout' ! /Prompt "Outer disk radius (au)"
say "let KEPLER_RMIN "'kepler_rmin' ! /Prompt "Minimum radius (au)"
if exist(kepler_rmax)  say "let KEPLER_RMAX "'kepler_rmax' ! /Prompt "Maximum radius (au)"
say "let KEPLER_VMASS "'kepler_vmass' ! /Prompt "Rotation Velocity at 100 au"
say "let KEPLER_INCLI "'kepler_incli' ! /Prompt "Inclination (°)"
say "let KEPLER_ROTA "'kepler_rota' ! /Prompt "Orientation (°)"
say "let KEPLER_X0 "'kepler_x0' ! /Prompt "RA Offser ("")"
say "let KEPLER_Y0 "'kepler_y0' ! /Prompt "Dec Offser ("")"
say "!"
say "let KEPLER_SHOW%V "'kepler_show%v[1]' 'kepler_show%v[2]' ! /Prompt "Velocity Range"
say "let KEPLER_SHOW%R "'kepler_show%r[1]' 'kepler_show%r[2]' ! /Prompt "Radius Range"
say "let KEPLER_SHOW%T "'kepler_show%t[1]' 'kepler_show%t[2]' ! /Prompt "Temperature Range"
say "let KEPLER_SHOW%F "'kepler_show%f[1]' 'kepler_show%f[2]' ! /Prompt "Flux Range"
sic output 
end procedure
