#! /bin/tcsh -f

echo "********************************"
echo "*  start barycenter_flare.csh  *"
echo "********************************"
date

echo ""
echo "Starting to apply barycentric correction to soft protons GTIs ${gtiflare}..."
echo ""
setenv SAS_ODF ${data_dir}/${dir0}
setenv SAS_CCF ${data_dir}/${dir0}/ccf.cif
cp $data_dir/$dir0/*ROS.ASC .
cp $data_dir/$dir0/*SUM.SAS .
echo "addattribute set="${gtiflare}:STDGTI" attributename='TELESCOP DATE-OBS DATE-END' attributetype='string string string' stringvalue='"\"XMM\" \"$DSTART\" \"$DSTOP\""' attributecomment='"XMM-Mission" "Start-time-exposure" "End-time-exposure"'" > addatt.csh
source addatt.csh
rm addatt.csh
echo "addattribute set="${gtiflare}:PRIMARY" attributename='TELESCOP DATE-OBS DATE-END' attributetype='string string string' stringvalue='"\"XMM\" \"$DSTART\" \"$DSTOP\""' attributecomment='"XMM-Mission" "Start-time-exposure" "End-time-exposure"'" > addatt.csh
source addatt.csh
rm addatt.csh
echo ""
echo "barycen withtable=yes table=${gtiflare}:STDGTI timecolumn=START withsrccoordinates=true srcra="$RA_NOM" srcdec="$DEC_NOM" processgtis=no ephemeris=DE405 -w ${warn}" > bary.csh
echo ""
source bary.csh
rm bary.csh
fparkey F ${gtiflare}'[1]' CLOCKAPP
fparkey 'TT' ${gtiflare}'[1]' TIMESYS
fparkey 'LOCAL' ${gtiflare}'[1]' TIMEREF
echo""
echo "barycen withtable=yes table=${gtiflare}:STDGTI timecolumn=STOP withsrccoordinates=true srcra="$RA_NOM" srcdec="$DEC_NOM" processgtis=no ephemeris=DE405 -w ${warn}" > bary.csh
echo ""
source bary.csh
rm bary.csh
fparkey T ${gtiflare}'[1]' CLOCKAPP
echo""
cp ${gtiflare} ${data_dir}/${dir0}/${gtiflare}
chmod 766 ${data_dir}/${dir0}/${gtiflare}
