

DO NOT USE THIS SCRIPT...PLEASE USE ep_run.csh
PPQ, August 29th, 2001


#! /usr/bin/csh 
#-vx

#-------------------------------------------------------
# Set various EDI_PISO control parameters.
# First load all of the defaults.  If you want to change
# any of them, just do so where indicated below.
# All of the control parameters are documented in:
#             EPDM_DEF.txt

source edi_piso_pp_defaults.csh

# Change any of the environment variables here:

#setenv pp_nchunk 2
setenv pp_curve_traj 1
setenv pp_order_assign 1
setenv pp_acfir_assign 1
setenv pp_outlier_removal 1
setenv pp_outlier_maxperc 30
setenv pp_fg_logpr 1
setenv pp_cg_logpr 20
setenv pp_order_use_unrun1 0
setenv pp_order_use_unrun2 0
setenv pp_order_use_hrb 1

#setenv pp_nbeam_min 6
#setenv pp_curve_traj 1
#setenv pp_acfir_assign 1
#setenv pp_acfir 2.0
#setenv pp_maxorder 3

#-------------------------------------------------------
# Set the official, nominal phase offset for Cluster 
# spin interval definition as defined in the document
# "Spin Timings and Offsets for Cluster Prime Parameters"
# by Schwarz and Daly, DS-QMW-TN-0007, 1996
#         OFFSET = 75/1024 * 360 degrees
# Note: EDI_PISO software assumes that the FGM software that
# produces the spin-averaged magnetic field file uses this
# exact offset also!!!  If this number ever changes, check to
# make sure the FGM code changes it's value also!!!

setenv EDI_PISO_OFFSET 26.3671875
#-------------------------------------------------------


#-------------------------------------------------------
# Setting the 'finfo' (file information) and 
# 'tinfo' (time information) variable arrays:
#
# 5 POSSIBLE finfo FORMS:
#    cl2_2000-10-05t15_54_00z.nsd-mpecl
#    cl2_2000-10-05t15_54_00z.bsd-mpecl
#    cl2_2000-10-05t00_00_00z.msf-mpecl
#    cl2_2000-10-05t00_00_00z.msf-cl1
#    cl2_2000-10-05t00_00_00z.msf-ibmcl1
#
# NOTE: The first 28 characters for the 'nsd'
#       and 'bsd' types (i.e. cl2_2000-10-05t15_54_00z.nsd)
#       specify the exact file to be used.  For the 'msf'
#       type, the '00_00_00' is just a place holder and is
#       not used for anything.
#
#       For either case, you must additionally specify
#       'tinfo' (start and end time string, see below)
#       It has the form HH_MM_SS-HH_MM_SS. It must be set for
#       every file listed in the 'finfo' variable.
#
#       If you want to use all of the data in the file, 
#       (for example if you don't know the time range
#       available within the file) just set tinfo to ALL.
#-------------------------------------------------------

if ("$HOST" == "ibmcl1") then

   set finfo = `cat ibmcl1_finfo_tinfo.txt | grep 'finfo'`
   set nlen = `echo $finfo | wc -c`
   @ nlen--
   set finfo = `echo $finfo | cut -c7-$nlen`

   set tinfo = `cat ibmcl1_finfo_tinfo.txt | grep 'tinfo'`
   set nlen = `echo $tinfo | wc -c`
   @ nlen--
   set tinfo = `echo $tinfo | cut -c7-$nlen`

else

   set tinfo = (ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL)
   set finfo = (cl1_2001-03-12t07_00_00z.nsd-mpecl cl1_2001-03-12t08_58_00z.nsd-mpecl cl1_2001-03-12t09_00_00z.nsd-mpecl cl1_2001-03-12t10_00_00z.nsd-mpecl cl1_2001-03-12t11_00_00z.nsd-mpecl cl1_2001-03-12t12_00_00z.nsd-mpecl cl2_2001-03-12t07_00_00z.nsd-mpecl cl2_2001-03-12t08_58_00z.nsd-mpecl cl2_2001-03-12t09_00_00z.nsd-mpecl cl2_2001-03-12t10_00_00z.nsd-mpecl cl2_2001-03-12t11_00_00z.nsd-mpecl cl2_2001-03-12t12_00_00z.nsd-mpecl cl3_2001-03-12t07_00_00z.nsd-mpecl cl3_2001-03-12t08_58_00z.nsd-mpecl cl3_2001-03-12t09_00_00z.nsd-mpecl cl3_2001-03-12t10_00_00z.nsd-mpecl cl3_2001-03-12t11_00_00z.nsd-mpecl cl3_2001-03-12t12_00_00z.nsd-mpecl)

#   set tinfo = (20_38_00-20_41_00)
#   set finfo = (cl1_2001-04-21t20_00_00z.nsd-mpecl)

#   set tinfo = (06_00_00-07_00_00)
#   set finfo = (cl1_2001-03-31t00_00_00z.msf-gamma)

#   set tinfo = (ALL)
#   set finfo = (cl1_2001-03-12t07_00_00z.nsd-mpecl)
#   set finfo = (cl1_2001-03-12t09_00_00z.nsd-mpecl)

#   set tinfo = (ALL)
#   set finfo = (cl1_2001-03-12t07_28_00z.bsd-mpecl)

    set tinfo = (12_00_00-12_10_00)
    set finfo = (cl1_2001-03-12t12_00_00z.nsd-mpecl)

endif

echo $finfo
echo $tinfo

@ j = 0
foreach i ($finfo)

    @ j++

    setenv EDI_PISO_SC_NUMBER `echo $i | cut -c3-3`
    setenv EDI_PISO_TSTRING `echo $i | cut -c16-23`
    setenv EDI_PISO_TINFO $tinfo[${j}]
    
    set year = `echo $i | cut -c5-8`
    set month = `echo $i | cut -c10-11`
    set day = `echo $i | cut -c13-14`
    setenv EDI_PISO_PRODUCTION_DATE ${year}${month}${day}

    set ftype = `echo $i | cut -c26-28`
    set machine = `echo $i | cut -c30-35`

    if ("$machine" == "cl1") then

        echo 'Not coded yet for this machine'
	goto next_file

    else if ("$machine" == "ibmcl1") then

        setenv EDI_PISO_ATT_ORB_PATH /home/ppq/edi_piso/att_orb/
	setenv EDI_PISO_PICK_PATH /home/ppq/pick
        setenv GDC_RDDA_ROOT /nfs/cl1/
	setenv GDC_OUT_DIR ./iff_data/
	setenv EDI_PISO_AUX_OUT ./aux_data/

	if ("$ftype" == "msf") then
	    set date_lite = `echo $EDI_PISO_PRODUCTION_DATE | cut -c3-8`
	    set files = `ls -1 /home/ppq/edi_piso/msf_data/${date_lite}em.??${EDI_PISO_SC_NUMBER}`

	    if ("${#files}" == "0") then
		echo "MSF file not found"
		goto next_file
	    else
		setenv EDI_PISO_FNAME $files[${#files}]
		setenv EDI_PISO_SNAME msf
		setenv EDI_PISO_CONFIG ibmcl1_msf
	    endif

	else
	    set ftp_fname = `echo $i | cut -c1-28`

	    set files = `ls -1 /home/ppq/edi_piso/ftp_data/${ftp_fname}`

	    if ("${#files}" == "0") then
		echo "FTP file not found"
		goto next_file
	    else
		setenv EDI_PISO_FNAME $files[${#files}]
		setenv EDI_PISO_SNAME ftp
		setenv EDI_PISO_CONFIG ibmcl1_ftp
	    endif
	endif

#================================================
# Create the spin-averaged FGM data file
#================================================
	setenv EDI_PISO_FGM_ROOT /home/eg/
	setenv EDI_PISO_FGM_OUT ./fgm_data/C${EDI_PISO_SC_NUMBER}_${EDI_PISO_PRODUCTION_DATE}_FGM_SCS_SPINRES.txt
	if (-r ${EDI_PISO_FGM_OUT}) then
	    echo "Using existing SPINRES FGM data file: ${EDI_PISO_FGM_OUT}"
	else
            echo "Creating SPINRES FGM data file: ${EDI_PISO_FGM_OUT}"
	    /usr/local/bin/bash -c "./ep_prod_fgm.bash"
	    if (-r ${EDI_PISO_FGM_OUT}) then
	        echo ''
	    else
	        echo "SPINRES FGM data file creation not successful: ${EDI_PISO_FGM_OUT}"
	        goto next_file
	    endif
	endif

    else if ("$machine" == "gamma") then

	setenv EDI_PISO_ATT_ORB_PATH /usr/users/ppq/cluster/att_orb
	setenv EDI_PISO_PICK_PATH /usr/users/ppq/cluster/edi/pick
	setenv GDC_OUT_DIR ./iff_data/
	setenv EDI_PISO_AUX_OUT ./aux_data/

	if ("$ftype" == "msf") then
	    set date_lite = `echo $EDI_PISO_PRODUCTION_DATE | cut -c3-8`
	    set files = `ls -1 /usr/users/ppq/cluster/edi/msf_data/${date_lite}em.??${EDI_PISO_SC_NUMBER}`

	    if ("${#files}" == "0") then
		echo "MSF file not found"
		goto next_file
	    else
		setenv EDI_PISO_FNAME $files[${#files}]
		setenv EDI_PISO_SNAME msf
		setenv EDI_PISO_CONFIG gamma_msf
	    endif

	else
	    set ftp_fname = `echo $i | cut -c1-28`

	    set files = `ls -1 /usr/users/ppq/cluster/edi/ftp_data/${ftp_fname}`

	    if ("${#files}" == "0") then
		echo "FTP file not found"
		goto next_file
	    else
		setenv EDI_PISO_FNAME $files[${#files}]
		setenv EDI_PISO_SNAME ftp
		setenv EDI_PISO_CONFIG gamma_ftp
	    endif
	endif

#===================================================
# Check that  the spin-averaged FGM data file exists
#===================================================
	setenv EDI_PISO_FGM_OUT ./fgm_data/C${EDI_PISO_SC_NUMBER}_${EDI_PISO_PRODUCTION_DATE}_FGM_SCS_SPINRES.txt
	if (-r ${EDI_PISO_FGM_OUT}) then
	    echo "FGM file exists: $EDI_PISO_FGM_OUT"
	else
	    echo "FGM file does not exist: $EDI_PISO_FGM_OUT"
	    goto next_file
	endif

    else if ("$machine" == "mpecl") then

	setenv EDI_PISO_ATT_ORB_PATH /nfs/cl1/att_orb/
	setenv EDI_PISO_PICK_PATH /home/chutter/edi/pick_idl/cluster
	setenv GDC_RDDA_ROOT /nfs/cl1/
	setenv GDC_OUT_DIR ./iff_data/
	setenv EDI_PISO_AUX_OUT ./aux_data/

	if ("$ftype" == "msf") then
	    set date_lite = `echo $EDI_PISO_PRODUCTION_DATE | cut -c3-8`
	    set files = `ls -1 /nfs/cl1/msf_data/msf_${EDI_PISO_SC_NUMBER}/${date_lite}em.??${EDI_PISO_SC_NUMBER}`

	    if ("${#files}" == "0") then
		echo "MSF file not found"
		goto next_file
	    else
		setenv EDI_PISO_FNAME $files[${#files}]
		setenv EDI_PISO_SNAME msf
		setenv EDI_PISO_CONFIG mpecl_msf
	    endif

	else
	    set ftp_fname = `echo $i | cut -c1-28`

	    set files = `ls -1 /data2/hav/sc${EDI_PISO_SC_NUMBER}/${ftp_fname}`

	    if ("${#files}" == "0") then
		echo "FTP file not found"
		goto next_file
	    else
		setenv EDI_PISO_FNAME $files[${#files}]
		setenv EDI_PISO_SNAME ftp
		setenv EDI_PISO_CONFIG mpecl_ftp
	    endif
	endif

#================================================
# Create the spin-averaged FGM data file
#================================================
	setenv EDI_PISO_FGM_ROOT /home/eg/
	setenv EDI_PISO_FGM_OUT ./fgm_data/C${EDI_PISO_SC_NUMBER}_${EDI_PISO_PRODUCTION_DATE}_FGM_SCS_SPINRES.txt
	if (-r ${EDI_PISO_FGM_OUT}) then
	    echo "Using existing SPINRES FGM data file: ${EDI_PISO_FGM_OUT}"
	else
            echo "Creating SPINRES FGM data file: ${EDI_PISO_FGM_OUT}"
	    /usr/local/bin/bash -c "./ep_prod_fgm.bash"
	    if (-r ${EDI_PISO_FGM_OUT}) then
	        echo ''
	    else
	        echo "SPINRES FGM data file creation not successful: ${EDI_PISO_FGM_OUT}"
	        goto next_file
	    endif
	endif

    endif

    idl edi_piso_wrapper

    echo "============================================"

    next_file:

end

exit
