function out = weights2cations(instruct,composition)
%out = weights2cations(instruct,composition)
%This function converts weight percent oxide components to cation components
%
%INPUT
%instruct = a structure that contains the data required for the transformatin
%created by prepweights2cations
%composition = a double vector containing the composition as weight
%percent oxide 
%OUTPUT
%out = a double vector of cation components
%
%Written by K. Steffen (ksteffen@unm.edu) at the University of New Mexico,
%Department of Earch and Planetary Science
%Copyright 2003 Kurt Steffen
%
%Last Modified June 17, 2003

oxygen = instruct.Oxygens;  %number of oxygens
gramformula = instruct.gramformula; %gram formula weight
cations = instruct.cation; %number of cations per oxide
charges = instruct.charges; %chare per cation
molepropoxides = composition./gramformula;
molepropcations = cations.*molepropoxides;
equivposcharge = molepropcations.*charges;
factor = (oxygen*2)/sum(equivposcharge);
out = molepropcations*factor;