samer@0
|
1 % with_arrow - Instatiate processing network and run a command against it
|
samer@0
|
2 %
|
samer@0
|
3 % with_arrow ::
|
samer@27
|
4 % arrow(T1@typelist(N),T2@typelist(M),S),
|
samer@0
|
5 % Cmd:(unit(T1,T2,S) -> action R) ~'function to apply to live unit',
|
samer@0
|
6 % {[N]->size} ~'sizes of inputs',
|
samer@0
|
7 % options {
|
samer@0
|
8 % pause :: boolean/false ~'pause after creation and before destruction of unit';
|
samer@0
|
9 % keyboard :: boolean/false ~'drop to debug command line instead of pausing';
|
samer@0
|
10 % gui :: boolean/false ~'create Java GUI for viewables'
|
samer@0
|
11 % }
|
samer@0
|
12 % -> action R ~'eventually returns any return values from Cmd.
|
samer@0
|
13 %
|
samer@0
|
14 % This command brings to life the processing network defined by the
|
samer@0
|
15 % supplied arrow. The function Cmd is called passing in a structure representing
|
samer@0
|
16 % the live system. After Cmd, the system is closed in a controlled fashion,
|
samer@0
|
17 % releasing any system resources that were claimed during construction.
|
samer@0
|
18 % This occures even if an exception is thrown. HOWEVER - if you press Ctrl-C,
|
samer@0
|
19 % this generates an uncatchable exception and so resources will not be
|
samer@0
|
20 % correctly released.
|
samer@0
|
21 %
|
samer@0
|
22 % If the gui option is supplied, a Java GUI is created for any viewable
|
samer@0
|
23 % objects created by the system (Java class samer.core.Viewable). This
|
samer@0
|
24 % requires that the Java AWT be available, ie usejava('awt')==1.
|
samer@0
|
25
|
samer@0
|
26
|
samer@0
|
27 function varargout=with_arrow(sys,cmd,sizes_in,varargin)
|
samer@37
|
28 opts=options('pause',0,'gui',0,'keyboard',0,varargin{:});
|
samer@0
|
29 ud.figs=[];
|
samer@0
|
30 ud.arrows={};
|
samer@0
|
31 set(0,'UserData',ud);
|
samer@0
|
32 u=construct(sys,sizes_in);
|
samer@0
|
33 if opts.gui,
|
samer@0
|
34 if usejava('awt'),
|
samer@0
|
35 if exist('expose_viewables','file')
|
samer@0
|
36 frame=expose_viewables(u.viewables,'system');
|
samer@0
|
37 else
|
samer@0
|
38 fprintf('WARNING: could not find expose_viewables function.\n');
|
samer@0
|
39 opts.gui=false;
|
samer@0
|
40 end
|
samer@0
|
41 else
|
samer@0
|
42 fprintf('WARNING: cannot create GUI Java AWT is unavailable.\n');
|
samer@0
|
43 opts.gui=false;
|
samer@0
|
44 end
|
samer@0
|
45 end
|
samer@0
|
46 if opts.keyboard
|
samer@0
|
47 whos
|
samer@0
|
48 fprintf('type "return" to when you have finished snooping around.\n');
|
samer@0
|
49 keyboard
|
samer@0
|
50 elseif opts.pause>0,
|
samer@0
|
51 msg_pause('press any key to start');
|
samer@0
|
52 fprintf('running...');
|
samer@0
|
53 end
|
samer@0
|
54 try, [varargout{1:nargout}]=cmd(u);
|
samer@0
|
55 catch ex
|
samer@0
|
56 fprintf('\nwith_arrow: CAUGHT EXCEPTION\n\n');
|
samer@0
|
57 % fprintf(getReport(ex));
|
samer@0
|
58 if opts.keyboard, keyboard
|
samer@0
|
59 elseif opts.pause>0, msg_pause('\npress any key to close'); end
|
samer@0
|
60 if opts.gui, frame.dispose; end
|
samer@0
|
61 u.dispose();
|
samer@0
|
62 rethrow(ex);
|
samer@0
|
63 end
|
samer@0
|
64 if opts.keyboard
|
samer@0
|
65 fprintf('type "return" to when you have finished snooping around.\n');
|
samer@0
|
66 keyboard
|
samer@0
|
67 elseif opts.pause>0,
|
samer@0
|
68 msg_pause('\npress any key to close');
|
samer@0
|
69 end
|
samer@0
|
70 if opts.gui, frame.close; end
|
samer@0
|
71 u.dispose();
|
samer@0
|
72 set(0,'UserData',[]);
|
samer@0
|
73 end
|
samer@0
|
74
|
samer@0
|
75 function msg_pause(msg)
|
samer@0
|
76 fprintf(msg); pause;
|
samer@0
|
77 fprintf('\n');
|
samer@0
|
78 end
|