
fileOUT = 'LHO_diff_lens.mat';
chans = {'H1:TCS-ITMX_HWS_PROBE_SPHERICAL_POWER.mean,m-trend', ...
    'H1:TCS-ITMY_HWS_PROBE_SPHERICAL_POWER.mean,m-trend', ...
    'H1:TCS-ITMX_CO2_LSRPWR_MTR_OUTPUT.mean,m-trend', ...
    'H1:TCS-ITMY_CO2_LSRPWR_MTR_OUTPUT.mean,m-trend', ...
    'H1:TCS-ITMY_HWS_MAGNIFICATION.mean,m-trend', ...
    'H1:ASC-X_TR_A_NSUM_OUTPUT.mean,m-trend', ...
    'H1:ASC-X_TR_A_SUM_OUTPUT.mean,m-trend', ...
    'H1:IMC-TRANS_OUTPUT.mean,m-trend'};

t0 = 1152482417
dt = 3600*12;

if exist(fileOUT, 'file') == 0

    [data1, t, info] = get_data(t0,t0+dt,chans, []);
    save(fileOUT, 'data1', 't', 'info');
else
    load(fileOUT);
end


data1(:,1) = 1E6*(data1(:, 1) - data1(1,1));
data1(:,2) = 1E6*(data1(:, 2) - data1(1,2))*(17.5/7.5)^2;

close all
subplot(2,2,1)
plot(data1(:, 1) )
hold all
grid on
xlabel('Time (min)')
ylabel('Defocus (\muD)')
plot(data1(:, 2))
axis([0 700 -100 100])
legend('HWSX', 'HWSY')

subplot(2,2,2)
plot(0.5*(data1(:, 1) +data1(:, 2)))
hold all
grid on
xlabel('Time (min)')
ylabel('Defocus (uD)')
plot((data1(:, 2) - data1(:, 1)))
axis([0 700 -100 100])
legend('Common Lens', 'Diff Lens')

subplot(2,2,3)
plot(data1(:, 3))
hold all
plot(data1(:, 4))
grid on
xlabel('Time (min)')
ylabel('Power (W)')
axis([0 700 0 2])
legend('XCO2', 'YCO2')

subplot(2,2,4)
plot((data1(:, 3) + data1(:, 4))*0.5)
hold all
plot((data1(:, 4) - data1(:, 3)))
grid on
xlabel('Time (min)')
ylabel('Power (W)')
axis([0 700 -2.2 1])
legend('Common CO2', 'Diff CO2')

orient landscape
print('-dpdf', [mfilename(), '.pdf']);




normOut = (data1(:, 7)./data1(:, 8));
ind1 = find(data1(:, 7) > 5E3);
figure
commLens = 0.5*(data1(:, 1) +data1(:, 2));
plot(commLens(ind1), normOut(ind1), 'o')
grid on
xlabel('Common Lens (\muD)')
ylabel('TR-X\_SUM/IMC\_OUTPUT')
ylim([3.2 5.2])
orient landscape

print('-dpdf', 'gain_vs_commonLens.pdf')

figure
diffLens = (data1(:, 2) -data1(:, 1));
plot(diffLens(ind1), normOut(ind1), 'o')
grid on
xlabel('Diff Lens (\muD)')
ylabel('TR-X\_SUM/IMC\_OUTPUT')
ylim([3.2 5.2])
orient landscape
print('-dpdf', 'gain_vs_diffLens.pdf')

figure
ind1 = find(data1(:, 7) < 5E3);
normOut(ind1) = 0;
plot(normOut)
xlabel('Time (min)')
ylabel('TR-X\_SUM/IMC\_OUTPUT')
grid on
ylim([3.2 5.2])
orient landscape

print('-dpdf', 'gain_vs_time.pdf')
