function [inorder] = Additive2Cations(order,Additive,m,MineralStruct,thelabelstemp,NumberCols)
%[inorder] = Additive2Cations(order,Additive,m,MineralCell,thelabelstemp,NumberCols)
%The purpose of this code is to convert from Additive/exchange components to cation components
%INPUT 
%order = A cell array that contains the desired order for the output
%Additive = The additive components (already in an order to corraspond to the A matrix) double array
%m = The column of MinerCell that contains the data for the mineral to be considered double
%MineralStruct = A cell of data that contains all background information neccessary for transformation
%a cell with the rows corrasponding to minerals and the the columns to data 
%thelabelstemp = a cell array that contains the input order of additive
%NumberCols = The number of columns in the output Cations 
%
%OUTPUT
%inorder = The cations in output order (the order specified by order)
%
%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


    A = MineralStruct(m).A;
    C = MineralStruct(m).C;
    LSSolution = A*Additive;
    if ~isempty(C) & ~isempty(LSSolution) %this code removes the additive components 
        temp =length(C(2,:)); 
        LSSolution(end-temp+1:end) = [];
    end    
    thelabelstemp = GetColumnsGeneral3(order,thelabelstemp);
    inorder = zeros(1,NumberCols);
    [crap colthelabelstemp] = size(thelabelstemp);
    for n = 1:colthelabelstemp %takes the LS solution and puts in the proper order
        if thelabelstemp{2,n} ~= -1
            inorder(n) = LSSolution(thelabelstemp{2,n});
        end    
    end