% AGORA-single gun example
% This script is an example how agora_kernel function can be used.
% Ozkan Sertlek, 2015, University of Leiden

ArrayGeo.Pg=2000;   % firing presssure [psi]
ArrayGeo.Vg=80;     % airgun chamber size [in3]
ArrayGeo.zg=6;      % firing depth [m]

ArrayGeo.N=1; % Number of airguns
ArrayGeo.x=0; % x location of gun  [m]
ArrayGeo.y=0; % y location of gun [m]
ArrayGeo.zr=9000;  % receiver depth [m]

[Signature]=agora_kernel(ArrayGeo)

subplot(2,1,1)
plot(Signature.Time_Ax,Signature.p_unperturbed,'r','LineWidth',3 )
xlabel('Time (ms)', 'FontSize', 20)
ylabel('Notional Signature [Pa.m]', 'FontSize', 20)
grid on

subplot(2,1,2)
plot(Signature.Time_Ax,Signature.p_bi_ghost,'LineWidth',3 )
xlabel('Time (ms)', 'FontSize', 20)
ylabel('Signature with Ghost [Pa.m]', 'FontSize', 20)
grid on

%% Vertical directivity of single airgun
az_angle=90; % azimuth angle
f_ind=1000;  % max freq index

phi=  linspace(-pi/2,pi/2,181); %elevation
F0=Signature.F0i;
Pff_ver(1:length(F0),1:length(phi))=0;
cw=1500; rhow=1020;
% adds surface ghost for dipole 
for pp=1:length(phi)
    Pff_ver(:,pp)= calc_directivity_AGORA_gui(Signature.F0i,az_angle,phi(pp),ArrayGeo,Signature.P_out);
end

Eef=Pff_ver.*conj(Pff_ver) ./(rhow*cw);
ESL_f=10*log10(abs((10^12).*Eef.*(rhow*cw)));
figure
plot(Signature.F0i,squeeze(ESL_f(:,90)))

figure;
polarplot3d(ESL_f(1:f_ind,:),'plottype','surfcn','radialrange',F0(1:f_ind),'InterpMethod','nearest','AxisLocation','off','PolarDirection','cw','AngularRange',[0 pi]);
caxis([100 max(ESL_f(:))]);colorbar('SouthOutside');
%ylabel('f [Hz]');
grid on
colormap hot;
axis([0 F0(f_ind) -F0(f_ind) F0(f_ind)])
view(90,90)
set(gca, 'YAxisLocation', 'right')
set(gca,'xticklabel',[]);
axis equal tight
