close all
clear all
%
% plotting apparent resistivity and phase for apr-files
% no errorbars for loglog plots
%

num_files = input('enter number of curves 1 or 2 (with reference)')

% plotting of only 1 data set
if num_files == 1
    [fname,pathname]=uigetfile('*.apr','Select data file');

    cfile=[pathname fname]
    data = load (cfile);
    [nper ncol]=size(data)

    figure
    %semilogy (F(2:nf),sqrt(P11(2:nf)))
    loglog(data(:,1),data(:,2),'-or',data(:,1),data(:,6),'-sb')
       
    xlabel 'Period (s)'
    ylabel 'Apparent resistivity (ohm.m)'
    ht=title ([fname]);
    set (ht,'Interpreter','none')
    legend ('RHOxy','RHOyx')

    figure
    semilogx(data(:,1),data(:,4),'-or',data(:,1),data(:,8),'-sb')
         
    xlabel 'Period (s)'
    ylabel 'Phase (degree)'
    ht=title ([fname]);
    set (ht,'Interpreter','none')
    legend ('PHSxy','PHSyx')
end

% plotting data set and reference data
if num_files == 2 
    [fname,pathname]=uigetfile('*.apr','Select reference data file');

    cfile=[pathname fname]
    refdata = load (cfile);
    [nper ncol]=size(refdata)


    [fname,pathname]=uigetfile('*.apr','Select data file');
 
    cfile=[pathname fname]
    data = load (cfile);
    [nper ncol]=size(data)

    figure
    %semilogy (F(2:nf),sqrt(P11(2:nf)))
    loglog(data(:,1),data(:,2),'-or',data(:,1),data(:,6),'-sb', ...
           refdata(:,1),refdata(:,2),'-*k',refdata(:,1),refdata(:,6),'-*k')
    xlabel 'Period (s)'
    ylabel 'Apparent resistivity (ohm.m)'
    ht=title ([fname]);
    set (ht,'Interpreter','none')
    legend ('RHOxy','RHOyx', 'ref xy','ref yx')

    figure
    semilogx(data(:,1),data(:,4),'-or',data(:,1),data(:,8),'-sb', ...
             refdata(:,1),refdata(:,4),'-*k',refdata(:,1),refdata(:,8),'-*k')
    xlabel 'Period (s)'
    ylabel 'Phase (degree)'
    ht=title ([fname]);
    set (ht,'Interpreter','none')
    legend ('PHSxy','PHSyx','ref xy','ref yx')
end

% figure  %test with errorbars
% semilogx(data(:,1),data(:,4),'-or',data(:,1),data(:,8)+180,'-sb')
% xlabel 'Period (s)'
% ylabel 'Phase (degree)'
% ht=title ([fname]);
% set (ht,'Interpreter','none')
% legend ('PHSxy','PHSyx+180°')
% 
% figure
% errorbar(data(:,1),data(:,4),data(:,5),'-or')
% errorbarlogx
% hold on
% errorbar(data(:,1),data(:,8)+180,data(:,9),'-sb')
% errorbarlogx
% xlabel 'Period (s)'
% ylabel 'Phase (degree)'
% ht=title ([fname]);
% set (ht,'Interpreter','none')
% legend ('PHSxy','PHSyx+180°')
% hold off