1	#! /bin/csh -f
     2	#For HILO System
     3	#jhz 2018-2-26: intiate 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: update for testing swarmRead for the LSB data               
     7	#jhz 2018-5-02: update for USB test               
     8	#jhz 2018-5-09: develop swarm2ms.py to execute CASA tasks
     9	#jhz 2018-5-10: export swarm2ms.py a bin area where swarmRead
    10	#               is located.
    11	#jhz 2018-5-11: add instruction lines
    12	#jhz 2018-5-24: updated for test on RTDC/RG system
    13	#jhz 2018-5-25: updated for test on Hilo system (hilodr2)
    14	#jhz 2018-5-25: updated for test on Hilo system (hilodr2) 
    15	#               no casa found
    16	#jhz 2018-5-29: add optinx to input variables
    17	#               add 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	#jhz 2018-6-13: updated the path for the new package-name
    25	#jhz 2018-6-14: add version control information to the package
    26	#jhz 2018-8-03: set up for Geoff Bower test
    27	#jhz 2018-8-07: add check/define LD_LIBRARY_PATH
    28	date
    29	# --------------------------------------------------------------------
    30	#
    31	# requirement -
    32	#
    33	# RH 6.7 to 6.9; or CentOS 6.7 to 6.9
    34	# CASA 5.1.1 and higher
    35	# --------------------------------------------------------------------
    36	#
    37	# set up c-shell and environment variables -
    38	#
    39	# INPUT_FILE_DIR     - the path of the SMA archived data produced by online 
    40	#                      system with the SWARM correlator
    41	# INPUT_FILE_NAME    - the file name of the SMA archived data that users want
    42	#                      to interpret to measurementSet of CASA
    43	# OUTPUT_FILE_PREFIX - the prefix of output file name,  for example, SMA180506
    44	#                      will result in SMA180506.ms for the data in measurementSet
    45	#                      for CASA       
    46	# PATH               - the location of the executable binary code and the Python 
    47	#                      script 
    48	# # SEPARATE_DRX       - a handle for daul receiver: 
    49	#                      "Y" to produce two separate RX files in CASA output    
    50	#                      "N" to produce a single dual RX file in CASA output                                                                       
    51	set    PATH = /sma/local/opt/sma/SWARM2CASA
    52	set    PATHBIN = $PATH/bin
    53	if (! $?LD_LIBRARY_PATH) then
    54	        setenv LD_LIBRARY_PATH $PATH/lib
    55	else
    56	        setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:$PATH/lib
    57	endif
    58	set    INPUT_FILE_DIR = /sma/data/science/mir_data/
    59	set    INPUT_FILE_NAME = 180506_03:52:53 
    60	setenv OUTPUT_FILE_PREFIX SMA180506
    61	set    SEPARATE_DRX    = N 
    62	#----------------------------------------------------------------------
    63	echo 'Start swarm2casa.csh script -'
    64	echo ''
    65	echo "SWARM2CASA pipeline version: " `cat $PATH/VERSION`
    66	echo "loaded from PATH=$PATH"
    67	echo ''
    68	echo "OUTPUT_FILE_PREFIX=" $OUTPUT_FILE_PREFIX
    69	#
    70	# process start -
    71	#
    72	#for LSB -
    73	$PATHBIN/swarmRead $INPUT_FILE_DIR $INPUT_FILE_NAME $OUTPUT_FILE_PREFIX 0 0 
    74	#for USB -
    75	$PATHBIN/swarmRead $INPUT_FILE_DIR $INPUT_FILE_NAME $OUTPUT_FILE_PREFIX 1 0
    76	#
    77	# run CASA batch process -
    78	#
    79	alias casa "$PATH/casabin/casa" 
    80	if($SEPARATE_DRX == "Y") then
    81	casa -c $PATHBIN/swarm2ms_d.py
    82	echo ''
    83	echo 'Two CASA measurementSet data outputs are produced: '
    84	echo $OUTPUT_FILE_PREFIX'_rx1.ms &' $OUTPUT_FILE_PREFIX'_rx2.ms'
    85	else
    86	casa -c $PATHBIN/swarm2ms_s.py
    87	echo ''
    88	echo 'A single CASA measurementSet data output is produced: '
    89	echo $OUTPUT_FILE_PREFIX'.ms'
    90	endif
    91	echo 'Done, congratulation! exit from the script!'
    92	date
    93	exit