% Pseudo Shot Generator
% The near offset of every shot profile is missing, the length of missing
% part is 1500ft, the receiver interval is 75ft and the source interval is
% 150ft.
% The data comes from Sigsbee 2B syntheric dataset, every shot gather has
% 348 traces and 1500 time samples. 
% suppose we want to interpolate the nearoffset data in shot "319"
% written by Yibo Wang, UTAM, 2006
% output is the Pseudo Shot we generate
% output1 is the interpolation result
% origin is the original data: shot "319"

function [output,output1,origin]=PSG
output(1:348,1:1500)=0;
origin(1:348,1:1500)=0;
tmp(1:348,1:1500)=0;
gap=20;
for i=319+gap/2:492   % The 18th line, sum over different sources.
% You can change the line above to use different number of shot gathers
    i
    % load data
    fs=['data/csg_fs',num2str(i),'.su'];
    fidfs=fopen(fs,'r');
    for j=1:348
        traceheader=fread(fidfs,60,'int32=>int32');
        origin(j,:)=fread(fidfs,1500,'float32=>float32');
    end
    fclose(fidfs);
    % mute direct wave
    origin=PSG_Mute(origin);
    origin(:,1:350)=0;
    % calculate the cross correlation
    p=2*(i-319)+1;
    tmp_p=origin(p,:);
    for m=p:348
        mm=m-p+1;
        tmp_m=origin(m,:);
        tmp_c=xcorr(tmp_m,tmp_p);
        tmp(mm,:)=tmp_c(1500:2999);
    end
    output(:,:)=output(:,:)+tmp(:,:);
    tmp(:,:)=0;
end
    i=319;
    % load data
    fs=['data/csg_fs',num2str(i),'.su'];
    fidfs=fopen(fs,'r');
    for j=1:348
        traceheader=fread(fidfs,60,'int32=>int32');
        origin(j,:)=fread(fidfs,1500,'float32=>float32');
    end
    origin=PSG_Mute(origin);
    origin(:,1:350)=0;
    fclose(fidfs);
    output1=origin;
    output1(1:gap,:)=output(1:gap,:);
    output1(1:gap,1:1499)=output1(1:gap,2:1500);
