%*************************************************************
% ZO Modeling Migration Code
% dx = spatial sampling interval (assume dx=dz)
% c = velocity m/s
% (nx,nz) = grid dimensions of model, trace at each surface pt
% app = migration aperture
% (refl,MIG) = (ZO traces, Poststack Migrated section)
%**************************************************************

clear all
dx=25;dz=dx;c=1500;nit=30; 
nx=75;nz=75;ntrace=nx;dt=.5*0.008;time_table=1;
ntime=round(1.2*sqrt(nx^2+nz^2)*dx/c/dt);app=round(nx/2);
%
% Create Source Wavelet, Reflectivity Model MIG, and Synthetic Data refl
%
    rick=ricker(100,15,dt);tshift=1;     
%
% Create Reflectivity Model MIG, and Synthetic Data refl
%
     MIG=zeros(nx,nz); for i=1:nx/3;MIG(i,round(nz/3))=1;end;
     for i=round(nx*2/3):nx;MIG(i,round(nz/3))=1;end;
     for i=round(nx/3)+1: round(nx*2/3-1);iz=15*sin((i-nx/3+1)*1.9*pi*3/nx/2);
     MIG(i,round(iz+nz/3))=1;end;MOD=MIG;
% Pt Source Model;    MIG=zeros(nx,nz);MIG(nx/2,nz/2)=1;MOD=MIG;
    [cdp1]= model1(MIG,time_table,nx,nx,nz,ntrace,ntime,dt,app,rick,tshift,dx,c);    
    [nx,ntime]=size(cdp1); refl=cdp1;n=nx;
    q=0; migi=zeros(nx,nz); 

%
% Plot Section
%
figure(1);
subplot(211)
imagesc([1:nx]*dx,[1:nz]*dx,ones(nx,nz)'*c+MIG')
colorbar
xlabel('X (m)')
ylabel('Z (m)')
title('Velocity Model');

subplot(212)
imagesc([1:nx]*dx, [1:ntime]*dt,diff(refl(1:nx,:)',1));
colorbar
xlabel('X (m)')
ylabel('Time (s)')
title('Poststack AGC Data in 1-Way Time');
