%% save_ext_call
%    callback function that is called whenever the save ext button
%    is pressed. This function will generate the code for the table
%    and output it to an external embedded matlab file which can
%    then be used in other functions. Filename of new file will be
%    the same as the expression name, currently this function will
%    overwrite an existing file of the same name.
% inputs:
%   object:GUI - current GUI object
%   src:double - source of the callback calling
%   event:eventdata - event that triggered the callback
% outputs:
%   none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = save_ext_call(object,src,event)
object.save_data;
% file name will be expression_name.m
fileid = fopen([get(object.function_name_control,'String') '.m'],'w');
%code = [];
%code = sprintf('function output = %s(%s)\n%s\noutput=0;\n',get(object.function_name_control,'String'),get(object.function_inputs_control,'String'),'%%#eml');
%code = [code object.generate_code(object.Grid1,object.Grid2,0)];
code = object.EMLGen.generate_eml_code;

fprintf(fileid,code);
% save an extra file called expression_name.data which
% contains a binary representation of the current gui object.
filename = [get(object.function_name_control,'String') '.table'];
%save(filename,'object');
object.save_data;

object.save_settings;
object.Data.save;
fclose(fileid);
end

