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