#! /bin/csh -f
#jhz 2015-10-20
#jhz 2016-01-12
#jhz 2016-01-27
#jhz 2016-01-28 make a templet using sma data:
#               160116_03:45:40
#
#jhz 2016-05-06 imaging SiO line             
echo "                                                                      "
echo "######################################################################"
echo "specially for the project 2015B-S044 - a narrow line system           "
echo "######################################################################"
#
#set the name of the SMA raw data
#
set file = 151226_04:17:44
echo ''
echo $file
#
set dt          = 151226 
#
echo ' '
echo 'prefix of data files = ' $dt
echo ' '
#
set hour        = 04:17:44
set sb          = usb
set nn          = 1 
set rxid        = 0
set rx          = rx${rxid}
set adge        = 5 
set nchan_as    = 1750
set maxtsys     = 500
set maxspw      = 2 
set fname       = "$dt""_""$rx".$sb
set oname       = "$dt""_""$rx"
set fcal        = callisto 
set gcal1       = 0501-019
set gcal2       = 0607-085 
set gcal        = $gcal1  
set bcal        = 3C279,3c454.3
set font        = sOri-2
set refant      = 1 
set avetime     = 5
set source      = $font
#twogcal    =  T two gain calibrators' scheme
#twogcal    =  F one ain calibrator scheme
set twogcal     = T
#
set sline = SiO54
set rfreq = 217.1049800 
set imnameA = ${font}.${sline}
#set linetype = vel,400,-25,0.25
set linetype = vel,20,-20,5
#set image
set niter = 2500
set fwhm  = 5,5
set rms   = 0.02
#
#goto NLINE
goto LNMAP
#goto LDISP
#goto STATS
goto MOMEN
goto MDISP
#goto UVFITS          # export calibrated data in UVFITS
#goto ZAP             # clean 
NLINE:
puthd in=151226.SiO54.uv/restfreq value=$rfreq type=real
prthd in=151226.SiO54.uv
set source = sOri-2
echo 'source=' $source
LNMAP:
set lineuv = 151226.SiO54.uv 
#smablflag vis=$lineuv axis=time,amp \
#        options=nobase device=/xs select='source('$source')'
#smauvspec vis=$lineuv axis=vel,both device=/xs options=avall,nobas
$<
\rm -r $imnameA.map $imnameA.beam $imnameA.icmp
invert vis=$lineuv map=$imnameA.map beam=$imnameA.beam \
        imsize=512 cell=0.5 sup=0 options=systemp \
        line=$linetype 
$<
cgdisp in=$imnameA.map type=pixel region=arcsec,'boxes(-50,-50,50,50)(1,20)' \
        xybin=1,1 device=/xs nxy=5,4 options=full,beambr,wedge,trlab,3val \
        labtyp=arcsec,arcsec range=0,0,lin,2 cols1=7 csize=0.5,0.5,0.5
$<
clean map=$imnameA.map beam=$imnameA.beam out=$imnameA.icmp gain=0.08 \
        cutoff=$rms niters=$niter \
        region=arcsec,'boxes(-4,-4,4,4)(1,20)'
$<
\rm -r $imnameA.icln
restor model=$imnameA.icmp beam=$imnameA.beam map=$imnameA.map  \
        out=$imnameA.icln 
#fwhm=$fwhm
$<
LDISP:
cgdisp in=$imnameA.icln type=pixel \
        region=arcsec,'boxes(-45,-45,45,45)(1,20)' \
        xybin=1,1 device=/xs \
        nxy=4,5 options=beambr,wedge,blacklab,3val \
        labtyp=arcsec,arcsec range=0,0,lin,2 cols1=7 csize=0.5,0.5,0.5
STATS:
imstat in=$imnameA.icln region=arcsec,'boxes(-25,-25,22,22)' \
         axes=ra,dec
$<
MOMEN:
imspect in=$imnameA.icln region=arcsec,'boxes(-1,-1,1,1)(1,20)' \
	device=/xs yrange=-0.5,0.5. 
\rm -r $imnameA.flux
#rms = 0.017
moment in=$imnameA.icln region='quarter(1,20)' out=$imnameA.flux mom=0 \
clip=-10,0.i1
$<
MDISP:
cgdisp in=$imnameA.flux type=pixel \
        region=arcsec,'boxes(-35,-35,35,35)' \
        xybin=1,1 device=/xs \
        nxy=1,1 options=beambr,wedge,blacklab,3val \
        labtyp=arcsec,arcsec range=0,0,lin,2 cols1=7 csize=0.5,0.5,0.5
exit

#
# end of Mapping SiO 
#