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