function [Pff Dr E]= calc_directivity_AGORA_gui(F0,theta,phi,ArrayGeo,P)
%     HO SERTLEK 2015 , University of Leiden
%     Version 2.0
%     This function calculates the far field signature of airgun array [Eq.24 from Duren,1988]

%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.see <http://www.gnu.org/licenses/>.
N=ArrayGeo.N;
x=ArrayGeo.x;
y=ArrayGeo.y;
zg=ArrayGeo.zg;
%zr=ArrayGeo.zr(1);
input_to_AGORA
%%
Pff(1:length(F0))=0; 
j_im=sqrt(-1);
k=2*pi.*F0./cw;
Rv(1)=sin(phi).*cos(theta);
Rv(2)=sin(phi).*sin(theta); 
Rv(3)=cos(phi);   
Rv(find(abs(Rv)<eps))=0;  % if the numbers are smaller than machine epsilon, set to 0 for the stability of algorithm
for i=1:2*N
    if i<N+1
         ai=[x(i) y(i) zg(i)].';         
         An=P(i,1:length(F0));     % Spectrum of notional signatures
         td(i)=(dot(Rv,(ai)));%travel distance
    elseif i>N
         ai=[x(i-N) y(i-N) -zg(i-N)].';         
         An=-P(i-N,1:length(F0));        
         td(i)=(dot(Rv,(ai)));
    end
        Pff=Pff +An.*exp(j_im.*k.*(td(i)));  
end
