samer@0: % ugather - Run a processing unit and collect output samer@0: % samer@0: % ugather :: samer@0: % unit({}, {[[N,1]]}, _) ~'live processing unit', samer@0: % T:natural ~'number of iterations to run (can be inf)', samer@0: % options { samer@0: % draw :: boolean/false ~'whether or not to call drawnow after each iteration'; samer@0: % quiet :: boolean/false ~'whether or not to suppress progress messages'; samer@0: % chunk :: natural/1 ~'print progress every chunk interations'; samer@0: % expand :: boolean/false~'do binary expansion of results array' samer@0: % } samer@0: % -> [[N,T]] ~'collected output'. samer@0: % samer@0: % This function accepts the live processing unit associated samer@0: % with an arrow (as created by with_arrow). The arrow must samer@0: % have zero inputs and one output. The requested number of outputs samer@0: % are collected into an array and returned. If inf outputs are samer@0: % requested, the system is run until an EOF exception is caught. samer@0: samer@0: function X=ugather(u,its,varargin) samer@0: opts=prefs('expand',1,varargin{:}); samer@0: if opts.expand && isinf(its) samer@0: X=zeros(u.sizes_out{1}(1),32); % initial size is arbitrarily 32 samer@0: done=uiter(u,its,@gatherxx,[],'label','ugather',opts); samer@0: if donesize(X,2), samer@0: %fprintf('ugather: expanding at %d.\n',size(X,2)); samer@0: X=[X,zeros(size(X))]; % double size samer@0: end samer@0: X(:,i)=u.process(); samer@0: end samer@0: end samer@0: samer@0: