%%% read and plot acoustic transfer function and projection
set(0,'DefaultAxesFontSize',12);
set(0,'DefaultTextFontSize',12);
run /users/swinkels/deploy/MatlabVirgoTools/trunk/startup.m
format longg
%---- read AdV+ design curves
[fO4,hO4]=textread('/users/fiori/home/AdV+/design_curves/O4baseline.txt');
[fO5,hO5]=textread('/users/fiori/home/AdV+/design_curves/O5low.txt');

directory = '/users/fiori/home/AdV/Commissioning/Injections/acoustic/results/O3/CEB/CEB_MIC/';
%filename=[directory,'1269251298_ENV_CEB_MIC_combinedTF.txt'];
filename=[directory,'1269425000_ENV_CEB_MIC_no_SQZ_combinedTF.txt']; % SQZ shutter closed
%directory = '/users/fiori/home/AdV/Commissioning/Injections/acoustic/results/O3/CEB/EDB_MIC/';
%filename=[directory,'1269422000_ENV_EDB_MIC_combinedTF.txt'];
%directory = '/users/fiori/home/AdV/Commissioning/Injections/acoustic/results/O3/CEB/SQZ_MIC/';
%filename=[directory,'1269422000_ENV_SQZ_MIC_combinedTF.txt'];
%filename=[directory,'1269425000_ENV_SQZ_MIC_no_SQZ_combinedTF.txt']; % SQZ shutter closed

% read parameters from 3rd line
[where,ch1,ch2,gps,dur,fs,T,THR_Hrec,THR_sensor,sk_hrec,sk_sensor]=textread(filename,'%s %s %s %f %f %f %f %f %f %f %f',1,'delimiter',',','commentstyle','matlab','headerlines',2);

[yy,mm,dd]=datevec(gps2utc(gps));
datestring = [num2str(dd),'/',num2str(mm),'/',num2str(yy)]

% read values starting from line 7th
[f,hrec,mic,flagUL,proj,TF]=textread(filename,'','delimiter',',','commentstyle','matlab','headerlines',6);

%%
proj_measured = proj.*flagUL;
idx = find(proj_measured==0);
proj_measured(idx)=NaN;
%%

figure(100)
loglog(f,hrec,'k'); hold on; 
loglog(f,proj,'.','Color',[0.7,0.7,0.7],'MarkerFaceColor',[0.7,0.7,0.7],'MarkerSize',3); 
loglog(f,proj_measured,'.r','MarkerSize',3, 'MarkerFaceColor','g'); 
ylim([1e-25 1e-20]); % axis tight;
grid on
loglog(fO4,hO4)
loglog(fO5,hO5)
hold off;
ylabel('[1/sqrt(Hz)]')
xlabel('Frequency [Hz]')
title(['Acoustic projection: ',strrep(char(ch2),'_','\_'),', ',datestring]);
xlim([10 fs/2])
legend([strrep(char(ch1),'_','\_')],'upper limit','measured','O4 design','O5 design');
ylim([1e-25 1e-20])

filename = [directory,char(ch2),'_',char(where),'_projection','.png'];
saveas(gcf,filename,'png');
filename = [directory,char(ch2),'_',char(where),'_projection','.fig'];
saveas(gcf,filename,'fig');
