#
#   Remember to initiate the segd input stack (latest)
#

num_args="$#"
if [  $num_args != "5" ]; then
    echo "Usage: stack line-name UKOOA-filename streamer-number source-number plot-direction(ltr/rtl)"
    exit
fi

lineno=$1
navfil=$2
streamer=$3
if [ $3 != "1" ] && [ $3 != "2" ] && [ $3 != "3" ] && [ $3 != "4" ]; then
     echo "arg 3 (streamer number) must be 1, 2, 3, or 4"
     exit;
fi
source=" "
if [ $4 != "1" ] && [ $4 != "2" ]; then
     echo "arg 4 (source number) must be 1 or 2"
fi
if [ $4 = "1" ]; then
     source="odd"
fi
if [ $4 = "2" ]; then
     source="even"
fi
dir="ltr"
if [ $num_args = "5" ]; then
     dir=$5
     if [ $dir != "rtl" ] && [ $dir != "ltr" ]; then
        echo "plot-direction (arg 5) must be rtl or ltr"
        exit
     fi
fi

outdir="/home/logadmin/output"
latest="latest_files.tmp"

sioseis << eof
procs segddin prout geom tredit wbt gather nmo stack diskoa avenor filter plot end
segddin
   fcset $streamer lcset $streamer retrac -1    # use accumulated trace number
   stack $latest $source
   logpath ./$lineno-stack.log
   end
end
tredit
     limits -2000 2000 kill outside lhdr 10 end
end
prout
 fno 0 lno 9999999 ftr 1 ltr 1 noinc 10  end
end

geom
  type 20 navfil $navfil end
end

wbt
    vel 1500 track .1 end
end

gather
   maxtrs 60  maxrps 250 end  # this may have to change!
end

nmo
addwb yes
vtp 1500 .600 
    1600 1
    2900 6.5
    7000 15.0
    end
end

diskoa   # Write out disk file
  opath $outdir/$lineno-stack.segy
end end

avenor
  hold 300
  addwb yes sets 0 .5 5 6 end
end


filter
  pass 5 90 ftype 0 dbdrop 48 end
end

plot 
  dir $dir
  scalar -1
  tlines 0.5 1 nibs 7225 ann gmtint anninc 5 ann2 shotno
  def 0.04 trpin 125 wiggle 0 
  vscale 1.25 clip .03
  opath $outdir/$lineno-stack.atlantek
  end 
end

end
eof