gti_merge (version 0.0)

You can also look at:
#! /usr/bin/ksh

###########################################################################
#
# 
# SYNTAX: gti_merge allgti listfile
#
# DESCRIPTION: This utility merges the GTIs in the event files listed in
# DESCRIPTION: listfile into a single allgti file. The files in listfile
# DESCRIPTION: should have the GTI extensions explicitly indicated
# DESCRIPTION: (e.g. event.unf[2]). The GTIs are assumed not to overlap
# DESCRIPTION: GTIs in allgti are sorted by TSTART.
#
# VERSION: 0.0
#
# HISTORY:
#
##############################################################################
allgti=$1
listfile=$2


tmp=out$$.tmp

$UTIL/log_entry "Merging GTIs from the following files:"
$UTIL/file_to_log $listfile

rm -f $allgti

$UTIL/setup_parfile $FTOOLS/fmerge.par infiles="@${listfile}" \
                                       outfile="$tmp"   \
                                       columns="START STOP"
                                       mextname="ALLGTI"

$FTOOLS/fmerge >stdout.log 2>stderr.log
$UTIL/ftool_test fmerge $? $0 2 stdout.log stderr.log


###############################
# sort the GTIs by start time
###############################
$UTIL/setup_parfile $FTOOLS/fmemsort.par infile="$tmp"   \
                                         outfile=$allgti  \
                                         column="START" \
                                         method=insert  \
                                         ascend=yes     \
                                         copyall=no    \
                                         history=no   

$FTOOLS/fmemsort  >stdout.log 2>stdout.log
$UTIL/ftool_test fmemsort $? $0 2 stdout.log stderr.log

rm -f $tmp


exit 0