merge_images (version 0.0)

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

###########################################################################
#
# 
# SYNTAX: merge_images outfile listfile
#
# DESCRIPTION: This utility sums the images listed in a file.
#
# HISTORY:
#
# VERSION: 0.0
#
##############################################################################
#DEBUG=1

outfile=$1
listfile=$2

old=old.tmp

if [ -s "$listfile" ]; then
     $UTIL/log_entry "Summing the following images to produce $outfile"
     $UTIL/file_to_log $listfile
fi

rm -f $outfile
for file in $(cat $listfile); do

     ###################
     # debuging output
     ###################
     if [ -n "$DEBUG" ]; then
          echo ${0##*/}: file=$file
     fi

     if [ -a "$outfile" ]; then
          #####################
          # add the next file
          #####################
          mv $outfile $old

          $UTIL/setup_parfile $FTOOLS/farith.par infil1=$file     \
                                                 infil2=$old     \
                                                 outfil=$outfile \
                                                 ops=ADD 

          rm -f $outfile
          $FTOOLS/farith >stdout.log 2>stderr.log
          $UTIL/ftool_test farith $? $0 2 stdout.log stderr.log

     
     else
          
          #####################################################
          # this is the first file, so just copy it to outfile
          #####################################################
          cp $file $outfile
     fi
                         
done

rm -f $old

exit 0