function [migi]=migrate_tt(cdp1,nx,nz,ntime,dt,ap,dx,dz,TOZS,TOZE)
migi=zeros(nx,TOZE-TOZS+1);
% for q=1:ntrace;cdp2(q,:)=xcorr(rick,cdp1(q,:));end; %
% cdp3=cdp2*0;for i=1:ntime;cdp3(:,i)=cdp2(:,ntime+i-1);end;

dzz=16.67;%traveltime spacing
for ixtrace=1:nx;
    ixtrace
    istart=1 + (ixtrace-1)-ap;iend=1+ (ixtrace-1)+ap;
    if istart<1;istart=1;end;
    if iend>nx;iend=nx;end;
    
    fn=sprintf('TT/TT_%d',ixtrace);
    load(fn);
    time=time';
    %time=1.05*time';
   
    for ixs=istart:iend;
        for izs=TOZS:TOZE;
            d=izs*dz;
            x=(ixtrace*dx-ixs*dx);
            r = sqrt(x^2+d^2);
            
            % Interpolare traveltime
            id1=round(d/dzz);
            d1=id1*dzz;
            d2=(id1+1)*dzz;  
            t1=time(ixs,id1);
            t2=time(ixs,id1+1);
            t=round(2*((d2-d)*t1+(d-d1)*t2)/dzz/dt)+1;
            
            %Obliquity factor
            obl=d/r;
            
            if t <= ntime
                migi(ixs,izs-TOZS+1) = migi(ixs,izs-TOZS+1) + obl*cdp1(ixtrace,t)/r;
                %migi(ixs,izs-TOZS+1) = migi(ixs,izs-TOZS+1) + cdp1(ixtrace,t)/r;
            end
        end;
    end;
end;
