!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Setup new project structure
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure 30m-setup-proj-definitions
  if .not.exist(setup30m%proj) then
     define structure setup30m%proj /global
  endif
  if .not.exist(setup30m%proj%inp) then
     define structure setup30m%proj%inp /global
     define character setup30m%proj%inp%nick*32 /global
     define character setup30m%proj%inp%id*32 setup30m%proj%inp%pi*32 /global
     define character setup30m%proj%inp%obs*32 setup30m%proj%inp%oper*32 /global
     ! Commands
     define command 30MSETUP\PROJECT   "@ 30m-setup-project"
  endif
end procedure 30m-setup-proj-definitions
!
begin procedure 30m-setup-proj-defaults
  let setup30m%proj%inp%nick "16314"
  let setup30m%proj%inp%id "314-16"
  let setup30m%proj%inp%pi "the-pi"
  let setup30m%proj%inp%obs "the-observer"
  let setup30m%proj%inp%oper "pako"
end procedure 30m-setup-proj-defaults
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Actions
!
begin procedure 30m-setup-proj-dump-inp
  say "Project input parameters:"
  say " * Project nickname:       "'setup30m%proj%inp%nick'
  say " * Project official id:    "'setup30m%proj%inp%id'
  say " * Principal Investigator: "'setup30m%proj%inp%pi'
  say " * Observer:               "'setup30m%proj%inp%obs'
  say " * Operator:               "'setup30m%proj%inp%oper'
end procedure 30m-setup-proj-dump-inp
!
begin procedure 30m-setup-proj-init
  let setup30m%dir%hard "ha/"
  let setup30m%dir%log "log/"
  let setup30m%dir%pro 'setup30m%proj%inp%nick'"/"
  !
  sic mkdir 'setup30m%dir%pro'
  sic mkdir 'setup30m%dir%hard'
  sic mkdir 'setup30m%dir%log'
  !
  let setup30m%file%proj 'setup30m%dir%pro'"general.pako"
  let setup30m%file%sour 'setup30m%dir%pro''setup30m%proj%inp%nick'".sou"
  let setup30m%file%spec 'setup30m%dir%pro''setup30m%proj%inp%nick'"-spec.lin"
  let setup30m%file%line 'setup30m%dir%pro''setup30m%proj%inp%nick'"-line.lin"
  let setup30m%file%log  'setup30m%dir%log''setup30m%proj%inp%nick'
  !
  ! A new project restart the numbering of the setups
  @ 30m-setup-new 1
  !
!  @ 30m-setup-spec-open
!  @ 30m-setup-line-open
end procedure 30m-setup-proj-init
!
begin procedure 30m-setup-proj-create-pro
  sic output 'setup30m%file%proj'
    say "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    say "!"
    say "sic priority"
    say "sic priority 1 pako"
    say "set project  "'setup30m%proj%inp%id'
    say "set pi       "'setup30m%proj%inp%pi'
    say "set observer "'setup30m%proj%inp%obs'
    say "set operator "'setup30m%proj%inp%oper'
    say "set angleunit arcsec"
    say "set topology low"
    say "set level 3 3"
    say "show"
    say "set dosubmit no"
    say "catalog sou ~/"'setup30m%file%sour'
    say "catalog lin ~/"'setup30m%file%spec'
    say "!"
    say "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  sic output
end procedure 30m-setup-proj-create-pro
!
begin procedure 30m-setup-proj-open
  @ 30m-setup-proj-init
  @ 30m-setup-proj-create-pro
end procedure 30m-setup-proj-open
!
begin procedure 30m-setup-proj-close
  ! Does nothing for the moment
end procedure 30m-setup-proj-close
!
begin procedure 30m-setup-proj-clean
  @ 30m-setup-proj-init
  sys "rm -rf "'setup30m%dir%pro'
  sys "rm -rf "'setup30m%dir%hard'
  sys "rm -rf "'setup30m%dir%log'
end procedure 30m-setup-proj-clean
!
begin procedure 30m-setup-proj-nick
  let setup30m%proj%inp%nick 'pro%arg[1]'
end procedure 30m-setup-proj-nick
!
begin procedure 30m-setup-proj-id
  let setup30m%proj%inp%id 'pro%arg[1]'
end procedure 30m-setup-proj-id
!
begin procedure 30m-setup-proj-pi
  let setup30m%proj%inp%pi 'pro%arg[1]'
end procedure 30m-setup-proj-pi
!
begin procedure 30m-setup-proj-obs
  let setup30m%proj%inp%obs 'pro%arg[1]'
end procedure 30m-setup-proj-obs
!
begin procedure 30m-setup-proj-oper
  let setup30m%proj%inp%oper 'pro%arg[1]'
end procedure 30m-setup-proj-oper
!
begin procedure 30m-setup-project
  if (pro%narg.ge.1) then
     if ((pro%arg[1].eq."open").or.(pro%arg[1].eq."close").or.(pro%arg[1].eq."clean")) then
        @ 30m-setup-proj-'pro%arg[1]'
     else if ((pro%narg.ge.2).and.(pro%arg[1].eq."nick").or.(pro%arg[1].eq."id").or.(pro%arg[1].eq."pi").or.(pro%arg[1].eq."obs").or.(pro%arg[1].eq."oper")) then
        @ 30m-setup-proj-'pro%arg[1]' 'pro%arg[2]'
     else
        message e 30m-setup-project "Usage: PROJECT OPEN|CLOSE|CLEAN"
        message e 30m-setup-project "   or: PROJECT NICK|ID|PI|OBS|OPER ARG"
        return base
     endif
  endif
end procedure 30m-setup-project
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Widget
!
begin procedure 30m-setup-proj-widget
  gui\panel "30m Heterodyne Setup Facility (J.Pety, C.Buchbender, P.Gratier)" gag_scratch:30m-setup.hlp
     @ 30m-setup-widget-step proj
     gui\button "@ 30m-setup-proj-open"  "Set project"
     gui\button "@ 30m-setup-proj-init"  "Set another nickname"
     gui\button "@ 30m-setup-proj-clean" "Clean project (Be careful)"
     let setup30m%proj%inp%nick 'setup30m%proj%inp%nick' /prompt "Nickname"
     say ""
     say "Project parameters"
     let setup30m%proj%inp%id 'setup30m%proj%inp%id' /prompt "Project ID"
     let setup30m%proj%inp%pi 'setup30m%proj%inp%pi' /prompt "Principal investigator"
     let setup30m%proj%inp%obs 'setup30m%proj%inp%obs' /prompt "Observer"
     let setup30m%proj%inp%oper "pako" /prompt "Operator"
  gui\go ""
end procedure 30m-setup-proj-widget
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
