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	#jhz 2018-8-13: add options with the handle optidx:
    30	#0 => Default, convert SWARM to MS along with online flagging, for testing
    31	#1 => Convert SWARM to MS without applying online flagging, for testing
    32	#jhz 2018-8-17: RTDC tested OPTIONS = 1
    33	#jhz 2018-8-29: add SWARM2CASA version requirement
    34	date
    35	# --------------------------------------------------------------------
    36	#
    37	# requirement -
    38	#
    39	# RH 6.7 to 6.9; or CentOS 6.7 to 6.9
    40	# CASA 5.1.1 and higher
    41	# SWARM2CASA 1.0.2 and higher
    42	# --------------------------------------------------------------------
    43	#
    44	# set up c-shell and environment variables -
    45	#
    46	# INPUT_FILE_DIR     - the path of the SMA archived data produced by online 
    47	#                      system with the SWARM correlator
    48	# INPUT_FILE_NAME    - the file name of the SMA archived data that users want
    49	#                      to interpret to measurementSet of CASA
    50	# OUTPUT_FILE_PREFIX - the prefix of output file name,  for example, SMA180506
    51	#                      will result in SMA180506.ms for the data in measurementSet
    52	#                      for CASA       
    53	# PATH               - the location of the executable binary code and the Python 
    54	#                      script
    55	# SEPARATE_DRX       - a handle for daul receiver: 
    56	#                      "Y" to produce two separate RX files in CASA output    
    57	#                      "N" to produce a single dual RX file in CASA output  
    58	# SIDEBAND           - an integer for selection of sideband
    59	#                      set SIDEBAND = 0 for LSB
    60	#                      set SIDEBAND = 1 for USB
    61	# OPTIONS            - an integer for options allowing the pipeline
    62	#                      processing visibility with online flagging and 
    63	#                      Tsys. There are four options to be implemented.
    64	#                      First two are implemented and tested by programmer:
    65	#                      set OPTIONS = 0    % Default, convert SWARM to MS along 
    66	#                                           with online flagging
    67	#                      set OPTIONS = 1    % Convert SWARM to MS without applying 
    68	#
    69	set    PATH = /opt/sma/SWARM2CASA
    70	set    PATHBIN = $PATH/bin
    71	if (! $?LD_LIBRARY_PATH) then
    72	        setenv LD_LIBRARY_PATH $PATH/lib
    73	else
    74	        setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:$PATH/lib
    75	endif
    76	set    INPUT_FILE_DIR = /sma/data/science/mir_data/
    77	set    INPUT_FILE_NAME = 180517_05:16:39 
    78	setenv OUTPUT_FILE_PREFIX SMA180517
    79	set    SEPARATE_DRX    = N
    80	set    OPTIONS         = 1  
    81	#----------------------------------------------------------------------
    82	echo 'Start swarm2casa.csh script -'
    83	echo ''
    84	echo "SWARM2CASA pipeline version: " `cat $PATH/VERSION`
    85	echo "loaded from PATH=$PATH"
    86	echo ''
    87	echo "OUTPUT_FILE_PREFIX=" $OUTPUT_FILE_PREFIX
    88	#
    89	# process start -
    90	#
    91	#for LSB -
    92	echo "Reading LSB data -"
    93	set SIDEBAND = 0
    94	$PATHBIN/swarmRead $INPUT_FILE_DIR $INPUT_FILE_NAME $OUTPUT_FILE_PREFIX $SIDEBAND $OPTIONS
    95	#for USB -
    96	echo "Reading USB data -"
    97	set SIDEBAND = 1
    98	$PATHBIN/swarmRead $INPUT_FILE_DIR $INPUT_FILE_NAME $OUTPUT_FILE_PREFIX $SIDEBAND $OPTIONS
    99	#
   100	# run CASA batch process -
   101	#
   102	#alias casa "/usr/local/casa-release-5.1.2-4.el6/bin/casa"
   103	alias casa "/opt/casa-release-5.3.0-143.el6/bin/casa"
   104	if($SEPARATE_DRX == "Y") then
   105	casa -c $PATHBIN/swarm2ms_d.py
   106	echo ''
   107	echo 'Two CASA measurementSet data outputs are produced: '
   108	echo $OUTPUT_FILE_PREFIX'_rx1.ms &' $OUTPUT_FILE_PREFIX'_rx2.ms' 
   109	else
   110	casa -c $PATHBIN/swarm2ms_s.py
   111	echo ''
   112	echo 'A single CASA measurementSet data output is produced: '
   113	echo $OUTPUT_FILE_PREFIX'.ms'
   114	endif
   115	echo 'Done, congratulation! exit from the script!'
   116	date
   117	exit