function [MineralStruct,outstruct] = PrepCompleteWeights2Cations(thelabels,controlstruct,which0,InStruct,MineralStructIn)
%[MineralCell,outstruct] = PrepCompleteWeights2Cations(thelabels,controlstruct,which0,InStruct,MineralStructIn)
%The purpose of this function is to prepare all of the background data neccessary to 
%convert from cations to weight components or weight to cation components 
%
%INPUT
%thelabels = The list of minerals to be considered 
%controlstruct = the output of createinputstruct and contains all options information about the run
%which0 = This value determines which oxygen value is used (hydrous vs. anhydrous)
%Instruct = The raw data (a structure array) from the background file. This function organizes that
%data.  Instruct is created in loadbackground.m
%MineralStructIn = The current state MineralStruct.  MineralStructIn is modified and then output as
%
%OUTPUT
%MineralStruct = a structure array that holds all background information for each mineral for
%conversion from cation to additive/exchange components 
%outstruct = contains a cell array that holds general information required for conversion from
%weights to cations and visa versa
%
%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 nargin == 2
		which0 = 1;
	end
	
	Minerals = InStruct.Minerals;
	NumberMinerals = length(Minerals);
	MineralStruct = CreateMineralCell(Minerals,NumberMinerals,thelabels,controlstruct,which0,MineralStructIn,InStruct);
    
	gflabels = InStruct.GfElement;
	gf = [InStruct.GramFormulaList';InStruct.CationsList';InStruct.ChargeList']; 
    
	ironcolumn = GetColumnsGeneral3(thelabels,{'Fe'}); %which column contain Fe 
    
	outstruct = struct('gf',{gf},'gflabels',{gflabels},...
		'ironcolumn',{ironcolumn},'Minerals',{Minerals},'NumberMinerals',{NumberMinerals});