%read DIW data:
wl=[400 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];


[dat]=rd_bb9('bb9_dark.TXT');
a_dark(1:9)=median(dat(:,[5:2:21]));
b_dark(1:9)=prctile(dat(:,[5:2:21]),84)-prctile(dat(:,[5:2:21]),16);

[dat]=rd_bb9('bb9_B_DIW.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('bb9_G_DIW.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('bb9_R_DIW.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,'--')
hold off

[dat]=rd_bb9('bb9_B_2drops.TXT ');
a_2d(1:3)=median(dat(:,[5,7,9]));
b_2d(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('bb9_G_2drops.TXT ');
a_2d(4:6)=median(dat(:,[11,13,15]));
b_2d(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('bb9_R_2drops.TXT ');
a_2d(7:9)=median(dat(:,[17,19,21]));
b_2d(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

figure(2)
plot(wl,(a_2d-a_diw).*cal_fac)
hold on
plot(wl,(a_2d-a_diw+b_2d/2).*cal_fac,'--')
plot(wl,(a_2d-a_diw-b_2d/2).*cal_fac,'--')

[dat]=rd_bb9('bb9_B_4drops.TXT');
a_4d(1:3)=median(dat(:,[5,7,9]));
b_4d(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('bb9_G_4drops.TXT');
a_4d(4:6)=median(dat(:,[11,13,15]));
b_4d(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('bb9_R_4drops.TXT');
a_4d(7:9)=median(dat(:,[17,19,21]));
b_4d(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

plot(wl,(a_4d-a_diw).*cal_fac,'k')
plot(wl,(a_4d-a_diw+b_4d/2).*cal_fac,'k--')
plot(wl,(a_4d-a_diw-b_4d/2).*cal_fac,'k--')

[dat]=rd_bb9('bb9_B_8drops.TXT');
a_8d(1:3)=median(dat(:,[5,7,9]));
b_8d(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('bb9_G_8drops.TXT');
a_8d(4:6)=median(dat(:,[11,13,15]));
b_8d(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('bb9_R_8drops.TXT');
a_8d(7:9)=median(dat(:,[17,19,21]));
b_8d(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

plot(wl,(a_8d-a_diw).*cal_fac,'g')
plot(wl,(a_8d-a_diw+b_8d/2).*cal_fac,'g--')
plot(wl,(a_8d-a_diw-b_8d/2).*cal_fac,'g--')

[dat]=rd_bb9('bb9_B_16drops.TXT');
a_16d(1:3)=median(dat(:,[5,7,9]));
b_16d(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('bb9_G_16drops.TXT');
a_16d(4:6)=median(dat(:,[11,13,15]));
b_16d(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('bb9_R_16drops.TXT');
a_16d(7:9)=median(dat(:,[17,19,21]));
b_16d(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

plot(wl,(a_16d-a_diw).*cal_fac,'r')
plot(wl,(a_16d-a_diw+b_16d/2).*cal_fac,'r--')
plot(wl,(a_16d-a_diw-b_16d/2).*cal_fac,'r--')

[dat]=rd_bb9('bb9_B_32drops.TXT');
a_32d(1:3)=median(dat(:,[5,7,9]));
b_32d(1:3)=prctile(dat(:,[5,7,9]),84)-prctile(dat(:,[5,7,9]),16);
[dat]=rd_bb9('bb9_G_32drops.TXT');
a_32d(4:6)=median(dat(:,[11,13,15]));
b_32d(4:6)=prctile(dat(:,[11,13,15]),84)-prctile(dat(:,[11,13,15]),16);
[dat]=rd_bb9('bb9_R_32drops.TXT');
a_32d(7:9)=median(dat(:,[17,19,21]));
b_32d(7:9)=prctile(dat(:,[17,19,21]),84)-prctile(dat(:,[17,19,21]),16);

plot(wl,(a_32d-a_diw).*cal_fac,'r')
plot(wl,(a_32d-a_diw+b_32d/2).*cal_fac,'r--')
plot(wl,(a_32d-a_diw-b_32d/2).*cal_fac,'r--')

hold off

figure(3)
plot(wl,(a_2d-a_diw).*cal_fac/(a_2d(7)-a_diw(7))/cal_fac(7))
hold on
plot(wl,(a_4d-a_diw).*cal_fac/(a_4d(7)-a_diw(7))/cal_fac(7))
plot(wl,(a_8d-a_diw).*cal_fac/(a_8d(7)-a_diw(7))/cal_fac(7))
plot(wl,(a_16d-a_diw).*cal_fac/(a_16d(7)-a_diw(7))/cal_fac(7))
plot(wl,(a_32d-a_diw).*cal_fac/(a_32d(7)-a_diw(7))/cal_fac(7))
hold off

