!
! To perform array simulations...
!
input
if (.not.exist(simulate_init)) then
 define character array*24 config*4 /global
 define real radius uvrange /global
 define real dec hour[2] horizon /global
 define integer array_type /global
 define logical simulate_init /global
 define real stretch tau trec phase /global
 define logical do_beams /global
endif
!
! panel for SIMULATE tasks 
!---------------------------------------------------------------------- 
! 
gui\panel "Array simulation" simulate_all.hlp
sic\let name 'name' /prompt "Output Image Name" 
sic\let array 'array' /prompt "Array name"
sic\let config 'config' /prompt "Configuration name"
!
gui\button "run array_layout gag_scratch:simulate_array.init /nowin" -
	ARRAY "Array Layout" simulate_array.hlp "Array Parameters"
sic\let radius 'radius' /prompt "Array size"
sic\let angle 'angle' /prompt "Angle of Reuleaux Triangles"
sic\let stretch 'stretch' /prompt "N-S stretching factor"
sic\let array_type 'array_type' /prompt "Array Type" /index compact - 
 alea_disk ring alea_ring reuleaux alea_reuleaux spiral
!
gui\button "@ simulate_map" -
	MAP "Compute Beam" simulate_map.hlp "Source Parameters"
sic\let dec 'dec' /prompt "Source declination"
sic\let hour 'hour[1]' 'hour[2]' /prompt "Hour angle range"
sic\let horizon 'horizon' /prompt "Minimum Elevation"
sic\let trec 'trec' /prompt "Receiver temperature"
sic\let tau 'tau' /prompt "Zenith opacity"
sic\let phase 'phase' /prompt "Phase noise"
!
gui\button "@ p_array.map" -
	DISPLAY "Display Beam" simulate_display.hlp "Display Parameters"
sic\let do_bit 'do_bit' /prompt "Show bitmap images ?" 
sic\let do_contour 'do_contour' /prompt "Draw contours ?" 
sic\let do_grey 'do_grey' /prompt "Fill contours ?" 
sic\let do_nice yes
sic\let size[1] 'size[1]' /prompt "Display size (arcsec)"
sic\let uvrange 'uvrange' /prompt "UV Range"
!
gui\button "run uv_stat gag_scratch:simulate_taper.init /nowin" -
	TAPERS "Taper behaviour" simulate_taper.hlp "Beam shapes"
sic\let do_beams 'do_beams' /prompt "Create beam file"
gui\button "run uv_stat gag_scratch:simulate_weight.init /nowin" -
	WEIGHT "Weight behaviour" simulate_weight.hlp "Robustness"
sic\let do_beams 'do_beams' /prompt "Create beam file"
on error return 
gui\go 
!
if (simulate_init) then
	return
endif
let array alma
let config b
let name demo
let do_bit yes
let do_contour yes
let radius 500
let stretch 1.1
let dec -60
let hour -0.5 0.5
let trec 40
let tau 0.075
let phase 0
!-----------------------------------------------------------------
begin procedure simulate_map
!
run uv_track gag_scratch:simulate_track.init /nowin
run uv_map gag_scratch:simulate_map.init /nowin
define real ogain 
define integer oiter 
!
let oiter niter
let ogain gain
let gain 0
let niter 1
go clean
let niter oiter
let gain ogain
!
end procedure simulate_map
!-----------------------------------------------------------------
begin data gag_scratch:simulate_track.init
!
! Parameter file for UV_TRACK
TASK\REAL "Source declination" DECLINATION$ 'dec'
TASK\REAL "Line Frequency" FREQUENCY$ 100
TASK\LOGICAL "New or Old table" NEW$ YES
TASK\CHARACTER "Table name" UV_TABLE$ 'name'
TASK\CHARACTER "Station file name" STATION_FILE$ 'array'-'config'.cfg
TASK\REAL "UV spacing" UV_SPACING$ 6.0
TASK\REAL "Antenna Diameter" DIAMETER$ 12.0
TASK\REAL "Minimum Elevation" HORIZON$ 'horizon'
TASK\REAL "Observatory latitude" LATITUDE$ -23.0
TASK\REAL "Hour angle range" HOUR$[2]  'hour[1]' 'hour[2]'
TASK\REAL "Integration time" INTEGRATION$ 0
TASK\REAL "Receiver temperature" TREC$ 'trec'
TASK\REAL "Zenith opacity" TAU$ 'tau'
TASK\REAL "Phase noise" PHASE$ 'phase'
TASK\GO
!
end data gag_scratch:simulate_track.init
!-----------------------------------------------------------------
begin data gag_scratch:simulate_map.init
! 
TASK\FILE "UV table" UV_TABLE$ 'name'
TASK\CHARACTER "Map name" MAP_NAME$ 'name'
TASK\CHARACTER "Weighting mode" WEIGHT_MODE$ "UN"
TASK\REAL "UV taper(1/e level, meters)" UV_TAPER$[3]  0 0 0
TASK\INTEGER "Map size(2)" MAP_SIZE$[2]  128 128
TASK\REAL "Map cell(arc sec)" MAP_CELL$[2]  0 0 
TASK\REAL "UV cell (m)" UV_CELL$[2]  0 0
TASK\LOGICAL "Make one beam (YES), or one per channel (NO)" ONEBEAM$ YES
TASK\INTEGER "Weight channel" WCOL$ 1
TASK\INTEGER "First and Last channel to map" MCOL$[2]  1 1
TASK\INTEGER "Convolution" CONVOLUTION$ 1
TASK\LOGICAL "Shift map" UV_SHIFT$ NO
!
TASK\CHARACTER "Map Center RA" RA_CENTER$ " "
TASK\CHARACTER "Map Center DEC" DEC_CENTER$ " " 
TASK\REAL "Map Position Angle" ANGLE$ 0
!
TASK\GO
!
end data gag_scratch:simulate_map.init
!-----------------------------------------------------------------
begin data gag_scratch:simulate_array.init
!
TASK\CHARACTER "Array name" ARRAY$ 'array'
TASK\CHARACTER "Configuration" CONFIGURATION$ 'config'
TASK\REAL "Longitude (degrees)" LONGITUDE$ -67.7
TASK\REAL "Latitude (degrees)" LATITUDE$ -23.0
TASK\INTEGER "Number of antennas" NANT$ 64
TASK\REAL "Antenna diameter (m)" DIAMETER$ 12.0
TASK\INTEGER "Type of model" MODEL$ 'ARRAY_TYPE'
TASK\REAL "Disk radius" RADIUS$ 'RADIUS'
TASK\REAL "Triangle angle " ANGLE$ 'ANGLE'
TASK\REAL "N-S stretching factor" STRETCH$ 'STRETCH'
TASK\GO
!
end data gag_scratch:simulate_array.init
!-----------------------------------------------------------------
begin data gag_scratch:simulate_taper.init
TASK\FILE "UV table" UV_TABLE$  'name'
TASK\CHARACTER "Checking mode (TAPER or WEIGHT)" UV_MODE$ TAPER
TASK\REAL "UV taper(1/e level, meters)" UV_TAPER$[3] 0 0 0
TASK\REAL "UV cell(m), for unif. weighting" UV_CELL$[2] 0 0 
TASK\INTEGER "Weight channel" WCOL$ 1
TASK\LOGICAL "Save beams on disk ? " DO_BEAMS$ NO
TASK\GO
end data gag_scratch:simulate_taper.init
!
begin data gag_scratch:simulate_weight.init
TASK\FILE "UV table" UV_TABLE$  'name'
TASK\CHARACTER "Checking mode (TAPER or WEIGHT)" UV_MODE$ WEIGHT
TASK\REAL "UV taper(1/e level, meters)" UV_TAPER$[3] 0 0 0
TASK\REAL "UV cell(m), for unif. weighting" UV_CELL$[2] 6.0 1.0
TASK\INTEGER "Weight channel" WCOL$ 1
TASK\LOGICAL "Save beams on disk ? " DO_BEAMS$ DO_BEAMS
TASK\GO
end data gag_scratch:simulate_weight.init
!
let simulate_init yes
