#! /bin/tcsh -f

fstruct ${data_dir}/${dir0}/${ev2} | grep 'GTI' | awk '{print $3,$6}' > ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt

set Q1_stdgti=`cat ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt | awk 'NR == 1 {print $2}'` 
set Q2_stdgti=`cat ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt | awk 'NR == 4 {print $2}'` 
set Q3_stdgti=`cat ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt | awk 'NR == 7 {print $2}'` 
set Q4_stdgti=`cat ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt | awk 'NR == 10 {print $2}'` 
set Q1_gti=`cat ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt | awk 'NR == 13 {print $2}'` 
set Q2_gti=`cat ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt | awk 'NR == 16 {print $2}'` 
set Q3_gti=`cat ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt | awk 'NR == 19 {print $2}'` 
set Q4_gti=`cat ${data_dir}/${dir0}/GTI_counting_mode_${par}.txt | awk 'NR == 22 {print $2}'`

if (${Q1_gti} > ${Q1_stdgti} || ${Q2_gti} > ${Q2_stdgti} || ${Q3_gti} > ${Q3_stdgti} || ${Q4_gti} > ${Q4_stdgti}) then
 echo "COUNTING MODE CHECK: ${dir0} pn GTIs are not correct for the event file ${data_dir}/${dir0}/${ev2}" >>& ${log_dir}/analysis.log
 echo "COUNTING MODE CHECK: ${dir0} pn GTIs are not correct for the event file ${data_dir}/${dir0}/${ev2}"  >>& ${data_dir}/${dir0}/check_counting_mode.txt 
else
 echo "COUNTING MODE CHECK: ${dir0} pn GTIs are correct for the event file ${data_dir}/${dir0}/${ev2}" >>& ${log_dir}/analysis.log
 echo "COUNTING MODE CHECK: ${dir0} pn GTIs are correct for the event file ${data_dir}/${dir0}/${ev2}" >>& ${data_dir}/${dir0}/check_counting_mode.txt
endif
