%read DIW data:
wl=[406 440 488 510 532 595 660 676 715]
cal_fac=[9.98e-6 1.31e-5 1.03e-5 9.01e-6 8.14e-6 5.59e-6 4.17e-6 7.42e-6 5.29e-6];
%cal_fac=[1.01646E-05,1.28855E-05,9.41591E-06,8.41375E-06,7.75941E-06,5.15017E-06,4.09204E-06,3.61327E-06,3.48711E-06];
offset=[49 67 43 79 64 73 37 54 54];
%cal_fac=[0.0000113583 0.0000480940 0.0000115762 0.0000087234 0.0000083901 0.0000166103 0.0000046500 0.0000036400 0.0000033084];
%cal_fac=[1.1014E-05 1.37626E-05 9.81093E-06 8.37738E-06 8.15194E-06 5.08848E-06 4.06171E-06 3.57627E-06 4.32096E-06];

%offset=[50.091 52.818 41.606 53.941 77.853 82.294 43.219 52.313 49.25];


[dat]=rd_bb9('DIW_bb9_b_020305.TXT');
a_diw(1:3)=median(dat(:,[5,7,9]));
b_diw(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('DIW_bb9_g_020305.TXT');
a_diw(4:6)=median(dat(:,[11,13,15]));
b_diw(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('DIW_bb9_r_020305.TXT');
a_diw(7:9)=median(dat(:,[17,19,21]));
b_diw(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

figure(1)
plot(wl,(a_diw-offset).*cal_fac)
hold on
plot(wl,(a_diw+b_diw/2-offset).*cal_fac,'--')
plot(wl,(a_diw-b_diw/2-offset).*cal_fac,'--')


[dat]=rd_bb9('FSW_bb9_b_020305.TXT');
a_fsw(1:3)=median(dat(:,[5,7,9]));
b_fsw(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('FSW_bb9_g_020305.TXT');
a_fsw(4:6)=median(dat(:,[11,13,15]));
b_fsw(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('FSW_bb9_r_020305.TXT');
a_fsw(7:9)=median(dat(:,[17,19,21]));
b_fsw(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

plot(wl,(a_fsw-offset).*cal_fac,'k')
plot(wl,(a_fsw+b_fsw/2-offset).*cal_fac,'k--')
plot(wl,(a_fsw-b_fsw/2-offset).*cal_fac,'k--')
hold off

[dat]=rd_bb9('A50ml_bb9_b_020305.TXT');
a_50ml(1:3)=median(dat(:,[5,7,9]));
b_50ml(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('A50ml_bb9_g_020305.TXT');
a_50ml(4:6)=median(dat(:,[11,13,15]));
b_50ml(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('A50ml_bb9_r_020305.TXT');
a_50ml(7:9)=median(dat(:,[17,19,21]));
b_50ml(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

figure(2)
plot(wl,(a_50ml-a_fsw).*cal_fac)
hold on
plot(wl,(a_50ml-a_fsw+b_50ml/2).*cal_fac,'--')
plot(wl,(a_50ml-a_fsw-b_50ml/2).*cal_fac,'--')

[dat]=rd_bb9('A150ml_bb9_b_020305.TXT');
a_150ml(1:3)=median(dat(:,[5,7,9]));
b_150ml(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('A150ml_bb9_g_020305.TXT');
a_150ml(4:6)=median(dat(:,[11,13,15]));
b_150ml(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('A150ml_bb9_r_020305.TXT');
a_150ml(7:9)=median(dat(:,[17,19,21]));
b_150ml(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

plot(wl,(a_150ml-a_fsw).*cal_fac,'k')
plot(wl,(a_150ml-a_fsw+b_150ml/2).*cal_fac,'k--')
plot(wl,(a_150ml-a_fsw-b_150ml/2).*cal_fac,'k--')

[dat]=rd_bb9('A300ml_bb9_b_020305.TXT');
a_300ml(1:3)=median(dat(:,[5,7,9]));
b_300ml(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('A300ml_bb9_g_020305.TXT');
a_300ml(4:6)=median(dat(:,[11,13,15]));
b_300ml(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('A300ml_bb9_r_020305.TXT');
a_300ml(7:9)=median(dat(:,[17,19,21]));
b_300ml(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

plot(wl,(a_300ml-a_fsw).*cal_fac,'g')
plot(wl,(a_300ml-a_fsw+b_300ml/2).*cal_fac,'g--')
plot(wl,(a_300ml-a_fsw-b_300ml/2).*cal_fac,'g--')

[dat]=rd_bb9('A800ml_bb9_b_020305.TXT');
a_800ml(1:3)=median(dat(:,[5,7,9]));
b_800ml(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('A800ml_bb9_g_020305.TXT');
a_800ml(4:6)=median(dat(:,[11,13,15]));
b_800ml(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('A800ml_bb9_r_020305.TXT')
a_800ml(7:9)=median(dat(:,[17,19,21]));
b_800ml(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

plot(wl,(a_800ml-a_fsw).*cal_fac,'r')
plot(wl,(a_800ml-a_fsw+b_800ml/2).*cal_fac,'r--')
plot(wl,(a_800ml-a_fsw-b_800ml/2).*cal_fac,'r--')
hold off

figure(3)
plot(wl,(a_800ml-a_fsw).*cal_fac/(a_800ml(7)-a_fsw(7))/cal_fac(7))
hold on
plot(wl,(a_300ml-a_fsw).*cal_fac/(a_300ml(7)-a_fsw(7))/cal_fac(7))
plot(wl,(a_150ml-a_fsw).*cal_fac/(a_150ml(7)-a_fsw(7))/cal_fac(7))
plot(wl,(a_50ml-a_fsw).*cal_fac/(a_50ml(7)-a_fsw(7))/cal_fac(7))
hold off

