!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Setup source
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin data gag_scratch:reproject.init
  TASK\FILE "Input file" Z_NAME$ 'name'"."'type'
  TASK\FILE "Output file" X_NAME$ 'name'"-rep."'type'
  TASK\LOGICAL "Reproject on a third file's projection [YES|NO]" TEMPLATE$ NO
  SAY "If you answered YES,  enter the file name below:"
  TASK\FILE "This Template File Name" Y_NAME$ ""
  SAY "If not, fill the form below:"
  TASK\CHARACTER "Projection type" PROJECTION$ RADIO /CHOICE     NONE GNOMONIC ORTHOGRAPHIC  AZIMUTHAL STEREOGRAPHIC LAMBERT AITOFF RADIO
  TASK\CHARACTER "Coord.System [EQUATORIAL [epoch]|GALACTIC]" SYSTEM$ "EQUATORIAL 2000" /CHOICE "EQUATORIAL 2000" "EQUATORIAL 1950" "GALACTIC" "UNCHANGED"
  TASK\CHARACTER "Coord. 1 of projection center. Could be UNCHANGED"     CENTER_1$ 'setup30m%source%inp%ra' /CHOICE UNCHANGED *
  TASK\CHARACTER "Coord. 2 of projection center" CENTER_2$ 'setup30m%source%inp%dec' /CHOICE UNCHANGED *
  TASK\REAL "Position angle of projection" ANGLE$ 0.0 /RANGE 0 360
  TASK\INTEGER "Dimensions of output image [0 0 mean guess]" DIMENSIONS$[2]    0 0
  TASK\REAL "First axis conversion formula [0 0 0 mean guess]" AXIS_1$[3]   0 0 0
  TASK\REAL "Second axis conversion formula [0 0 0 mean guess]" AXIS_2$[3]   0 0 0
  TASK\LOGICAL "Change blanking value" CHANGE$ NO
  SAY "If you answered YES,  enter the new blanking value below:"
  TASK\REAL "New blanking value and tolerance" BLANKING$[2] 0 0
  TASK\GO
end data gag_scratch:reproject.init
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure 30m-setup-source-definitions
  if .not.exist(setup30m%source) then
     define structure setup30m%source /global
  endif
  !
  if .not.exist(setup30m%source%inp) then
     define structure setup30m%source%inp /global
     define character setup30m%source%inp%name*12 /global
     define character setup30m%source%inp%ra*12 setup30m%source%inp%dec*12 /global
     define double setup30m%source%inp%vlsr /global
     ! Commands
     define command 30MSETUP\SOURCAT  "@ 30m-setup-source-cat"
     define command 30MSETUP\SOURVIS  "@ 30m-setup-source-vis"
     define command 30MSETUP\SOURIMA  "@ 30m-setup-source-ima"
     define command 30MSETUP\SOURREP  "@ 30m-setup-source-rep"
  endif
end procedure 30m-setup-source-definitions
!
begin procedure 30m-setup-source-defaults
  let setup30m%source%inp%name "horsehead"
  let setup30m%source%inp%ra  "05:40:54.2700"
  let setup30m%source%inp%dec "-02:28:00.000"
  let setup30m%source%inp%vlsr 10.5 ! km/s
  let do_rcoord yes ! Relative coordinate by default
end procedure 30m-setup-source-defaults
!
begin procedure 30m-setup-source-reset-out
  !
  !
end procedure 30m-setup-source-reset-out
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Actions
!
begin procedure 30m-setup-source-dump-inp
  say "Source input parameters:"
  say " * Source name:         "'setup30m%source%inp%name'
  say " * EQ 2000 coordinates: "'setup30m%source%inp%ra'" "'setup30m%source%inp%dec'
  say " * Vlsr [km/s]:         "'setup30m%source%inp%vls'
end procedure 30m-setup-source-dump-inp
!
begin procedure 30m-setup-source-cat-open
  sic delete 'setup30m%file%sour'
  sic output 'setup30m%file%sour'
    say "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    say "! Source catalog for project "'setup30m%proj%inp%id'
    say "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    say "!"
end procedure 30m-setup-source-cat-open
!
begin procedure 30m-setup-source-cat-add
    say 'setup30m%source%inp%name' " EQ 2000 " 'setup30m%source%inp%ra' " " -
        'setup30m%source%inp%dec' " LSR " 'setup30m%source%inp%vlsr' /format a a a a a a f8.2
end procedure 30m-setup-source-cat-add
!
begin procedure 30m-setup-source-cat-close
    say "!"
    say "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  sic output
end procedure 30m-setup-source-cat-close
!
begin procedure 30m-setup-source-vis
  observatory veleta
  set azimuth north ! This is PV, not Bure!
  sic date
  time 00:00:00.000 'sys_date'
  cata 'setup30m%file%sour'
  horizon /source /planet /night
  let setup30m%file%vis 'setup30m%dir%hard''setup30m%proj%inp%nick'"-vis"
  ha 'setup30m%file%vis' /dev png /over
end procedure 30m-setup-source-vis
!
begin procedure 30m-setup-source-parse
  if (pro%narg.eq.1) then
     if file(pro%arg[1]) then
        define character dir*512
        sic parse 'pro%arg[1]' name type dir
!        exa pro%arg[1] dir name type ! *** JP
        let name 'dir''name'
        if (name.eq." ") then
           message e sourima "Please set the basename of your image file"
           return base
        else
           message i sourima "Variable NAME set to "'name'
        endif
        if (type.eq." ") then
           message e sourima "Please set the extension of your image file"
           return base
        else
           message i sourima "Variable TYPE set to "'type'
        endif
        delete /var dir
        tickspace 0 0 0 0
     else
        message e sourima "Unknown file: "'pro%arg[1]'
        return base
     endif
  else
        message e sourima "Usage: SOURIMA full-filename"
        return base
  endif
end procedure 30m-setup-source-parse
!
begin procedure 30m-setup-source-ima
  @ 30m-setup-source-parse &1
  go nice
end procedure 30m-setup-source-ima
!
begin procedure 30m-setup-source-rep
  @ 30m-setup-source-parse &1
  run reproject gag_scratch:reproject.init /nowin
  let name 'name'"-rep"
  message i sourrep "Name set to: "'name'
  v\header 'name'"."'type' /extrema
  go nice
end procedure 30m-setup-source-rep
!
begin procedure 30m-setup-source-show
  @ 30m-setup-source-&1 'name'"."'type'
end procedure 30m-setup-source-show
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Commands
!
begin procedure 30m-setup-source-cat
  if (pro%narg.eq.1) then
     if ((pro%arg[1].eq."open").or.(pro%arg[1].eq."close")) then
        @ 30m-setup-source-cat-'pro%arg[1]'
     else
        message e 30m-setup-source "Usage: SOURCAT OPEN|ADD|CLOSE name ra dec vlsr"
        return base
     endif
  else if (pro%narg.eq.5) then
     let setup30m%source%inp%name 'pro%arg[2]'
     let setup30m%source%inp%ra   'pro%arg[3]'
     let setup30m%source%inp%dec  'pro%arg[4]'
     let setup30m%source%inp%vlsr 'pro%arg[5]'
     if (pro%arg[1].eq."add") then
        @ 30m-setup-source-cat-'pro%arg[1]'
     else
        message e 30m-setup-source "1st argument must be ADD"
        return base
     endif
  else
     message e 30m-setup-source "Usage: SOURCAT OPEN|ADD|CLOSE name ra dec vlsr"
     return base
  endif
end procedure 30m-setup-source-cat
!
begin procedure 30m-setup-source-sel
  if (pro%narg.eq.1) then
     let setup30m%source%inp%name 'pro%arg[1]'
  else
     message e 30m-setup-source "Usage: SOURSEL name"
     return base
  endif
end procedure 30m-setup-source-sel
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Widget
!
begin procedure 30m-setup-source-widget
  gui\panel "30m Heterodyne Source Setup Facility (J.Pety)" gag_scratch:30m-setup-source.hlp
     @ 30m-setup-widget-step source
     gui\menu "CATALOG" /choices
        gui\button "@ 30m-setup-source-cat-open" "Open catalog"
        gui\button "@ 30m-setup-source-cat-add" "Add source to catalog"
        gui\button "@ 30m-setup-source-cat-close" "Close catalog"
        gui\button "type 'setup30m%file%sour'" "Dump catalog"
     gui\menu /close
     gui\button "@ 30m-setup-source-vis" "Show visibility"
     gui\menu "IMAGE" /choices
        gui\button "@ 30m-setup-source-show ima" "Show image"
        gui\button "@ 30m-setup-source-show rep" "Reproject image on current source"
     gui\menu /close
     say "Next source in catalog"
     let setup30m%source%inp%name 'setup30m%source%inp%name' /prompt "Source name"
     let setup30m%source%inp%ra  'setup30m%source%inp%ra' /prompt "Equatorial 2000 Right Ascension [hh:mm:ss.ssss]"
     let setup30m%source%inp%dec 'setup30m%source%inp%dec' /prompt "Equatorial 2000 Right Declination [+/-dd:mm:ss.sss]"
     let setup30m%source%inp%vlsr 'setup30m%source%inp%vlsr' /prompt "LSR velocity [km/s]"
     @ 30m-setup-widget-image
     @ 30m-setup-widget-status
  gui\go ""
end procedure 30m-setup-source-widget
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
