function [overwritex,overwritey,errmsg] = bfitsaveresults(datahandle,savex,xname,savey,yname,overwriteok)
% BFITSAVERESULTS Save evaluated results of a fit to the workspace. 
%
%   [OVERWRITEX,OVERWRITEY,ERRMSG] = BFITSAVERESULTS(DATAHANDLE,SAVEX,...
%                                         XNAME,SAVEY,YNAME,OVERWRITEOK)
%   saves the x values evaluated of current fit of data DATAHANDLE to  
%   XNAME in the base workspace if SAVEX is 1, and saves the y = f(x) values
%   to a variable YNAME if SAVEY is 1.  If the variable exists,
%   then it won't overwrite unless OVERWRITEOK is 1.  If XNAME and YNAME
%   are the same, then the values are save to a 2-D array XNAME.

%   Copyright 1984-2000 The MathWorks, Inc.
%   $Revision: 1.8 $  $Date: 2000/05/22 01:47:30 $

evalresults = getappdata(datahandle,'_Basic_Fit_EvalResults');
xvalue = evalresults.x;
yvalue = evalresults.y;

combovalue(:,1) = xvalue(:);
combovalue(:,2) = yvalue(:);

xname = deblank(xname);
yname = deblank(yname);

err1.empty = sprintf('%s\n','   X:  an empty string is not a valid choice for a variable name.');    
err1.invalid = sprintf('%s %s %s\n','   X:  the string',xname,'is not a valid choice for a variable name.');    

err2.empty = sprintf('%s\n','f(X):  an empty string is not a valid choice for a variable name.');    
err2.invalid = sprintf('%s %s %s\n','f(X):  the string',yname,'is not a valid choice for a variable name.');    


[overwritex,overwritey,errmsg] = ...
    bfitsavetoworkspace('results',savex,xname,xvalue,err1,savey,yname,yvalue,err2,combovalue,overwriteok);

