function [cations,order,thelabelstemp,w2cstruct] = WeightsToCationsComplete(MineralStruct,...
thelabelstemp,theweights,outstruct,m,controlstruct,addC,whichiron)
%[cations,order,thelabelstemp,w2cstruct] = WeightsToCationsComplete(MineralStruct,...
%thelabelstemp,theweights,outstruct,m,controlstruct,addC,whichiron)
%The purpose of this function is to convert percent oxide weight data in cation data
%This function provides a wrapper around the functions that do the real work
%
%INPUT
% MineralStruct = a structure array created by CreateMineralCell.m that hold background
% information for the transformations
% thelabelstemp = a cell array that contains the names of the elements used during this run
% theweights = a double vector that contains the weight percent oxide data
% outstruct = a structure that contains the general (non-mineral specific) information
% required for transformation between cations and weights (created in CreateMineralCell.m)
% m = This is the index of the mineral that is being considered.  Specifically this is 
% an index in into the data in MineralList (scaler).
% controlstruct = a structure holding the basic information required to run APHID
% addC = The value of the additive components(double vector)
% whichiron = is Fe ferrous or ferric (scaler)
%
%OUTPUT
% cations = a double vector of the cations data
% order = a cell array of strings which lists the names of the cations in proper order
% thelabelstemp = a cell array of the names of the elements used in this APHID run
% w2cstruct = a structure of data required for the transformation from weights to cations
%
%
%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



if whichiron == 1
	changeiron = controlstruct.changeiron1;
end
if whichiron == 0
	changeiron = controlstruct.changeiron0;
end
gflabels = outstruct.gflabels;
gf = outstruct.gf; 
ironcolumn = outstruct.ironcolumn;
C = MineralStruct(m).C;
order = MineralStruct(m).order;
Oxygens = MineralStruct(m).O;
if ironcolumn{2,1} ~= -1
	thelabelstemp(ironcolumn{2,1}) = {['Fe' MineralStruct(m).irontemp]};
end
if MineralStruct(m).irontemp == '3' & changeiron & ironcolumn{2,1} ~= -1
	theweights(ironcolumn{2,1}) = theweights(ironcolumn{2,1})*1.1113;
end
w2cstruct =prepweights2cations(thelabelstemp,gflabels,gf);
w2cstruct.Oxygens = MineralStruct(m).O;
cations = weights2cations(w2cstruct,theweights); %converting weights to cations 
orderironcolumn = GetColumnsGeneral3(order,{'Fe'});
if orderironcolumn{2,1} ~= -1
	order(1,orderironcolumn{2,1}) = {['Fe' MineralStruct(m).irontemp]};
end
if ~isempty(C) & addC
	cations = [cations [C{2,:}]];
end