#define PEMFULL /SDA/martin/PemFull/CDP
#define PEMFULL /wrk8/martin/
#define PEMFULL /promax1/martin/Window
#define PSARGS color=y fat=1 fatmult=1.5
#define FIGDIR ./Fig
#define FIGSUP ./Fig2
#define FIGLIST
#define BINDIR ../../Bin/MTYPE
#include <SEP.defs>

/* for the whole thesis */
#define NINECOMP xx xy xz yx yy yz zx zy zz

/* get the clip value from one component and use it for all 9 other */
#define GETCLIP(A,B) `( Clip <A pclip=B >Jjunk ; Get <Jjunk clip parform=n)`

/* interactive plot panel */
#define PLOTSELECT(prefix,suffix,option)  xtpanel -var NAME prefix -var TYPE suffix  -var OPTION option  -file compare9c.panel
$ make xtpanel file relative in included martin.rules

#define TAPLOT Taplot pclip=90.
#define MOVIE Animator
#define NULL head=/dev/null

/* we dont need to fix header since it makes  shotnumber 0 with trace zero,
 such that we get a filter that will be zero for all the missing traces 
 a waist of computing, but otherwise ok  */

/* do all in junks of 10 cdps gives the angular/offset average */

dojunkxx&: [[ sub -i X smallxx-X 130 140 150 160 170 180 190 ]]

dojunkxx&: [[ sub -i X smallxx-X 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 ]]

dojunkzz&: [[ sub -i X smallzz-X 0 ]]

dojunkyy&: [[ sub -i X smallyy-X 0 5 10 ]]

filtspecavg%.V:
	Window f3=19  n3=1 < filtmov%.H  |Spectrum |Graph title="% Avg. Spectrum" grid=y g1num=5 >filtspecavg%.V


%.N.H: %.H
	BINDIR/Notching freak=17.5 <%.H | BINDIR/Notching freak=60 >%.N.H

%.B.H: %.H
	Balance rms=0.1 <%.H >%.B.H

eqbxx: Ixx.eq.B.H

eqxx&: Ixx.eq.H

eqzz&: zz.eq.H

eqyy&: yy.eq.H

eqzz&: zx.eq.H

zx.eq.H:  PEMFULL/cwindowzx.H BINDIR/EqualizePre5a
	Window n1=101 <PEMFULL/cwindowzx.H >inzx.H
	WIndow n1=101 <PEMFULL/hzxcube.H >hinzx.H	
	time BINDIR/Count sxbias=55. attrfile=hin%.H scdfile=csd.%.H recifile=jreci.%.H <in%.H  >jnorm.%.H
	Rm in%.H 
$ need only half since the other part of norm%.H is stored in reci%.H
$ we leave scd%.H intact, but the second half will never be read
	Window n2=101 <jnorm.%.H >norm.%.H
	Window n2=101 <jreci.%.H >reci.%.H
        Rm jnorm.%.H jreci.%.H
        time BINDIR/EqualizePre5a <norm.%.H scdfile=csd.%.H recifile=reci.%.H  >norm.%.eq.H filter1=jf%.H  filtermovie=filtmov%.H par=parfile  attrfile=hin%.H restart=d niter=20
	Rm  hin%.H
$ do not remove scd.%.H , because we can reuse it at least for xx, yy, zz

#ifdef IShp700
#define PEMFULL /wrk8/martin/Window
#endif
#ifdef ISsun4
#define PEMFULL /scr4/martin/Window
#endif
$ test that shots cannot be zero
testI%.eq.H:  PEMFULL/cwindow%.H BINDIR/EqualizePre5i
	Window n3=10 <PEMFULL/cwindow%.H >in%.H
	Window n3=10  <PEMFULL/h%cube.H >hin%.H	
	time BINDIR/Count sxbias=55. attrfile=hin%.H scdfile=csd.%.H recifile=reci.%.H <in%.H  >norm.%.H
	Rm in%.H
        time BINDIR/EqualizePre5i <norm.%.H scdfile=csd.%.H recifile=reci.%.H  >norm.%.eq.H filter1=jf%.H  filtermovie=filtmov%.H par=parfile  attrfile=hin%.H restart=d niter=20 

$ Balance first, then equalize
I%.eq.B.H:  norm.%.H reci.%.H csd.%.H  BINDIR/EqualizePre5i
	Cp <PEMFULL/h%cube.H >hin%.H
	Balance oper=1 < norm.%.H >balfact%.H rms=0.1
	Balance oper=2 < norm.%.H bal=balfact%.H > norm.%.B.H
	Balance        < reci.%.H                > reci.%.B.H rms=0.1
        time BINDIR/EqualizePre5i <norm.%.B.H scdfile=csd.%.H recifile=reci.%.B.H  >norm.%.B.eq.H  filtermovie=filtmov%.B.H par=parfile  attrfile=hin%.H restart=d niter=20 

I%.eq.H:  PEMFULL/cwindow%.H BINDIR/EqualizePre5i
	Cp <PEMFULL/cwindow%.H >in%.H
	Cp <PEMFULL/h%cube.H >hin%.H	
	time BINDIR/Count sxbias=55. attrfile=hin%.H scdfile=csd.%.H recifile=reci.%.H <in%.H  >norm.%.H
	Rm in%.H
        time BINDIR/EqualizePre5i <norm.%.H scdfile=csd.%.H recifile=reci.%.H  >norm.%.eq.H filter1=jf%.H  filtermovie=filtmov%.H par=parfile  attrfile=hin%.H restart=d niter=20 
$ do not remove scd.%.H , because we can reuse it at least for xx, yy, zz
	Rm hin%.H

Efilt%&: BINDIR/Efilter 
	Window <filtmov%.H f3=19 n3=1 > jfilt%.H
	BINDIR/Efilter <norm.%.H scdfile=csd.%.H filter1=jfilt%.H >norm.%.eq.H par=parfile

%.eq.H:  PEMFULL/cwindow%.H BINDIR/EqualizePre5b
	Cp <PEMFULL/cwindow%.H >in%.H
	Cp <PEMFULL/h%cube.H >hin%.H	
	time BINDIR/Count sxbias=55. attrfile=hin%.H scdfile=csd.%.H recifile=reci.%.H <in%.H  >norm.%.H
	Rm in%.H
$ need only half since the other part of norm%.H is stored in reci%.H
$ we leave scd%.H intact, but the second half will never be read
$	Window n2=101 <jnorm.%.H >norm.%.H
$	Window n2=101 <jreci.%.H >reci.%.H
$        Rm jnorm%.H jreci%.H
        time BINDIR/EqualizePre5b <norm.%.H scdfile=csd.%.H recifile=reci.%.H  >norm.%.eq.H filter1=jf%.H  filtermovie=filtmov%.H par=parfile  attrfile=hin%.H restart=d niter=1  rms=y
$ do not remove scd.%.H , because we can reuse it at least for xx, yy, zz
	Rm hin%.H





small%1-%2&:
	Window f3=%2 n3=NCDPS f1=750 n1=500 <%1cube.M.B.H >in.small%1-%2.M.H
	Window f3=%2  n3=NCDPS <PEMFULL/h%1cube.H >hin.small%1-%2.M.H	
	time BINDIR/Count sxbias=55. attrfile=hin.small%1-%2.M.H scdfile=csd.small%1-%2.M.H recifile=reci.small%1-%2.M.H <in.small%1-%2.M.H  >norm.small%1-%2.M.H
        BINDIR/EqualizePre5a <norm.small%1-%2.M.H scdfile=csd.small%1-%2.M.H recifile=reci.small%1-%2.M.H  >norm.small%1-%2.eq.M.H filter1=filt1cdp%1-%2.H  filtermovie=filtmovcdpsmall%1-%2.M.H par=parfile  attrfile=hin.small%1-%2.M.H restart=d niter=20

test%1-%2&:
	Window f3=100  n3=20 f1=750 n1=250 <PEMFULL/%1cube.M.H >in.test%1-%2.M.H
	Window f3=100  n3=20 <PEMFULL/h%1cube.H >hin.test%1-%2.M.H	
	time BINDIR/Count sxbias=55. attrfile=hin.test%1-%2.M.H scdfile=csd.test%1-%2.M.H recifile=reci.test%1-%2.M.H <in.test%1-%2.M.H  >norm.test%1-%2.M.H
        BINDIR/EqualizePre5a <norm.test%1-%2.M.H scdfile=csd.test%1-%2.M.H recifile=reci.test%1-%2.M.H  >norm.test%1-%2.eq.M.H filter1=filt1cdp%1-%2.H  filtermovie=filtmovcdptest%1-%2.M.H par=parfile  attrfile=hin.test%1-%2.M.H restart=d niter=20 rms=y

posttest%1-%2&:
	NMO < norm.test%1-%2.M.H vel=8000 >norm.test%1-%2.M.H.NMO
	NMO < norm.test%1-%2.eq.M.H vel=8000 >norm.test%1-%2.eq.M.H.NMO
	Window f3=1 n3=1 < norm.test%1-%2.M.H.NMO >j1.H
	Window f3=1 n3=1 < norm.test%1-%2.eq.M.H.NMO >j2.H
	Merge j1.H j2.H space=n >jj.H

testprep%&:
$	Window n3=5 f1=500 n1=750 <PEMFULL/%cube.H |Scale dscale=1.e-15 >in.small%.H
$	Window n3=5 <PEMFULL/h%cube.H >hin.small%.H	
	Window n3=50 j3=4 f1=500 n1=750 <PEMFULL/%cube.H |Scale dscale=1.e-15 >in.small%.H
	Window n3=50 j3=4 <PEMFULL/h%cube.H >hin.small%.H
	time BINDIR/Count sxbias=55. attrfile=hin.small%.H scdfile=csd.small%.H recifile=reci.small%.H <in.small%.H  >norm.small%.H

test%&:
        BINDIR/EqualizePre5 <norm.small%.H scdfile=csd.small%.H recifile=reci.small%.H  >norm.small%.eq.H filter1=filt1cdp%.H  filtermovie=filtmovcdpsmall%.H par=parfile  attrfile=hin.small%.H restart=d niter=40

/*	Fixheader <PEMFULL/Pem50/h%cube.H >hin%.H*/

in%.H: if not exist in%.H
	Scale <PEMFULL/%cube.H dscale=1.e-15 >in%.H
	Cp <PEMFULL/h%cube.H >hin%.H

/*
norm%.H reci%.H: in%.H
	time BINDIR/Count sxbias=55. attrfile=hin%.H scdfile=csd%.H recifile=reci%.H <in%.H  >norm%.H
*/


sgplot%.V: PEMFULL/cwindow%.H
	Window <PEMFULL/h%cube.H >junk f1=6 n1=1
	Window <PEMFULL/h%cube.H >junk2 f1=8 n1=1
	Merge axis=3 space=n junk junk2 >junk3
	Transp plane=13 <junk3 >junk4
	echo "esize=8 n1=1" >>junk4
	Window n1=1 <junk4 | Graph  symbol="*" >sgplotxx.V title='S-G-Plot %  Pembrook' label1="shot inline" label2="geophone inline"


sg-plot%: sgplot%.V
	Xtpen <sgplot%.V


clean&:
	-RM_CMD *.x *.o  a.out core *.H csd* j* *.v

#include <SEP.idoc.rules>
#include <SEP.obj.rules>
#include <SEP.prog.rules>
