#!/bin/csh -vf

echo $0 CARMA PRIMARY BEAM FITTING 

set FILE = ct007.1C_1003C273.2

goto start

uvindex device=/xs vis=$FILE.miriad

rm -r $FILE.?
uvcal vis=$FILE.miriad options=nopass,nocal select='dra(14.88),ddec(25.76)' out=$FILE.3
uvcal vis=$FILE.miriad options=nopass,nocal select='dra(14.88),ddec(-25.76)' out=$FILE.4
uvcal vis=$FILE.miriad options=nopass,nocal select='dra(-14.88),ddec(25.76)' out=$FILE.5
uvcal vis=$FILE.miriad options=nopass,nocal select='dra(-14.88),ddec(-25.76)' out=$FILE.6
uvcal vis=$FILE.miriad options=nopass,nocal select='dra(-29.75),ddec(0)' out=$FILE.1
uvcal vis=$FILE.miriad options=nopass,nocal select='dra(29.75),ddec(0)' out=$FILE.2
uvcal vis=$FILE.miriad options=nopass,nocal select='dra(0),ddec(0),-source(NOISE)' out=$FILE.0

uvindex vis=$FILE.0
uvindex vis=$FILE.1
uvindex vis=$FILE.2
uvindex vis=$FILE.3
uvindex vis=$FILE.4
uvindex vis=$FILE.5
uvindex vis=$FILE.6

#Flux of: 3C273     09MAR06.00 at  92.3 GHz: 26.79 Jy; rms: 4.02 Jy
#Flux of: 3C273     09MAR06.00 at 228.7 GHz: 13.92 Jy; rms: 2.09 Jy
#Flux of: 3C273     09MAR12.00 at 228.7 GHz: 14.75 Jy; rms: 2.21 Jy
#Flux of: 3C273     09APR03.00 at 227.3 GHz: 10.04 Jy; rms: 1.51 Jy
#/sun2/wright/carma/hex7> calflux source=3c273 in=$MIRCAT/FluxSource.cat

start:
foreach INT ( 20 30 60 )
 foreach N ( 0 1 2 3 4 5 6 )
  mfcal vis=$FILE.$N flux=22. interval=0.2 line=wide
  gpplt device=/xs vis=$FILE.$N.uvcal nxy=5,3
  fitgains vis=$FILE.$N
  gpaver   vis=$FILE.$N options=scalar interval=$INT
  fitgains vis=$FILE.$N
 end

goto hex7

map:
 foreach N ( 0 1 2 3 4 5 6)
  rm -r $FILE.$N.mp $FILE.$N.bm
  invert vis=$FILE.$N.uvcal map=$FILE.$N.mp beam=$FILE.$N.bm imsize=128 cell=.5 options=mfs sup=0
  implot in=$FILE.$N.mp device=/xs
 end 

clean:
 foreach N ( 0 1 2 3 4 5 6)
  rm -r $FILE.$N.cl $FILE.$N.cm
  clean  map=$FILE.$N.mp beam=$FILE.$N.bm out=$FILE.$N.cl 'region=relpix,box(-10,-10,10,10)'
  restor map=$FILE.$N.mp beam=$FILE.$N.bm out=$FILE.$N.cm model=$FILE.$N.cl
  implot in=$FILE.$N.cm device=/xs
 end 

imfit:
 foreach N ( 0 1 2 3 4 5 6)
  rm -r $FILE.$N.rm
  imfit  in=$FILE.$N.cm 'region=relpix,box(-10,-10,10,10)' object=point
 end 

hex7:
 source ~davidm/gemrc.csh
/home/davidm/mmm/davidm/gpfit.rb vis="$FILE.?" options=verbose > $FILE.gpfit.$INT
/home/davidm/mmm/davidm/plotpbfits.rb -r 1.6 -n 4,4 -d /xs $FILE.gpfit.$INT
/home/davidm/mmm/davidm/plotpbfits.rb -r 1.6 -n 4,4 -d $FILE.gpfit.$INT.ps/ps $FILE.gpfit.$INT

end
end:
