%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Single Scattering Prestack Diffraction Stack Modeling
% and migration. Source is on surface at (sx,0) and 
% geophones at (gx,0) for 0<gx<nx.
% Homogeneous velocity model with velocity c and
% reflectivity model R(i,j)
%  
% (nx,nz)  - input- Dimensions of Model
% (dx,dz)  - input- Spatial Sampling Intervals
% (dt,sx)  - input- Time sampling interval, source x-index 
% W(t)     -output- Ricker Wavelet with Central freq=fr
% D(g,t)   -output- Shot gather for a source at (sx,0)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
np=200;
sx=10;nx=75;                                    % Define Source Position
nz=nx;c=1000;dt=.01;dx=7;dz=dx;fr=20;
[rick]=ricker(np,fr,dt);                       % Create Ricker Source Wavelet
nt=round(sqrt((dx*nx)^2+(dz*nz)^2)*2/c/dt+1)
nd2=round(nt)+2; W=zeros(2*nt,1); 
W(nt:nt+np-1)=rick(1:np);                      % Center-Time Shift Wavelet
R=zeros(nx,nz);R(round(nx/2),round(nz/2))=1;   % Define Refl. Model

[TGX]=TIME(R,nx,nz,nt,dx,dz,dt,c,sx,W,nd2);    % Traveltime Table
[D]=forw(R,nx,nz,nt,dx,dz,dt,c,sx,W,nd2,TGX);  % Compute Shot Gather
[R]=mig(D,nx,nz,nt,dx,dz,dt,c,sx,W,nd2,TGX);   % Migrate Shot Gather
