1 / 2

% p = adep('FUN','-opt') % p = adep(p,'-opt') % a wrapper for ML's <depfun>

% p = adep('FUN','-opt') % p = adep(p,'-opt') % a wrapper for ML's <depfun> % - returns struct <p>, which can be reused for display % - useful to determine which user defined modules must % be included in a distribution % % opt parameters comment

ananda
Download Presentation

% p = adep('FUN','-opt') % p = adep(p,'-opt') % a wrapper for ML's <depfun>

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. % p = adep('FUN','-opt') % p = adep(p,'-opt') % a wrapper for ML's <depfun> % - returns struct <p>, which can be reused for display % - useful to determine which user defined modules must % be included in a distribution % % opt parameters comment %-------------------------------------------------------------------------------- % -m : - do NOT plot linkage matrix % % p. field contents %---------------------------------------------------------------------------- % .fl list of files used by <FUN> and its subordinates % .bi list of builtins ... % .cn list of classes ... % .pf list of problemfiles unable to find, access, parse % .ps list of problemsymbols unable to resolve % .es list of <eval>/<feval> NOT USED BY R14+! % .cf called from fl(cf{i}) % returns all fun in <FUN> that % invoke the fun{i} % .jc list of java classes % see: help DEPFUN % % .user list of user defined functions % .tree tree of user defined functions [char(p.tree) shows contents] % .mat tree linkage matrix % % --: begin of a new function % a: + = module calls <eval/feval> [def: ' '] % b: r = module calls itself (recursively) [def: ' '] % c: - = module calls no other user defined function [def: ' '] % cid: caller id % mid: module id % nr: nr of times module is used % % example % p = adep('mavi'); % a user defined function % % xx caller .module abc cid mid nr module %---------------------------------------------------------------------------- % -- mavi .setoptn > + 1 2 3 f:\usr\matlab\mri\mavi.m % mavi .getoptn > + 1 11 2 % -- setoptn .setoptn > +r 2 2 3 f:\usr\matlab\unix\setoptn.m % setoptn .getoptn > + 2 11 2 % setoptn .gettok > + - 2 20 2 % setoptn .noblank > - 2 22 3 % <SNIP> % % note % <mavi.setoptn> = mid:2 is linked to <setoptn.> = cid:2 % clicking on a function name will open the file in the ML editor % created: % us 25-Dec-2001 % modified: % us 21-Mar-2006 20:26:47 / TMW % much of the programming is devoted to beautify the output! % % output format % '...|pmax|.|pmax|>.+rn.%5d.%5d.%5d...<|module|' function p=adep(varargin) if ~nargin help adep; return; end if nargout p=[]; end fun=varargin{1}; mlr=lower(matlabroot); nver=14; ver=sscanf(version('-release'),'%d'); if ver >= nver opt='-all'; else opt='-nographics'; end if ischar(fun) if ~exist(fun) disp(sprintf('ADEP> missing/not a function <%s>',fun)); return; end p.ADEPVER='21-Mar-2006 20:26:47'; p.root=mlr; com=sprintf('lower(which(''%s''))',fun); p.fun=eval(com); p.par=[]; [ p.fl,... p.bi,... p.cn,... p.pf,... p.ps,... p.es,... p.cf,... p.jc] = depfun(fun,opt); elseif isstruct(fun) & isfield(fun,'ADEPVER'); p=fun; else disp(sprintf('ADEP> invalid input (class:%s)',class(fun))); return; end p=get_opt(p,varargin{:}); disp(sprintf('\nADEP> %s\n',p.fun)); p.fl=lower(p.fl); p.esm={}; if ~isempty(p.es) if ver >= nver p.esm=p.es; else [p.esm{1:size(p.es,1)}]=deal(p.es.fcn_name); end end p.nm=0; p.ix=[]; p.user=[]; p.module=[]; ix=xor(strncmp(mlr,p.fl,length(mlr)),1); fx=ix; p.ix=find(ix); p.ux=[]; p.tx=[]; if ~isempty(p.ix) p.user=p.fl(ix); p.module=cell(size(p.fl(ix),1),1); p.mod1={}; p.mod2={}; p.call={}; p.tree=[]; fmax=size(p.fl,1); p.par.pmax=-inf; for i=1:size(p.user) [pw,f]=fileparts(p.user{i}); p.module(i)={f}; p.par.pmax=max(p.par.pmax,length(f)); end p.par.fmt=sprintf('%%-%d.%ds.%%-%d.%ds',p.par.pmax,p.par.pmax,p.par.pmax,p.par.pmax); for i=1:fmax if ix(i) f=p.fl{i}; st=sprintf('%s %s',repmat('-',2*p.par.pmax+5,1),f); disp(st); p=get_subfun(p,f,i); end end end if ~isempty(p.ux) p=get_tree(p); else disp(sprintf('\nADEP> no user defined calls')); end return; %-------------------------------------------------------------------------------- function p=get_opt(p,varargin); p.par.mflg=0; if ~isempty(find(strcmp(varargin,'-m'))) p.par.mflg=1; end return; %-------------------------------------------------------------------------------- function p=get_subfun(p,f,i) fnam=f; rc=' '; % recursive call ec=' '; % has <eval/feval> eflg=0; if ~isempty(find(strcmp(f,p.esm))) ec='+'; eflg=1; end nc=[]; cf=p.cf{i}; cf=cf(cf>0); for l=1:length(cf) if find(p.ix==cf(l)) if isempty(find(ismember(cf(l),nc))); ff=p.fl{cf(l)}; fnam=ff; [pw,f]=fileparts(f); [pw,ff]=fileparts(ff); nc=[nc;cf(l)]; tx=[cf(l) i length(cf)]; rc=' '; cflg=0; if i == cf(l) rc='r'; cflg=1; end st=sprintf([' ' p.par.fmt '> %s%s %5d %5d %5d <%s '],... ff,f,ec,rc,tx,fnam); p.ux=[p.ux;cf(l)]; p.tx=[p.tx;[tx eflg cflg -1]]; p.call=[p.call;{st}]; p.mod1(end+1)={ff}; p.mod2(end+1)={f}; disp(st); end end end return %-------------------------------------------------------------------------------- function p=get_tree(p) [a,b]=sort(p.ux); p.tx=p.tx(b,:); p.mod1=p.mod1(b)'; p.mod2=p.mod2(b)'; p.tree=p.call(b); [n1,dum,m1]=unique(p.mod1); n2=unique(p.mod2); nc=zeros(size(n1)); p.mat=zeros(length(n2),length(n1)); ix=[1;diff(p.tx(:,1))]; k=0; cid=0; mid=0; for i=1:size(p.tree,1) jx=find(p.tree{i}=='<'); if isempty(find(p.tx(:,1)==p.tx(i,2))) p.tree{i}(2*p.par.pmax+9)='-'; end if ix(i) > 0 k=k+1; p.tree{i}(1:2)='-'; p.tree{i}(jx)=' '; p.tx(i,end)=k; cid=find(strcmp(p.mod1{i},n1)); cid=cid(1); nc(k)=m1(i); else p.tree{i}(jx:end)=''; end mid=find(strcmp(p.mod2{i},n2)); mid=mid(1); if p.tx(i,1) == p.tx(i,2) p.mat(mid,cid)=p.mat(mid,cid)-1; else p.mat(mid,cid)=p.mat(mid,cid)+1; end end disp(sprintf('\nADEP> %s\n',p.fun)); disp(char(p.tree)); p=plot_mat(p,n1,n2,nc); return; %-------------------------------------------------------------------------------- function p=plot_mat(p,n1,n2,nc) if p.par.mflg return; end xoff=-.1; mrks=5; p.nc=nc; p.n1=n1; p.n2=n2; p.n1=p.n1(p.nc); p.mat=p.mat(:,p.nc); cs=sum(abs(p.mat),1); ms=sum(abs(p.mat),2); clf; ah=axes; set(ah,'xlim',[0 length(p.n1)+1]); set(ah,'xtick',[1:length(p.n1)]); set(ah,'xticklabel',cs); set(ah,'ydir','reverse'); set(ah,'ylim',[0 length(p.n2)+1]); set(ah,'ytick',[1:length(p.n2)]); set(ah,'yaxislocation','right'); set(ah,'yticklabel',ms); set(ah,'color','none'); box on; axis square; fs=get(ah,'fontsize'); fn=get(ah,'fontname'); xt=sprintf('%-1d caller(s) [+: link',size(p.mat,2)); xt=[xt ' \o: recursive']; xt=[xt ' \diamondsuit: caller=module]']; yt=sprintf('%-1d module(s)',size(p.mat,1)); yt=[yt ' [+: a caller >: not a caller]']; xlabel(xt,'fontsize',fs+2); ylabel(yt,'fontsize',fs+2); for i=1:length(p.n1) com=sprintf('edit(''%s'')',p.n1{i}); th=text(i,xoff,p.n1{i},'rotation',90); set(th,'fontsize',fs,'fontname',fn); set(th,'interpreter','none'); set(th,'buttondownfcn',com); if i == 1 set(th,'color',[1 0 0]); end set(th,'tag','c'); for j=1:length(p.n2) ix=strcmp(p.n1{i},p.n2{j}); if p.mat(j,i) > 0 mrk='+'; mrkc=[0 0 1]; elseif p.mat(j,i) < 0 mrk='o'; mrkc='none'; elseif ix mrk='diamond'; mrkc=[0 0 1]; else mrk=''; end if mrk lh=line(i,j,... 'marker',mrk,... 'markersize',mrks,... 'markerfacecolor',mrkc,... 'linestyle','none',... 'color',[0 0 1],... 'tag','d'); end end end for i=1:length(p.n2); mod=p.n2{i}; ix=find(strcmp(mod,p.n1)); if ~isempty(ix) mod=sprintf('%s +',mod); else mod=sprintf('%s >',mod); end com=sprintf('edit(''%s'')',p.n2{i}); th=text(xoff,i,mod); set(th,'horizontalalignment','right'); set(th,'fontsize',fs,'fontname',fn); set(th,'interpreter','none'); set(th,'buttondownfcn',com); set(th,'tag','m'); end set(gcf,'color',[.75 1 1]); set(gcf,'toolbar','none') set(gcf,'menubar','none') set(gcf,'numberTitle','off') set(gcf,'name',['DEPENDENCY MATRIX: '... strrep(p.fun,'\','/')]); shg; return; %--------------------------------------------------------------------------------

More Related