!-*-f90-*-
! MAIN procedure is at the end of file ...
! this procedure may be called from CLIC too:
if .not.exist(astro) then
  let astro (sic%program.eq."astro") /new logical global
endif
if .not.exist(clic) then
  let clic (sic%program.eq."clic") /new logical global
endif
on error return
!
! define non-x procedures:
@ newproject.astro
if (astro) then
   @ newproject-astro.astro
endif
!------------------------------------------------------------------------------
begin help project_input1.hlp

Project definition procedure                               R. Lucas 06-apr-1999

In this procedure we input parameters for a given project. These parameters
will be used to create/check the observing setup file, and to prepare the
CLIC table creating procedures. In this first window you should enter
the number of program sources for the project, the number of continuum tables,
and the number of line tables.

Active Buttons:
---------------
INPUT
	Enter a second window to fill in the project parameters.
SETUP
	In Astro: create the setup procedure, the source catalog and the
	table creation 	procedures.
	In CLIC: create only the table creation procedures.
SAVE
	Save the current values of project parameters in a file 'proj.pro'
RESTORE
	Restore  project parameters from the 'proj.pro' file.
PLOT R1
	(in ASTRO only) Plot the receiver 1 frequency setup
PLOT R2
	(in ASTRO only) Plot the receiver 2 frequency setup
CALIBR.
	(in ASTRO only) Plot the calibrators
TABLES
	(in CLIC only) go to the panel to create the tables.
RESET
	Restart the procedure, enabling input of primary parameters such as
	project id, number of sources, cont tables, line tables.
GO
	Same as 'SETUP'.

2 PROJ
	The project name as an up to eight letter code.

2 N_SOURCES
	The number of project sources

2 N_CONT
	The number of different continuum tables (usually two: 1mm and 3mm).

2 N_LINE
	The number of line tables
	(can be many if several transitions are simultaneously observed).
end help project_input1.hlp
!------------------------------------------------------------------------------
begin procedure project_input1
   if .not.exist(n_cont) then
      define integer n_cont n_line n_sources /global
      let n_cont 1
      let n_line 1
      let n_sources 1
   end if
   if .not.exist(do_line) then
      define logical do_line do_cal /global
   end if
   let do_line yes
   let do_cal  yes
   if .not.exist(proj) then
      define character proj*8 /global
   end if
   gui\panel "Create project procedure" project_input1.hlp
   let proj  'proj'       /prompt "Project name ?"
   let n_sources	'n_sources'	/prompt "number of sources ?"
   let n_cont  	'n_cont' 	/prompt "number of continuum tables ?"
   let n_line	'n_line'	/prompt "number of line tables ?"
   gui\button "@ project_input"    "INPUT"
   gui\button "@ project_restore"  "RESTORE"
   gui\button "@ project_save"     "SAVE"
   if (astro) then
      gui\button "@ project_plot 1 "   "PLOT R1"
      gui\button "@ project_plot 2 "   "PLOT R2"
      gui\button "@ calibrators "      "CALIBR."
      gui\button "@ project_setup"    "SETUP"
      gui\button "@ newproject-print"        "PRINT"
   else if (clic) then
      gui\button "@ project_setup"    "PROCEDURES"
      if ("&1?".eq."SINGLE?") then
        gui\button "@ x_newtable_single"    "TABLES"
      else
        gui\button "@ x_newtable"           "TABLES"
      endif
      sic out
   endif
   gui\go     "@ project_setup"
end procedure project_input1
!------------------------------------------------------------------------------
begin help project_input.hlp
1 Description
Project parameters input procedure                         R. Lucas 06-apr-1999

In this procedure we input parameters for a given project. These parameters
will be used to create/check the observing setup file, and to prepare the
CLIC table creating procedures. In this window you may select the
project source, line table or continuum table. Press the corresponding
'parameters' button.

Active Buttons:
---------------
SETUP
	Create the setup procedure, the source catalog and the table creation
	procedures.
SAVE
	Save the current values of project parameters in a file 'proj.pro'
RESTORE
	Restore  project parameters from the 'proj.pro' file.
PLOT R1
	Plot the receiver 1 frequency setup
PLOT R2
	Plot the receiver 2 frequency setup
CALIBR.
	Plot the calibrators
RESET
	Restart the procedure, enabling input of primary parameters such as
	project id, number of sources, cont tables, line tables.
GO
	Same as 'Setup'.

end help project_input.hlp
!------------------------------------------------------------------------------
begin help source_input.hlp
Source definition:
-----------------
The source parameters are used to prepare the observing setup and the table
creation procedures.
Inputs:
-------
2 SOURCENAME_1
	Name of the source (less than 12 characters)
2 RA2000_1
  	Right ascension (J2000) in sexagesimal coordinates
	format is  hh:mm:ss.ssss
2 DEC2000_1
  	Declination (J2000) in sexagesimal coordinates
	format is  sdd:mm:ss.ssss
2 VLSR_1
	Local Standard of Rest velocity in km/s.
	For extragalactic objects, the recommended practice is to
	correct the frequency for redshift and enter zero velocity.
2 NFIELD_1
	Number of fields for mosaics
2 XFIELD_1
	RA  offsets of the field centers, in arc seconds, separated by blank
	spaces
2 YFIELD_1
	Declinaton  offsets of the field centers, in arc seconds,
	separated by blank spaces.
2 TFIELD_1
	Time to be spent in each field, in minutes of time (integer)
end help   source_input.hlp
!------------------------------------------------------------------------------
begin help spectral_input.hlp
Spectral setup definition
-------------------------
All these parameters are needed to specify the continuum and line
tables that will be built, as well as the frequency setup of the
receivers and of the correlator units.  Pressing the GO button will
prepare the observing setup and table creation procedures.

Inputs:
-------
2 CONTTABLE_1
	Name of the output continuum table
2 CONTBANDS_1
	Frequency limits to be used for the continuum table. Enter a list
	of frequency intervals (for each interval give the start rest
	frequency and end rest frequency in MHz). These intervals are
	used to exclude lines from the continuum data. They are also used
	to prepare the correlator setup.
2 LINETABLE_1
	Name of the output line table
2 LINENAME_1
	Name of the line transition, e.g. CO(J=2-1)
2 LINEFREQ_1
	Rest frequency of the line transition, in MHz
2 LINEVELO_1
	Velocity range to be tabulated, in km/s: start and end velocity,
	separated by blank space.
2 LINEVRES_1
	Velocity resolution (separation between channels), in km/s.
end help   spectral_input.hlp
!------------------------------------------------------------------------------
begin procedure project_input
   define character text*80
   gui\panel "Input parameters for Project" project_input.hlp
   let proj 'proj' /lower
   let proj 'proj' /lower
   sic\say 'proj'": "'n_sources'" source(s) "'n_cont'" continuum table(s) "'n_line'" line table(s)"
!
! Spectral parameters
! continuum
   if n_cont.gt.0 then
     for i 1 to n_cont
        gui\button " " "Spectral"'i' " " spectral_input.hlp -
           "Spectral "'i'" parameters"
        if .not.exist(conttable_'i') then
           define character conttable_'i'*20 contbands_'i'*80 /global
           let conttable_'i' [unknown]
           let contbands_'i' "0 380000."
        end if
        let text conttable_'i' /format a80
        sic\let conttable_'i'    'text' /prompt "Cont table # "'i'" name"
        let text contbands_'i' /format a80
        sic\let contbands_'i'    'text' /prompt "Frequency bands (MHz)"
     next
   end if
!
! line
   if n_line.gt.0 then
     for i 1 to n_line
        gui\button " " "Line "'i' " "  line_input.hlp -
           "Line "'i'" parameters"
        if .not.exist(linetable_'i') then
           define character linetable_'i'*20 /global
           define character linename_'i'*20  /global
           define character linevelo_'i'*80  /global
           define double linefreq_'i'        /global
           define double linevres_'i'        /global
           let linetable_'i' [unknown]
           let linename_'i' [unknown]
           let linevelo_'i' "-10 10"
           let linefreq_'i' 100000.000
           let linevres_'i' 1
        end if
        let text linetable_'i' /format a80
        sic\let linetable_'i' 'text'    /prompt "Line Table # "'i'" name"
        let text linename_'i' /format a80
        sic\let linename_'i'  'text'    /prompt "Line name"
        let text linefreq_'i' /format f16.3
        sic\let linefreq_'i' 'text'   /prompt "Line frequency (MHz)"
        let text linevelo_'i' /format a80
        sic\let linevelo_'i' 'text'     /prompt "Velocity range (km/s)"
        let text linevres_'i' /format f16.3
        sic\let linevres_'i' 'text'     /prompt "Velocity resolution (km/s)"
     next
  endif
!
! source parameters
!
   for i 1 to n_sources
      gui\button " " "Source "'i' " " source_input.hlp "parameters"
      if .not.exist(sourcename_'i') then
         define character sourcename_'i'*12 ra2000_'i'*16 dec2000_'i'*16 -
               xfield_'i'*120 yfield_'i'*120 tfield_'i'*120 /global
         define double vlsr_'i' /global
         define integer nfield_'i' /global
        let sourcename_'i' [unknown]
        let ra2000_'i' 00:00:00.000
        let dec2000_'i' 00:00:00.000
        let vlsr_'i' 0
        let nfield_'i' 0
        let xfield_'i' 0
        let yfield_'i' 0
        let tfield_'i' 0
      end if
      let text sourcename_'i' /format a12
      sic\let sourcename_'i'    'text' /prompt "Source "'i'" name"
      let text ra2000_'i' /format a16
      sic\let ra2000_'i'    'text' /prompt  " RA(J2000)  hh:mm:ss.sss"
      let text dec2000_'i' /format a16
      sic\let dec2000_'i'    'text' /prompt "DEC(J2000) sdd:mm:ss.sss"
      let text vlsr_'i' /format f10.3
      sic\let vlsr_'i' 'text'     /prompt   "LSR Velocity (km/s)"
      say "Mosaic for Source "'i'":"
      let text  nfield_'i' /format i3
      sic\let nfield_'i' 'text' /prompt "Number of fields"
      let text  xfield_'i' /format a120
      sic\let xfield_'i' 'text' /prompt "X coordinates ("")"
      let text  yfield_'i' /format a120
      sic\let yfield_'i' 'text' /prompt "Y coordinates ("")"
      let text  tfield_'i' /format a120
      sic\let tfield_'i' 'text' /prompt "Times (min.)"
   next
   gui\button "@ project_restore"  "RESTORE"
   gui\button "@ project_save"     "SAVE"
   if (astro) then
      gui\button "@ project_plot 1"   "PLOT R1"
      gui\button "@ project_plot 2"   "PLOT R2"
      gui\button "@ calibrators "      "CALIBR."
      gui\button "@ project_setup"    "SETUP"
      gui\button "@ newproject-print"        "PRINT"
   else if (clic) then
      gui\button "@ project_setup"    "SETUP"
      if ("&2?".eq."SINGLE?") then
        gui\button "@ x_newtable_single"    "TABLES"
      else
        gui\button "@ x_newtable"           "TABLES"
      endif
      sic out
   endif
   gui\button "@ x_newproject.astro RESET"     "RESET"
   gui\go     "@ project_setup"
end procedure project_input
!------------------------------------------------------------------------------
! MAIN procedure: x_newproject
!------------------------------------------------------------------------------
!*!sic verif on
if exist(project) then
   if .not.exist(proj) then
      define character proj*8 /global
   end if
   if (.not.isaod) then    ! rn
     let proj 'project'
   else
     let proj 'project' /lower    ! rn
     let proj 'project' /lower    ! rn
   end if
   say "Restoring parameters for project " 'proj'
   @ project_restore
endif
if .not.exist(project_entered) then
   @ project_input1 &2
   return
endif
if "&1?".eq."RESET?" then
   @ project_input1
   return
endif
!
! normally do something ...
return
