#! /bin/bash

#
# Residual static test
#
# Synthetic shots are created , then random time shifts are added
# to the traces using sujitter program.
# The alogrithm solves for these and applies them.
# No prior knowledge about the acquisition geomtery is required.
# Works on 3D data also.
# 
# Shot id should be stored in headerword fldr
# Receiver id should be stored in headerword tracf
# CDP number should be stored in headerword cdp
#
# The residual static can only
# correct for short wavelength variation
#
#
#The algorithm used here is based on
#	Ronen, Claerbout, 1985. Surface-consistent residual static
#	estimation by stack-power maximization. 
#	Geophysics, 50, 12: 2759-2767.
#   Author: Balazs Nemeth; Saskatoon, Saskatchewan, CANADA.
#   Modified by A. Bitri BRGM  France.

echo
echo "Residual static test"
echo
echo







nshot=25
nrec=96


function m_shots()
{
nt=500
dt=0.001
kilounits=0

nxo=$nrec
dxo=10
fxo=-1000

nxs=$nshot
dxs=20
fxs=0.0
v00=3000


susynlv nt=$nt dt=$dt kilounits=$kilounits \
	nxo=$nxo dxo=$dxo fxo=$fxo \
	nxs=$nxs dxs=$dxs fxs=$fxs \
	ref="1:-400,250;1500,250"   \
	ref="0.8:00,500;3000,500"   \
	v00=$v00 fpeak=90.0 \
	verbose=1 ndpfz=10 \
	| suaddnoise sn=10 \
	> tmp.su
}

m_shots

# Fill in the headers

	cat tmp.su |
	suabshw key=offset |
	suchw key1=cdp key2=fldr key3=tracf b=10 c=10 d=2 |  # set cdp 
	suchw key1=tracf key2=gx a=101 b=0.1> shots.su       # Now tracf is receiver field position 
						             # Receiver position number starting at 1 
	                                                     # at receiver number 1 


#
# Add random time shifts at receivers and shot points
#
#


	sujitter< shots.su min=1 max=5 pon=1 fldr=1 >  shots_static.su
	
# Do NMO on gathers

	sunmo vnmo=3000 < shots_static.su |
	suwind tmin=0.1 tmax=0.35         \
	> shots_static_nmo_w.su




# Show uncorrected stack
	susort <  shots_static_nmo_w.su cdp |
	sustack | suximage perc=99 title="Stack without static residual correction" &

# Compute cross correlation based static solution 

	suresstat fn=shots_static_nmo_w.su ssol=s_static rsol=r_static 


# Apply statics; show section with static effects removed

	susort < shots_static_nmo_w.su cdp | sustatic hdrs=3 sou_file=s_static rec_file=r_static | 
	sustack |
	suximage perc=99 title=" Recovered static applied before stacking" 
	

echo
echo " Done with the test"
echo
	

	

