prc=load('PRC_POP18frz_tsdata.txt');


t=prc(:,1);

ind=find(and(t>=4.2,t<5.0));
ind2=find(and(t>=4.37,t<4.84));
t=prc(ind,1);
p=prc(ind,2);
tt=prc(ind2,1);
pp=prc(ind2,2);

[pk,vpk,pk2,vpk2]=pkFind(t,p,50,17);
ct=1:length(pk);
cct=spline(pk,ct,tt);


gp=360*mod(spline(pk,ct,pk2),1);

owgp=mean(gp)/2;
owgp_sdev=std(gp)/2;

owgp_sdevMn=(std(gp)/sqrt(length(gp)))/2;

%plot(tt,cct,pk,ct)
%plot(t,p);
if 1

plot(360*mod(cct,1),pp,'d',2*owgp*[1,1],[0,160],'r-',4*owgp*[1,1],[0,160],'r-');
grid on
axis([0,120,-10,180]);
xlabel('Gouy phase (deg)')
ylabel('power (cts)')
title(['PRC Gouy phase measurement: ',num2str(owgp,4),'deg +-',num2str(owgp_sdevMn,1),'deg (statistical error of mean, ',num2str(length(gp)),' measurements)']);
%plot(t,cct,pk,ct)
%plot(t,p,'d');
end