function [overwritex,overwritey,errmsg] = bfitsavedatastats(datahandle,savex,xname,savey,yname,overwriteok)
% BFITSAVEDATASTATS Save evaluated results of a fit to the workspace. 
%
%   [OVERWRITEX,OVERWRITEY,ERRMSG] = BFITSAVEDATASTATS(DATAHANDLE,SAVEX,...
%                                         XNAME,SAVEY,YNAME,OVERWRITEOK)
%   saves the x stats of current data DATAHANDLE to a struct XNAME
%   in the base workspace if SAVEX is 1, and saves the ystats 
%   to a struct 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 struct named XNAME
%   with fields x and y.


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


xvalue = getappdata(datahandle,'_Data_Stats_X');
yvalue = getappdata(datahandle,'_Data_Stats_Y');

combovalue.x = xvalue;
combovalue.y = yvalue;

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

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

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

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



