#! /bin/sh

set -x

# ------------------------------------------------------
# DCDemo2 -  Demo for data mapping downward continuation 
# code SUKDMDCR
# ------------------------------------------------------
#
# This demo downward continues the receivers and the sources
# in the data generated by DataDemo2, to a horizontal 
# datum.  This demo is set up for a simple constant 
# wavespeed model with horizontal recording and
# reflecting surfaces, but the script includes general 
# commands that can serve as a template for more complex
# models. 


# Define the velocity model:

  nxvm=150
  dxvm=12.5
  nzvm=251
  dzvm=10

# Define the travel time table:

  nxt=150
  dxt=12.5
  fzt=0
  nzt=161 
  dzt=10  

  fst=0
  nst=150
  dst=12.5

# Define the input data: 

  foff=0	
  noff=100
  doff=12.5

  nts=1600
  dts=0.002

  fshot=0
  nshot=25
  dshot=12.5

  v0=2000
  freq=20

# Define the datum depth:

  datumdepth=300.0

# Define the half-aperture in meters: 

  aper=1250.

# Define a full velocity model for ray tracing:

   unif2 < vel.mod > vel.out nx=$nxvm dx=$dxvm nz=$nzvm dz=$dzvm ninf=6\
   v00=2000,2000,2000,2000,2000,2000,2000

   smooth2 < vel.out n1=$nzvm n2=$nxvm r1=10 r2=10 > smvel.out

# Trace rays between recording surface and the datum (even though
# data mapping depends on paths to stationary points below the 
# datum, this implementation uses a straight ray approximation
# for amplitude determination, and uses ray traced times for the 
# kinematic calculation.  Since the kinematics depends only on
# times above the datum, ray tracing is only required for this 
# region, here.)
 
    rayt2d vfile=vel.out tfile=times2.out dt=$dts nt=$nts \
       	fz=0 nz=$nzvm dz=$dzvm fx=0 nx=$nxvm dx=$dxvm \
  	nxo=$nxt dxo=$dxt fxo=0 nzo=$nzt dzo=$dzt fzo=$fzt\
       	fxs=$fst nxs=$nst dxs=$dst  \
 	verbose=1

# Sort the data for receiver continuation:

   susort <demo2.data >hold.out +sx +gx

# Downward continue receivers:

   sukdmdcr < hold.out > demo.out ttfile=times2.out \
        fzt=$fzt nzt=$nzt dzt=$dzt fxt=0 nxt=$nxt dxt=$dxt \
        fs=$fst ns=$nst ds=$dst \
        dt=$dts ft=0.0 \
        fzo=0 dzo=$dzt nzo=$nzt fxso=0 \
        nxso=$nshot dxso=$dshot \
        fxgo=0 nxgo=$noff dxgo=$doff \
        mtr=10 v0=$v0 dvz=0.0 \
        aperx=$aper verbose=1 freq=$freq\
        zrec=0.0 zdat=$datumdepth 

  rm hold.out

# Resort the data four source continuation:

  susort <demo.out >hold.out +gx +sx

# Downward continue sources (set dc=1 to indicate that
# the receivers are already on the datum):

  sukdmdcs < hold.out > demo2.out ttfile=times2.out \
        fzt=$fzt nzt=$nzt dzt=$dzt fxt=0 nxt=$nxt dxt=$dxt \
        fs=$fst ns=$nst ds=$dst \
        dt=$dts ft=0.0 \
        fzo=0 dzo=$dzt nzo=$nzt fxso=0 \
        nxso=$nshot dxso=$dshot \
        fxgo=0 nxgo=$noff dxgo=$doff \
        mtr=10 v0=$v0 dvz=0.0 \
        aperx=$aper verbose=1 freq=$freq\
        zrec=0.0 zdat=$datumdepth dc=1 

mv demo2.out hold.out
susort <hold.out >demo2.out +sx +gx

rm hold.out

# Now, the data in demo2.out is such that both the sources
# and the receivers are on the datum at 300m depth.


