function hs2=calc_Bb(hs2,Cal)

%find real gain number from cal file and hs2 pointers
%while gain < 6
for gain=1:5
    ind=find(hs2.Gain1==gain);
    hs2.Gain1(ind)=Cal.Ch(1).Gain(gain);
    clear ind;
    ind=find(hs2.Gain2==gain);
    hs2.Gain2(ind)=Cal.Ch(2).Gain(gain);
    clear ind;
    ind=find(hs2.Gain3==gain);
    hs2.Gain3(ind)=Cal.Ch(3).Gain(gain);
    clear ind;
    %gain=gain+1;
end;


bbu470=calc_bbu(Cal.Ch(1).TempCoeff,hs2.Temp,Cal.CalTemp,Cal.Ch(1).Mu,Cal.Ch(1).Beta2Bb...
    ,hs2.Snorm1,hs2.Gain1,Cal.Ch(1).RNominal);
bbu676=calc_bbu(Cal.Ch(2).TempCoeff,hs2.Temp,Cal.CalTemp,Cal.Ch(2).Mu,Cal.Ch(2).Beta2Bb...
    ,hs2.Snorm2,hs2.Gain2,Cal.Ch(2).RNominal);
fl676=calc_bbu(Cal.Ch(3).TempCoeff,hs2.Temp,Cal.CalTemp,Cal.Ch(3).Mu,Cal.Ch(3).Beta2Bb...
    ,hs2.Snorm3,hs2.Gain3,Cal.Ch(3).RNominal);

c470=calc_c(bbu470,Cal.Ch(1).Bb2c);
c676=calc_c(bbu676,Cal.Ch(2).Bb2c);
cfl676=calc_c(fl676,Cal.Ch(3).Bb2c);

hs2.Bb470=calc_bb(Cal.Ch(1).Sigma(1),Cal.Ch(1).Sigma(2),Cal.Ch(1).Sigma(3),c470,bbu470);
hs2.Bb676=calc_bb(Cal.Ch(2).Sigma(1),Cal.Ch(2).Sigma(2),Cal.Ch(2).Sigma(3),c676,bbu676);
hs2.Fl676=calc_bb(Cal.Ch(3).Sigma(1),Cal.Ch(3).Sigma(2),Cal.Ch(3).Sigma(3),cfl676,fl676);
hs2.CalDepth=(Cal.DepthCal.*hs2.Depth)-Cal.DepthOff;

%Calibrated
function bbu=calc_bbu(TC,T,CT,Mu,B2Bb,Snorm,Gain,RNom)
    bbu=(1-(TC*T/CT)).*((Mu.*B2Bb.*Snorm)./(Gain.*RNom));

%Sigma Correction
function c=calc_c(bbu,Bb2c)
    c=bbu.*Bb2c;
    
%Calibrated and sigma corrected    
function bb=calc_bb(S1,S2,S3,c,bbu)
    sigma_c=S1+(S2.*c)+(S3.*c.^2);
    bb=bbu.*sigma_c;
  