#!/bin/sh

#Input CMP gather with only positive offsets
file1="shot_dat1.su"

#taup transform parameters
pmin=0
pmax=0.002
np=101
dx=12.5 #Separation between adjacent traces on a CMP gather (m)

cmps=601 #Number of CMPs
cmpd2=0.0125 #distance between adjacent CMP locations (km)

#Formation of constant ray parameter sections
suwind < $file1 key=cdp min=1 max=1 | sutaup dx=$dx pmin=$pmin pmax=$pmax np=$np | sushw key=ep a=0 b=1 > temp1.su
C=2
while [ "$C" -le "$cmps" ]
do
        suwind <shot_dat1.su key=cdp min=$C max=$C |
	sutaup dx=$dx pmin=$pmin pmax=$pmax np=$np |
	sushw key=ep a=0 b=1 > temp.su
	cat temp1.su temp.su > temp2.su
	cp temp2.su temp1.su
	C=`expr $C + 1`
done
susort < temp1.su > unmig.psecs.su ep cdp

#Set the header for the separation between adjacent CMP locations
sushw < unmig.psecs.su key=d2 a=$cmpd2 > temp3.su

#Migrate each of the constant ray parameter sections
suwind < temp3.su key=ep min=0 max=0 | sumigps tmig=0,1.022 vmig=1.5,2.5 > temp1.su
C=1
while [ "$C" -lt "$np" ]
do
        suwind < temp3.su key=ep min=$C max=$C |
	sumigps tmig=0,1.022 vmig=1.5,2.5 > temp.su
        cat temp1.su temp.su > temp2.su
        cp temp2.su temp1.su
	C=`expr $C + 1`
done

#Stack all the migrated sections to obtain the final migrated image
susort < temp1.su cdp ep | sustack key=cdp > slntstkmig.su

rm -f temp*
rm -f unmig.psecs.su

suximage < slntstkmig.su &

exit 0

