1	#! /bin/csh -f
     2	#
     3	#jhz 2015-07-20
     4	#jhz 2015-07-22
     5	#jhz 2015-07-23
     6	#jhz 2015-07-24
     7	#jhz 2015-07-24 for swarm+asic data
     8	#jhz 2016-06-22 for two quadrant swarm + asic
     9	#jhz 2017-09-15 for swarm only in dual receivers
    10	#jhz 2017-10-19 add a note for Miriad versions for this script 
    11	date
    12	echo "                                                                      "
    13	echo "######################################################################"
    14	echo "#   Input: SMA online archived data                                   "
    15	echo "#   Tool:  Miriad SMA-WB5.0.0 and more recent versions                "
    16	echo "#                                                                     "
    17	echo "# swarmDRXload.csh: script to convert SMA data produced from SWARM    "
    18	echo "# correlator sampled with two receivers simultaneously                "
    19	echo "#                                                                     "
    20	echo "#   Production: Two sideband separated datasets -                     "
    21	echo "#               each contains two receiver data                       "
    22	echo "#   Output format: Miriad                                             "
    23	echo "#   Next: further reduction with Miriad SMA-WB5.0.0 or more recent    "
    24	echo "#         versions; or run swarmDRX03pp.csh for rx pair 230 240 or    "
    25	echo "#                          swarmDRX12pp.csh for rx pair 340 400       "
    26	echo "#         to produce datasets for further calibration with globally   "
    27	echo "#         distributed Miriad, CASA and AIPS                           "  
    28	echo "######################################################################"
    29	echo "                                                                      "
    30	############################################################################
    31	#
    32	#begin of users' input
    33	#
    34	#set the name of the SMA raw data
    35	#
    36	set file = 170717_09:31:42 
    37	echo $file
    38	#
    39	#the observing date for the prefix of the output file names 
    40	#
    41	set dt    = 170717
    42	#
    43	#set the data path, e.g. for RTDC in Cambridge, MA
    44	#
    45	#set DATPATH = /2015/science/mir_data/ 
    46	#set DATPATH = /2016/science/mir_data/
    47	#set DATPATH = /2017/science/mir_data/
    48	#
    49	#after 2017 August for RTDC in Cambridge, MA
    50	#set DATPATH = /sma/data/science/mir_data/
    51	#
    52	#set DATPATH = /run/media/miriad/SMAmac1/data/2016
    53	#set DATPATH = /media/8TBBackup/data/2017
    54	set DATPATH = ./
    55	#
    56	#end of users' input
    57	#
    58	#####################################
    59	#                                   #
    60	# The pre-processing routine starts #
    61	#                                   #
    62	#####################################
    63	#
    64	#set the receiver
    65	#
    66	set rxid  = 0       #0 for 230 GHz
    67	                    #1 for 345 GHz
    68	                    #2 for 400 GHz
    69	                    #3 for 240 GHz
    70	                    #for both bands if the data sampled in dual receivers
    71	                    #with the SWARM correlator only. 
    72	set rx    = rx${rxid}
    73	#
    74	#set the sideband
    75	#
    76	set sb    = lsb
    77	set nn    = 0       #0 for lsb 
    78	                    #1 for usb
    79	#
    80	#set number of spectral window for SWARM data
    81	#
    82	set maxspw      = 4 
    83	#
    84	#the handle of switch sideband
    85	#
    86	OTHERSIDEBAND:
    87	set fname = "$dt""_""$rx".$sb
    88	#goto SPLIT-SWARM    #split the swarm chunks
    89	#
    90	#start the pipeline to convert new SMA format to Miriad 
    91	#
    92	SMALOD:
    93	echo "Loading "$sb "data: "$fname
    94	\rm -fr $fname
    95	smalod in=${DATPATH}/$file out=$dt rxif=$rxid \
    96	   options=circular sideband=$nn nscans=0
    97	#
    98	#check the smaloded data with miriad program uvindex
    99	#
   100	\rm -r $fname.uvindex.log
   101	uvindex vis=$fname log=$fname.uvindex.log
   102	#
   103	echo "Successfully inspected vis=" $fname
   104	echo " "
   105	echo "done with sb -" $sb
   106	echo "reset sideband parameter -"
   107	echo " "
   108	set sb    = usb
   109	set nn    = 1       #0 for lsb 
   110	                    #1 for usb
   111	set fname = "$dt""_""$rx".$sb
   112	echo "Loading "$sb "data: "$fname
   113	\rm -fr $fname
   114	smalod in=${DATPATH}/$file out=$dt rxif=$rxid \
   115	   options=circular sideband=$nn nscans=0,
   116	#
   117	##check the smaloded data with miriad program uvindex
   118	#
   119	\rm -r $fname.uvindex.log
   120	uvindex vis=$fname log=$fname.uvindex.log
   121	#
   122	#echo "Successfully inspected vis=" $fname
   123	echo " "
   124	echo "done with sb -" $sb 
   125	echo " "
   126	echo "End the pre-processing successfully!"
   127	echo " "
   128	##########################
   129	#                        #
   130	# End of the pre-process #
   131	#                        #
   132	##########################
   133	date
   134	exit