% Get beta_p and bbp for all cast
%
% Author: Nils Haentjens, Ms, University of Maine
% Email: nils.haentjens@maine.edu
% Created: 30th July 2015
% Last update: 30th July 2015

clear;
load('cruise/iop_l2');
addpath ../utils/misc_lab/
addpath ../utils/data_ie/

iop_l3b = struct();
for i=1:22;%size(i_stn,2);
  % Copy ctd
  iop_l3b(i).p = iop(i).p;
  iop_l3b(i).t = iop(i).t;
  iop_l3b(i).s = iop(i).s;
  iop_l3b(i).sig = iop(i).sig;
  
  % process ECO-BB9 and ECO-VSF
  [iop_l3b(i).bbp_BB9, iop_l3b(i).beta_p_BB9] = compute_bbp(iop(i).bb9, iop(i).t, iop(i).s, meta.wl_bb9, 117);
  [iop_l3b(i).bbp_VSF, iop_l3b(i).beta_p_VSF] = compute_bbp(iop(i).bb3, iop(i).t, iop(i).s, 650, meta.scat_angle);
end;

%% Export Level 3 b (no ACS and WS3S)
iop = iop_l3b;
save('cruise/iop_l3b', 'iop', 'meta');
for i=1:22;
  % Adding wavelength for csv struct
  iop(i).wl_bb9 = meta.wl_bb9;
  iop(i).scat_angle = meta.scat_angle;
end;
struct2csv(iop, 'cruise/iop_l3b.csv');

%%
fig(200, 'debug'); i=12;
plot(iop_l3b(i).bbp_BB9, iop_l3b(i).p);
axis('ij');