#! /bin/sh
#

modelfile=model10.unif           # input model file for unif2aniso

ninf=3                          # number of interfaces (surface counts)
x0=0,0                      # x-position(s) for  vp00,vs00,rho00, etc.
z0=0,1800			# z-position(s) for  vp00,vs00,rho00, etc.
nz=600                          # size of z (depth) dimension  of model
nx=300                          # size of x (horizontal) dimension of model
dz=5                            # increment in z direction
dx=5                            # increment in x direction
vp00=4000,2000
vs00=2309.3,1154.7
rho00=2500,2100
eps00=0.133,0.0
delta00=0.12,0.0
method=spline			# boundary interpolation scheme for unif2aniso
dt=0.0002                       # time sampling interval
lt=1.6	                        # latest time modeled
fx=0                            # first x value
verbose=1                       # =1 chatty, =0 silent
rhofile="rho_file"
snfile="snaps.su"                # output file for snapshots
hsz=0.0		                # z-position of horizontal line of geophones
vsx=0.0		                # x-position of vertical line of geophones
snaptime=0.02,0.05,.1,.15,.2,.25.3,.35,.4,.45,.5,.55,.6,.65,.7,.75,.8,.85,.9,.95 # times of snapshots
bc=10,20,20,20                      # boundary conditions
qsw=0                              # =1 put in attenuation
asw=1                              # =1 anisotropy
sx=3000                            # x-position of sources
sz=0                              # z-position of sources
favg=30.0                        # average frequency
ts=.05                            # source duration
wtype=ri                          # waveform type
paramtype=1

# take default unif2aniso model
#unif2aniso tfile=$modelfile

# build stiffness and density files
unif2aniso < $modelfile ninf=$ninf x0=$x0 z0=$z0 nz=$nz nx=$nx \
dx=$dx dz=$dz vp00=$vp00 vs00=$vs00 eps00=$eps00 paramtype=$paramtype delta00=$delta00 rho00=$rho00 method=$method

xbox=10
ybox=10
nxplot=`bc -l <<-END
        scale=0
        $nx  / 2
END`
nzplot=`bc -l <<-END
        scale=0
        $nz  / 2
END`
# transpose stiffness and density
for i in c11 c13 c15 c33 c35 c55 rho
do
	echo $xbox $ybox
	ximage <  ${i}_file n1=$nz n2=$nx perc=99 xbox=$xbox \
		ybox=$ybox  wbox=$nxplot hbox=$nzplot  legend=1 \
		title=" ${i} parameter file  "	&
	sleep 2

	xbox=`expr $xbox + 80 `
	ybox=`expr $ybox + 10 `


        mv ${i}_file tmp.file
        transp n1=$nz < tmp.file > ${i}_file
done

rm tmp.file


# run suea2df
suea2df dt=$dt aniso=1 lt=$lt nz=$nz fx=$fx nx=$nx dx=$dx dz=$dz verbose=1 \
snfile=$snfile rhofile=$rhofile hsz=$hsz vsx=$vsx snaptime=$snaptime \
bc=$bc qsw=$qsw c11file=c11_file c55file=c55_file  c13file=c13_file c33file=c33_file c15file=c15_file c35file=c35_file sx=$sx sz=$sz favg=$favg ts=$ts wtype=$wtype \
>out2


n2=`bc -l <<-END
      scale=1
       $nx * 2
END`

echo $n2

suxmovie < snaps.su n1=$nz n2=$n2 clip=1e-13 loop=1 title="snapshots horizontal vertical " width=$nxplot height=$nzplot  sleep=2 &

# shot gathers from a horizontal line of geophones
suximage <  hs.su xbox=0 ybox=400 wbox=$nx hbox=$nz  perc=99 title="  shot gathers  vertical horizontal " &
supswigb <  hs.su xbox=0 ybox=400 wbox=$nx hbox=$nz  perc=99 title="  shot gathers  vertical horizontal " >hs.eps

suwind <hs.su key=tracl min=1 max=600  >hsv.su
suwind <hs.su key=tracl min=601 max=1200 >hsx.su

suwind < hsv.su j=3 | suximage perc=99 &
suwind < hsx.su j=3 | suximage  perc=99 &


exit 0
