#! /bin/sh

set -x

# ------------------------------------------------------
# DCDemo1 -  Demo for data mapping downward continuation 
# code SUKDMDCR
# ------------------------------------------------------
#
# This demo downward continues the receivers in the data 
# generated by DataDemo1 to a horizontal datum, leaving
# the source fixed.  This demo is set up for the 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=201
  dxvm=12.5
  nzvm=251
  dzvm=10

# Define the travel time table:

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

  fst=0
  nst=201
  dst=12.5

# Define the input data: 

  foff=0	
  noff=200
  doff=12.5

  nts=1600
  dts=0.002

  fshot=0
  nshot=1
  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=times1.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

# Preprocess and sort the data:

   susort <demo1.data >hold1.out +sx +gx

# Downward continue:

   sukdmdcr < hold1.out > demo1.out ttfile=times1.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 hold1.out

  suximage <demo1.out title="Output data from Demo 1"

exit 0
