%   mass_loading.m   ver 1.0  March 12, 2008
%
%   by Tom Irvine   Email: tomirvine@aol.com
%
%   See tutorial: mass_loading.pdf
%
clear m;
clear F;
kg_to_lbm=0.45351;
%
disp(' ');
disp(' Enter analysis type ');
disp(' 1=calculate dB  2=calculate mass ');
itype=input(' ');
disp(' ');
%
if(itype==1)
    disp(' Select unit:  1=lbm  2=kg ');
    iunit=input(' ');
    disp(' ');
    if(iunit==1)
        disp(' Enter mass lbm');
    else
        disp(' Enter mass kg');      
    end
    m=input(' ');
    if(iunit==2)
        m=m/kg_to_lbm;
    end
    F=0;
    if(m>=40)
        F=-3*log(m/40)/log(2);
    end
    out1=sprintf(' F = %6.3g dB',F);
    disp(out1);  
else
    disp(' Enter dB ');
    F=input(' ');
    F=abs(F);
    m=40*exp(((F/3)*log(2)));
    out1=sprintf(' mass= %6.3g lbm = %6.3g kg',m,m*kg_to_lbm);
    disp(out1);
end