1	#! /bin/csh -f
     2	#for RTDC system
     3	#jhz 2018-2-26: initiate a script for developing/testing the prototype
     4	#               program swarm2uvfits
     5	#jhz 2018-4-23: updated for new disk names on RTDC/RG
     6	#jhz 2018-4-26: updated for testing swarmRead for the LSB data               
     7	#jhz 2018-5-02: updated for USB test               
     8	#jhz 2018-5-09: developed swarm2ms.py to execute CASA tasks
     9	#jhz 2018-5-10: exported swarm2ms.py to a bin area where swarmRead
    10	#               is located.
    11	#jhz 2018-5-11: added instruction lines
    12	#jhz 2018-5-24: updated for test on RTDC/RG system
    13	#jhz 2018-5-25: added casa alias to the new distribution 5.1.2
    14	#jhz 2018-5-25: updated for test on Hilo system (hilodr2) 
    15	#               no casa found
    16	#jhz 2018-5-29: added optinx to input variables
    17	#               added alias casa /usr/local/casa-release-4.7.0-1-el6/bin/casa (from Holly)
    18	#               on hilodr1 to test CASA 4.7.0 
    19	#jhz 2018-5-30: options to separate dual rx for CASA measurementSet
    20	#               outputs
    21	#               CASA 4.7.0 seems to not work correctly for SMA data
    22	#               on hilodr1
    23	#jhz 2018-5-31: test swarmio library
    24	#               
    25	date
    26	# --------------------------------------------------------------------
    27	#
    28	# requirement -
    29	#
    30	# RH 6.7 to 6.9; or CentOS 6.7 to 6.9
    31	# CASA 5.1.1 and higher
    32	# --------------------------------------------------------------------
    33	#
    34	# set up c-shell and environment variables -
    35	#
    36	# INPUT_FILE_DIR     - the path of the SMA archived data produced by online 
    37	#                      system with the SWARM correlator
    38	# INPUT_FILE_NAME    - the file name of the SMA archived data that users want
    39	#                      to interpret to measurementSet of CASA
    40	# OUTPUT_FILE_PREFIX - the prefix of output file name,  for example, SMA180506
    41	#                      will result in SMA180506.ms for the data in measurementSet
    42	#                      for CASA       
    43	# PATH               - the location of the executable binary code and the Python 
    44	#                      script
    45	# SEPARATE_DRX       - a handle for daul receiver: 
    46	#                      "Y" to produce two separate RX files in CASA output    
    47	#                      "N" to produce a single dual RX file in CASA output                                                                 
    48	set    INPUT_FILE_DIR = /sma/data/science/mir_data/
    49	set    INPUT_FILE_NAME = 180506_03:52:53 
    50	setenv OUTPUT_FILE_PREFIX SMA180506
    51	set    PATH = /reduction/jzhao/SMA2CASA_TESTING/swarm2measurementSet/bin/ 
    52	set    SEPARATE_DRX    = N
    53	#----------------------------------------------------------------------
    54	echo 'Start swarm2uvfits.csh script -'
    55	echo ''
    56	#
    57	# process start -
    58	#
    59	#for LSB -
    60	$PATH/swarmRead $INPUT_FILE_DIR $INPUT_FILE_NAME $OUTPUT_FILE_PREFIX 0 0
    61	#for USB -
    62	$PATH/swarmRead $INPUT_FILE_DIR $INPUT_FILE_NAME $OUTPUT_FILE_PREFIX 1 0
    63	#
    64	# run CASA batch process -
    65	#
    66	alias casa "/usr/local/casa-release-5.1.2-4.el6/bin/casa"
    67	if($SEPARATE_DRX == "Y") then
    68	casa -c $PATH/swarm2ms_d.py
    69	echo ''
    70	echo 'Two CASA measurementSet data outputs are produced: '
    71	echo $OUTPUT_FILE_PREFIX'_rx1.ms &' $OUTPUT_FILE_PREFIX'_rx2.ms' 
    72	else
    73	casa -c $PATH/swarm2ms_s.py
    74	echo ''
    75	echo 'A single CASA measurementSet data output is produced: '
    76	echo $OUTPUT_FILE_PREFIX'.ms'
    77	endif
    78	echo 'Done, congratulation! exit from the script!'
    79	date
    80	exit