function aber=minvle(Amarg)
% function aber=minvle(Amarg)
% Sum of absolute errors in fitting activity coefficients stored
%   in XG array using the function named in gamf for a ternary system.
% Data in the XG array must be:
% 1     2     3     4     5     6
% x1    x2    x3   gam1  gam2  gam3
% The function name gamf, array XG and data used in the gamf function
%   Amar are global.  The argument Amarg holds the data to be stored in Amar.
% The function is intended for use in fmins to find the "best" parameters
%   for fitting the data.
global Amar gamf XG
[nd,ncol]=size(XG);
if ncol~=6
	disp('global XG is not the right size; should have 6 cols.')
	return
end
aber=0;
Amar=Amarg;
for k=1:nd
	gams=eval([gamf,'(XG(k,1:3))']);
	aber=aber+sum(abs(gams-XG(k,4:6)));
end
[aber,Amarg]
