function ArrayGeo= array_oipen_plot(handles,cond)
 % Ozkan Sertlek, 2015, University of Leiden
% opens and plots the airgun geometry for a selected .*ago file (cond=1)
% and a loaded signature file (cond=0)
if cond==1
    [filename,PathName,FilterIndex] = uigetfile({  '*.ago; *.ans','AGORA Array Geometry file (*.ago) or AGORA Notional Signature File (*.ans)'})
if filename==0
    errordlg('No airgun array geometry (*.ago) file is loaded','Error')
else
%     if filename((end-2):end)=='ans'
%         p_notg=str2num(fgetl(fid));
%         Time_Ax=str2num(fgetl(fid));
%         fclose(fid)
%         fid = fopen( [PathName filename(1:end-2) 'ago'], 'r' );
%         if fid<0
%             errordlg('Array Geometry file cannot be found. Please copy in the same path with *.aas file','Error')
%             [filename,PathName,FilterIndex] = uigetfile({  '*.ago','AGORA Array Geometry file (*.ago)'})
%             fid = fopen( [PathName filename], 'r' );
%       end
%    end
    fid = fopen( [PathName filename], 'r' );
    ArrayGeo.N= str2num(fgetl(fid));
    ArrayGeo.zr(1:ArrayGeo.N)= str2num(fgetl(fid));
    legendmatrix=cell(ArrayGeo.N,1);
    axes(handles.axes_ArrayGeo);
    % cla;        %  set(gca,'XTick',[],'YTick',[],'XLabel',[],'YLabel',[],'Title',[]); % clear axes labels 
    cla
    for i=1:ArrayGeo.N
        arraydata(i,:)=str2num(fgetl(fid));
        ArrayGeo.x(i)= arraydata(i,1);
        ArrayGeo.y(i)=arraydata(i,2); 
        ArrayGeo.zg(i)=arraydata(i,3); 
        ArrayGeo.Vg(i)=arraydata(i,4); 
        ArrayGeo.Pg(i)=arraydata(i,5); 
        hold on
        plot(ArrayGeo.x(i), ArrayGeo.y(i),'rd', 'LineWidth',3);
        text(ArrayGeo.x(i), ArrayGeo.y(i)  , ['G' num2str(i) '=' num2str(ArrayGeo.Vg(i)) 'in3'],'FontSize',8);
        title(['Geometry of Array( ' num2str(ArrayGeo.N) ' airguns ), z_r=' num2str(ArrayGeo.zr(1)) ' m, V_{tot}= ' num2str(sum(ArrayGeo.Vg)) ' in^3'],'Color', 'w');
        axis([ min(ArrayGeo.x)-2 max(ArrayGeo.x)+2 min(ArrayGeo.y)-2 max(ArrayGeo.y)+2 ]) 
      %  ax = gca;
        xtick_vec=round(linspace((min(ArrayGeo.x)-2),(max(ArrayGeo.x)+2),5));
        ytick_vec=round(linspace(floor(min(ArrayGeo.y)-2),ceil(max(ArrayGeo.y)+2),5));
        set(gca,'XTick',xtick_vec,'YTick',ytick_vec);
        xlabel('x(m)');ylabel('y (m)');
        grid on
    end
    ArrayGeo.filename=filename; 
    ArrayGeo.PathName=PathName; 
    fclose(fid)
end
else
    cla
    for i=1:handles.ArrayGeo.N
        hold on
        plot(handles.ArrayGeo.x(i), handles.ArrayGeo.y(i),'rd', 'LineWidth',3);
        text(handles.ArrayGeo.x(i), handles.ArrayGeo.y(i)  , ['G' num2str(i) '=' num2str(handles.ArrayGeo.Vg(i)) 'in3'],'FontSize',8);
        title(['Geometry of Array (' num2str(handles.ArrayGeo.N) ' airguns), z_r=' num2str(handles.ArrayGeo.zr(1)) ' m, V_{tot}= ' num2str(sum(handles.ArrayGeo.Vg)) ' in^3'],'Color', 'w');
        axis([ min(handles.ArrayGeo.x)-2 max(handles.ArrayGeo.x)+2 min(handles.ArrayGeo.y)-2 max(handles.ArrayGeo.y)+2 ]) 
        xlabel('x(m)');ylabel('y (m)');
        xtick_vec=round(linspace((min(handles.ArrayGeo.x)-2),(max(handles.ArrayGeo.x)+2),5));
        ytick_vec=round(linspace(floor(min(handles.ArrayGeo.y)-2),ceil(max(handles.ArrayGeo.y)+2),5));
        set(gca,'XTick',xtick_vec,'YTick',ytick_vec);        grid on
    end
end