function fgagui
% function fgagui
%
% fgagui - flow graph analysis gui
%
% GUI front-end for the flowgraph analysis tool
%
p = which('flow_tf.m');
if isempty(p)
error(['File flow_tf.m from flowgraph',...
' analysis tool not found. http://www.mathworks.com/',...
'matlabcentral/fileexchange/loadFile.do?objectId=',...
'7224&objectType=file']) %#ok<ERTAG>
end
hMainGui = figure(...
'NumberTitle','off',...
'Color','yellow',...
'Visible','off',...
'Units','pixels',...
'Name','Flow Graph Analysis Tool Gui',...
'Position',[50 50 800 500]);
movegui(hMainGui,'center')
set(hMainGui,'Visible','on')
hEdit = uicontrol(hMainGui,...
'Style','edit',...
'Units','normalized',...
'FontSize',10,...
'FontName','courier',...
'Min',0,'Max',500,...
'HorizontalAlignment','left',...
'BackGroundColor','white','ForegroundColor','black',...
'Position',0.01*[10 10 60 80],...
'Callback',@hEdit_Callback);
hFilenameText= uicontrol(hMainGui,...
'Style','text',...
'String','(save file first to make the Run-button appear)',...
'FontSize',10,'FontWeight','bold',...
'HorizontalAlignment','left',...
'Units','normalized','Position',0.01*[10 92 60 6]);
hTitleText = uicontrol(hMainGui,...
'Style','text','String',['Results will be imported into a workspace ',...
'variable named ''result'''],...
'FontSize',10,'FontWeight','bold',...
'Units','normalized','Position',0.01*[75 65 20 20],...
'Callback',@hLoadButton_Callback);
hLoadButton = uicontrol(hMainGui,...
'Style','pushbutton','String','Load',...
'Units','normalized','Position',0.01*[75 50 7 7],...
'Callback',@hLoadButton_Callback);
hClearButton = uicontrol(hMainGui,...
'Style','pushbutton','String','Clear',...
'Units','normalized','Position',0.01*[88 50 7 7],...
'Callback',@hClearButton_Callback);
hSaveButton = uicontrol(hMainGui,...
'Style','pushbutton','String','Save',...
'Units','normalized','Position',0.01*[75 35 7 7],...
'Callback',@hSaveButton_Callback);
hQuitButton = uicontrol(hMainGui,...
'Style','pushbutton','String','Quit',...
'Units','normalized','Position',0.01*[88 35 7 7],...
'Callback',@hQuitButton_Callback);
hRunButton = uicontrol(hMainGui,...
'Style','pushbutton','String','Run',...
'Units','normalized','Position',0.01*[75 18 20 10],...
'Enable','off','Visible','off',...
'Callback',@hRunButton_Callback);
hDemoButton = uicontrol(hMainGui,...
'Style','pushbutton','String','Demo',...
'Units','normalized','Position',0.01*[80 7 10 5],...
'Callback',@hDemoButton_Callback);
setappdata(hMainGui,'demomode',0)
set(hTitleText,'BackGroundColor','yellow','ForegroundColor','blue')
set(hFilenameText,'BackGroundColor','yellow','ForegroundColor','blue')
hButtons = [hLoadButton,hClearButton,hSaveButton,hQuitButton,hRunButton,...
hDemoButton];
set(hButtons,'BackGroundColor','blue','ForegroundColor','yellow',...
'FontWeight','bold')
function hEdit_Callback(source,eventdata)
set(hRunButton,'Enable','off')
set(hRunButton,'Visible','off')
set(hFilenameText,'String',...
'(save file first to make the Run-button appear)')
end
function hLoadButton_Callback(source,eventdata)
[filename,pathname] = uigetfile('*.flw', 'Pick an flw-file');
if not(filename==0)
set(hFilenameText,'String',['File: ',pathname,filename])
setappdata(hMainGui,'filename',filename)
setappdata(hMainGui,'pathname',pathname)
fid = fopen([pathname,filename],'r');
c = fread(fid).';
fclose(fid);
s = char(c);
i_eol = findstr(s,char([13 10]));
s(i_eol) = '';
s=fix_string(s);
set(hEdit,'String',eval(s))
set(hRunButton,'Enable','on')
set(hRunButton,'Visible','on')
setappdata(hMainGui,'demomode',0)
end
end
function hClearButton_Callback(source,eventdata)
set(hEdit,'String','')
setappdata(hMainGui,'filename','')
set(hFilenameText,'String','(save file first to make the Run-button appear)')
set(hRunButton,'Enable','off')
set(hRunButton,'Visible','off')
end
function hQuitButton_Callback(source,eventdata)
Parent=get(source,'Parent');
close(Parent)
end
function hSaveButton_Callback(source,eventdata)
filename = getappdata(hMainGui,'filename');
pathname = getappdata(hMainGui,'pathname');
s = get(hEdit,'String');
demomode = getappdata(hMainGui,'demomode');
rows=length(s);
diy = 0;
if isempty(filename)
[filename,pathname] = uiputfile({'*.flw'},'Save as');
setappdata(hMainGui,'filename',filename)
setappdata(hMainGui,'pathname',pathname)
if demomode == 0
[RC]=size(s);
rows = RC(1);
s=[s 10*ones(rows,1)];
ds=double(s).';
dss=ds(:);
s=char(dss.');
diy =1;
end
end
set(hFilenameText,'String',['File: ',pathname,filename])
if not(filename==0)
fid = fopen(filename,'w');
%put filename here if you dare
if diy == 0 || demomode == 1
for ind = 1:(rows)
line = s{ind};
fprintf(fid,'%s\n',line);
end
else
fprintf(fid,'%s',s);
end
fclose(fid);
set(hRunButton,'Enable','on')
set(hRunButton,'Visible','on')
end
end
function hRunButton_Callback(source,eventdata)
filename = getappdata(hMainGui,'filename');
out=flow_tf(filename);
assignin('base','result',out);
end
function hDemoButton_Callback(source,eventdata)
setappdata(hMainGui,'filename','')
s={'*plain integrator';...
'1 2 z^(-1)';...
'2 1 1';...
'.pre syms z';...
'.tf 1 2';...
'.post z=tf(''z'',1);'};
set(hEdit,'String',s)
setappdata(hMainGui,'demomode',1)
set(hRunButton,'Enable','off')
set(hRunButton,'Visible','off')
end
function s = fix_string(s)
i_q = findstr(s,'''');
for ind = length(i_q):-1:1
s = [s(1:(i_q(ind))),'''',s((i_q(ind)+1):end)];
end
s = ['{[''',s,''']}'];
i_eol = find(double(s)==10);
for ind = length(i_eol):-1:1
s = [s(1:(i_eol(ind)-1)),'''];[''',s((i_eol(ind)+1):end)];
end
s((double(s)==10))='';
end
end