function [uncor_age_mean,uncor_age_SD] = calc_age_uncorr(mineral,He,He_SD,U238,U235,U_SD,Th232,Th_SD,Sm147,Sm_SD)

% function to calculate the AHe/ZHe ages following the approach of Meesters
% and Dunai 2005: A noniterative solution of the (U-Th)/He age equation.
% G3, doi:10.1029/2004GC000834.

% input:
%	mineral: ap or zr
%	He: 4He connect of grain in mol
%   He_SD: SD of 4He in mol
%	Ft: grain dimension correction
%	238U, 235U, 232Th, 147Sm: parent isotope content in mol
%   U_SD, Th_SD, Sm_SD: relative SD of parent isotope content in %

% param
lambda238=1.55125E-10;
lambda235=9.84500E-10;
lambda232=4.94750E-11;
lambda147=6.53900E-12;

mineral=char(mineral);
mineral=mineral(1:2);

uncor_age=zeros(1,1000);
U238_rand=normrnd(U238,U238*U_SD/100,1,1000);
U235_rand=normrnd(U235,U235*U_SD/100,1,1000);
Th232_rand=normrnd(Th232,Th232*Th_SD/100,1,1000);
Sm147_rand=normrnd(Sm147,Sm147*Sm_SD/100,1,1000);
He_rand=normrnd(He,He_SD,1,1000);
switch mineral
	case {'ap', 'Ap'}
        production=8*lambda238*U238_rand+7*lambda235*U235_rand+6*lambda232*Th232_rand+1*lambda147*Sm147_rand;
        lambda_weight=(8*lambda238^2.*U238_rand+7*lambda235^2.*U235_rand+6*lambda232^2.*Th232_rand+1*lambda147^2.*Sm147_rand)./production;
        uncor_age=1./lambda_weight.*log(lambda_weight./production.*He_rand+1)./1E6;
        uncor_age_mean=mean(uncor_age);
        uncor_age_SD=std(uncor_age);
	case {'zr', 'Zr'}	
        production=8*lambda238*U238_rand+7*lambda235*U235_rand+6*lambda232*Th232_rand;
        lambda_weight=(8*lambda238^2.*U238_rand+7*lambda235^2.*U235_rand+6*lambda232^2.*Th232_rand)./production;
        uncor_age=1./lambda_weight.*log(lambda_weight./production.*He_rand+1)./1E6;
        uncor_age_mean=mean(uncor_age);
        uncor_age_SD=std(uncor_age);
    otherwise
        uncor_age_mean=0;
        uncor_age_SD=0;
end

end
        