%this routine uses result of a Mie code to give the 
%optical properties of particles assuming a Junge distribution.
%for simplicity we assume the value at the lower boundary of each size bin to be representative of the whole bin.
%Note: this extends the population beyond D_max

clear all

load phyto_data

nn=length(D);
lambda=wavel;

delta_D=diff(D);
delta_D(nn)=delta_D(nn-1)*fac;

%distribution function
f=5*10^4*D.^(-4);
f=f*10^-12; %in order to have #particles in micron^3
%Calculate the contribution from each size class factor 10^6 to get in m^-1
a_per_bin=pi/4*(Qext-Qscat).*f.*D.^2.*delta_D*10^6; 
a=sum(a_per_bin);
b_per_bin=pi/4*Qscat.*f.*D.^2.*delta_D*10^6; 
b=sum(b_per_bin);
bb_per_bin=pi/4*Qbb.*f.*D.^2.*delta_D*10^6; 
bb=sum(bb_per_bin);
c_per_bin=pi/4*Qext.*f.*D.^2.*delta_D*10^6; 
c=sum(c_per_bin);
VSF=sum(b_per_bin'*ones(1,181).*S11);

figure(1)
subplot(2,1,1)
semilogy([0:1:180],S11(:,:)')
subplot(2,1,2)
semilogy([0:1:180],VSF)

figure(2)
subplot(2,1,1)
loglog(D,c_per_bin)
title('c per bin')

subplot(2,1,2)
loglog(D,b_per_bin)
title('b per bin')

figure(6)
subplot(2,1,1)
loglog(D,a_per_bin)
title('a per bin')

subplot(2,1,2)
loglog(D,bb_per_bin)
title('b_b per bin')


