clear all
close all

datadir=fullfile('..','raw');

load(fullfile(datadir,'PT_data_2'))

i1=pt.bstart;
i2=pt.bend;

sd=pt.sdate;
dp=pt.pressure;

for i=1:length(i1)
% i=1
    
    inds=[i1(i):i2(i)];
    
    tt=sd(inds);
    
    td=dp(inds);
    
    [res,names,spect] = wavesp(td,0.3,5);
    
    wavess(i,:)=res;
    
    spectrums{i}=spect;
    
    tim(i,1)=mean(tt);
    
end

tmin=min(tim);
tmax=max(tim);

cinds=[1; 5; 3];

labs={'Depth (m)';'Significant Wave Height (m)';'Peak Period (s)'};

lc=length(cinds);

icolor=make_icol_scheme;

for ii=1:lc
    
    subplot(lc,1,ii)

    int=20;
    
     s1=tim;
    a1=wavess(:,cinds(ii));

    plot(s1,a1,'Color',icolor(:,ii)),axis([tmin tmax min(a1) max(a1)]);

    set(gca,'XTick',(tmin:(tmax-tmin)/int:tmax),'XMinorTick','on','TickDir','out','XTickLabel',datestr((tmin:(tmax-tmin)/int:tmax),19),'FontSize',8);


    %     title([labs2{i}])

    %     a2=desp4(a,1,10,10);

    % xlabel('Date')
    grid on 
    box on
    ylabel(labs{ii})
    
end

print('-dtiff',fullfile(datadir,'infinity_analysis_example'))

for i=1:length(names)

    temp=['infinity.' names{i} '=wavess(:,i);'];
    
    eval(temp)
    
end

infinity.sdate=tim;
infinity.names=names;
infinity.spectra=spectrums;

save(fullfile(datadir,'infinity_processed_example'),'infinity')