Code covered by the BSD License  

Highlights from
fdep: a pedestrian function dependencies finder

4.94595

4.9 | 38 ratings Rate this file 123 Downloads (last 30 days) File Size: 266 KB File ID: #17291
image thumbnail

fdep: a pedestrian function dependencies finder

by

 

01 Nov 2007 (Updated )

FDEP dissects ML files and iteratively looks for all user defined functions used during runtime

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

FDEP dissects MATLAB files and iteratively looks for all user defined functions (modules), which are used during runtime

FDEP retrieves for each module its
- subfunctions
- nested functions
- anonymous functions
- eval class calls
- unresolved calls
    and all
- ML stock functions
- ML built-in functions
- ML classes
- ML toolboxes
    that it uses

runtime options and returned macros create user-friendly,
intuitively comprehensible, and interactive GUIs, which
- list the results in various panels and listboxes
- plot a full synopsis for each module with
exhaustive information
- plot a full dependency matrix
- plot a runtime and modules tree

in essence, FDEP is a wrapper for DEPFUN and MLINT; however, due to an efficient pruning engine it is considerably (20-100 times!) faster

FDEP is particularly useful if you want to distribute your functions and need so see what else to include as well as the toolboxes they use

FDEP may be useful to debug an erroneous function with correct syntax

see
> help fdep
and the accompanying published M-file for help and an exhaustive example

Acknowledgements

Farg: A Pedestrian M File Parser Showing All Used Functions' Syntax and Detab: A Pedestrian String Detabulator inspired this file.

This file inspired Ftoc (V1.2), Graph Viz Like Tools For Matlab, and Dep.

MATLAB release MATLAB 7 (R14)
Other requirements optimized for R2010+
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (61)
24 Nov 2014 Molly Rossow  
08 Oct 2014 Pierre

Why didn't I find this before? A wonderful time-saving utility.

24 Sep 2014 Brad Ridder

Good Lord this function is amazing! Bravo!

11 Mar 2014 Augustin  
23 Jan 2014 Rene Heideklang

Very useful tool!

However, in the latest version 20 Jun 2010, the maximum allowed m-file-name for class files (scripts and functions are ok) is 40 characters! For longer file names, fdep will produce an obscure error message:

In an assignment A(:) = B, the number of elements in A and B must be the same.

It took me some time to figure this out... Unfortunately I have no solution other than to use shorter class names at the moment. This does not seem to be related to depfun.

Any suggestions?

07 Jan 2014 p kung

much faster than depfun, like 20 times. thanks.

but it does not seem to return .fig files.
(also problematic file)

09 Dec 2013 Yulia  
07 Nov 2013 Ilan Bar

This is a great tool !
However, I need to also get the position in the file (line & column) of each function call. Is it possible ? If yes, could you advise me how to do it ?

02 Oct 2013 Thierry Dalon

Hi us,
fdep brings an error on schema.m file used in UDD Packages.
Thanks for the great contrib!

25 Jul 2013 Simone

Amazing! The fact that it also list the real toolboxes that are used is precious

21 May 2013 Scott Robertson

This is a phenomenal tool! I've been using depfun and this is a much better tool. Thank you...

14 May 2013 Nik

Fantastic tool! It helped me locate the function that required a unlicensed toolbox.

There is one thing I've noticed I want to share:
fdep() and the underlaying depfun() does not interprete "constant-conditional" branches, i.e. when you have

if 1
Foo();
else
Bla();
end

it lists both functions. In my case, this led to the case that MATLAB complained about a unlicensed Toolbox - which I did not use. Commenting out Bla() resolved the problem. :)

26 Mar 2013 Matt Wolinsky

Very useful tool, and fast!

It worked great for me, except for one issue: if the input function calls subfun.m only from within an anonymous function, then fdep() does not find it.

In other words if myfun.m has the lines

Sfunc=@(x)subfun(x);
x=rand;
y=Sfunc(x);

then for p=fdep('myfun'), p.fun does NOT contain subfun.m

This came up because I tend to use anonymous functions as aliases a lot, e.g. Fab=@(c,d)F(a,b,c,d)

08 Feb 2013 Paul

WOW! brilliant and fast. Highly recommend! Thank you

04 Feb 2013 Reza Farrahi Moghaddam  
10 Oct 2012 Justin Elstrott  
10 Oct 2012 Justin Elstrott  
27 Sep 2012 Jaroslaw Tuszynski

exactly what I needed

05 Jul 2012 Adam A  
24 Apr 2012 Alvaro Delgado  
16 Jan 2012 Nilimb

very helpful and fast.

22 Dec 2011 Eric

Great function. Saves lots of time and headache. Much faster than depfun which I had to force quit to stop after 20 minutes.

03 Oct 2011 Kelly Kearney

This is an excellent function that I've used for years. However, the GUIs don't play nicely with multiple monitors. Because of the mix of normalized and absolute units used for various parts of the GUI, simply resizing the whole thing post-render isn't ideal (and I just discovered by accident that there are some buttons in the upper corner that I never knew existed in all my time using it). It would be nice if I could somehow tell it which portion of the screen to use (even if I had to hardcode that in my own version, but right now that seems to require changing several lines throughout the code, and I haven't tracked them all down).

30 Sep 2011 Aurelien Queffurust

WoW ! which a great tool!

18 Aug 2011 Ben Petschel

Excellent tool, much faster and more informative than DEPFUN.

An especially useful feature is detection of unresolved function calls, which DEPFUN doesn't seem to do. The synopses of each module have a list of unresolved names, though I couldn't see a way to get a single list of all unresolved names except by browsing.

Also you might want to switch off latex interpretation in the point labels in the dependency matrix (line 1921, I think).

Good work!

26 May 2011 Jon Griffiths

Hi, I am having some problems using fdep on a script/function that calls functions which are part of a collection.

e.g. fdep('myfunction', '-m')
where
function [x] = myFunction(y)
x = mycollection.getX(y);
end

Is there a switch to capture this?

Thanks
Jon

15 Apr 2011 Kassi

This is awesome! My job requires using/debugging code written by someone else and this is extremely useful. Thank you for easy to navigate, clean, well written code :)

06 Apr 2011 Shahar

Amazing!

04 Apr 2011 AMVR

(Continuation of my previous error report). In case it helps, after tracing the error I reported earlier, I noticed the following:

The error occurs at:
ixb(1:par.mfun,1)=find(ixt(:,1)==1);
(??? Subscripted assignment dimension mismatch.)

and this is because

K>> par.mfun
ans =
32

K>> numel(find(ixt(:,1) == 1))
ans =
41

04 Apr 2011 AMVR

I'm getting the following error when running fdep on a function that uses IBM's CPLEX
26 7 : | cplexbilp P 1: C:\ILOG\CPLEX_Studio_AcademicResearch122\cplex\matlab\x64_win64\cplexcreateprob.p
27 8 : | cplexcreateprob R P 1: C:\ILOG\CPLEX_Studio_AcademicResearch122\cplex\matlab\x64_win64\cplexoptimset.p
28 9 : | cplexoptimset P 1: C:\ILOG\CPLEX_Studio_AcademicResearch122\cplex\matlab\x64_win64\@Cplex\Cplex.p
??? Subscripted assignment dimension mismatch.

Error in ==> fdep>FARG_get_entries at 3066
ixb(1:par.mfun,1)=find(ixt(:,1)==1);

Error in ==> fdep>farg at 2585
[p,par]=FARG_get_entries(p,par);

Error in ==> fdep>FDEP_get_fun at 770
[fa,fap]=farg(fnam,'-s','-d');

Error in ==> fdep>FDEP_get_dep at 664
[p,par,dtmp,dmlf,dmod,dmcl,docl]=FDEP_get_fun(p,par,fnam,frot);

Error in ==> fdep>FDEP_get_dep at 740
[p,par]=FDEP_get_dep(p,par,dtmp{i});

Any ideas why this happens?

28 Jan 2011 CLF

Very Useful. Would it be possible to handle also comments of, e.g.
%ToDo-things?

14 Jan 2011 Julian

Splendid! I am really impressed with this tool, especially, as others have commented, the speed up over depfun. Do you know if it will work with the new(ish) user classdefs?

29 Oct 2010 Ole

Ok, I have been damn stupid. Sorry. This piece of software is excellent!

29 Oct 2010 Ole

Thanks a lot, generally it works great! Unfortunately I have to analyze a gui-based software project and fdep seems only to consider automatically called functions. E.g. submodules which are called due to user input are not analyzed. Is that correct?

And if yes, what can I do about it? I really need to find out, which toolboxes are involved in a rather confusing project I recently "inherited".

22 Jun 2010 Andrew  
17 Jun 2010 us

andrew

unfortunately: no...
one of the reasons why the .EVAL. group is collected separately by fdep and a warning flag is displayed if any such construct is found...

which, in turn, is one of the reasons why one should follow these rules
- do NOT use EVAL
- use FEVAL with function handles, only
note:
feval(@sind,30)
will correctly find the call to SIND...

sorry
us

17 Jun 2010 Andrew

Is fdep capable of finding feval calls, where the function name argument in feval is itself a string variable?

e.g.

feval(fname,1,2,3)

27 May 2010 us

thomas
thanks for your comment

to achieve what you need, you could do this

pp=fdep('yourmain');
% now,
pp.sub.M
% is an array listing all the modules with their full path
% you could simply create a little utility, which does the copy, eg
function copymod(pp,newfolder)
% error checking etc left out...
for i=1:pp.nfun
copyfile(pp.sub(i).M,newfolder);
end
end

us

27 May 2010 Thomas Benson

This is fantastic. It worked quickly on a matlab program that contains 184 functions. An additional capability that would be useful would be to have an option in fdep to copy all the non-toolbox dependencies to the current working directory, although I think I could write this myself from the information provided in the P structure. Thanks us.

19 Mar 2010 Peder Schmedling  
11 Feb 2010 Oleg Komarov

I really find useful this tool.

26 Jan 2010 us

oleg
thanks for your comment

there are two reasons
1) a MODULE is a M-file/-script, and the first (main) function
is simply another (sub-) function within this file
2) the first function should(!) have the same
name as the M-file (otherwise, mlint complains); this is a simple
sanity check for the user

also, note the first char in the panel
M (...) ... % <- the main function
S (...) ... % <- the first (official) subfunction
S (...) ... % <- and so on

us

22 Jan 2010 Oleg Komarov

The package is great but I don't understand why the main function is listed in the subfunction pane (or in the 'sub.S.fn'):

function foo
end
function foo2
end

I'd expect only foo2 to be there. What is the rationale?
Tnx

05 Nov 2009 Jonas

Excellent function!

In Windows, the file separators in output.froot point the wrong way, though. Is that on purpose?

13 Aug 2009 us

hi dirk
great suggestion for an enhancement!...
i built a helper function, which does what you need and will email it to you if you want...
it will become part of FDEP as soon as i can get to it...
us

13 Aug 2009 Dirk

Thanks for this fantastic tool. The speed-up compared to depfun is amazing.

Though there is one feature I am missing somewhat:
fdep lets you identify which toolboxes are used from _somewhere_ in you code easiliy. But unfortunately it is not so easy to identify which of my .m files caused this toolbox dependency.
What would be great would be a possibilty to, e.g. select one of the toolboxes in the list-view which in turn could highlights all modules that directly depend on the selected tool box.

27 Jul 2009 us

jason

yes, this is by design...
while it could easily be changed, it also (potentially) would lead to undesirable results...
thus, to FDEP a file residing in a folder, which is not in ML's path, you must CD into that folder...
however, let me know if this is a real problem for you, as it certainly can be changed...

us

27 Jul 2009 Jason Kaeding

For being as full-featured as it appears, why will this function not accept full path names?

fdep('C:\blah\blah\blah\file.m')

I get an error saying "file not found". It only seems to work with files in current directory or in the MATLAB path.

17 Jun 2009 Andreas

I liked the previous version very much! Thanks a lot.

The latest version has a bug. If a sealed class (e.g. with a definition "classdef (Sealed) MyClass") is analyzed, the program crashes in fdep on line 2928. If "(Sealed)" is removed the program works as advertised.

08 Jun 2009 us

with the latest version (08-Jun-2009 22:24:13/R14-R2009a), per isakson's error messages do not show anymore...
the reason was an old parser engine, which did not handle more recent function constructs...
thanks, per, for alerting me to this problem...
us

07 Jun 2009 Alon

This is a great idea, implemented in a great way!
Full of user-fraindly and usefull features.

Great job.

28 Feb 2009 Jveer

very nice. thank you for sharing this very useful too

27 Feb 2009 Yuri K

Great function! Very useful. Is it possible to see also other files required in a package, like mat, txt, ini, etc?

10 Jan 2009 Image Analyst

I just downloaded it and it looks very nice. However I'd like you to fix the bug where it's locating the wrong module. I have a main module and it calls 8 other modules, 7 of which are in the same folder as the main module. However, module #2 you list as being one of the same name that I happen to have in another folder. I'm not sure why you're seeing that one first - MATLAB doesn't, it sees and runs the proper one which is in the same module as the main module. For example, in folder1, I have m-files myFile and mySubFile1, mySubFile2, etc. But in folder2, there is also a mySubFile1 and this is the one that your program is finding instead of the mySubFile1 in folder1.

A few more suggestions on the list GUI:
1. Replace the [John D'] button with a scroll bar or two small buttons to increase and decrease the font size.
2. I'd also like to see tooltips on your 6 buttons (right off the bat, it's not obvious what some of them do).
3. I'd like it to start with a GUI rather than a 2-steps command line process.
4. The Image Processing Toolbox is incorrectly called "images" in the toolboxes listbox.
5. A longer and more descriptive name than the short and cryptic "fdep" would be nice. And what does "pedestrian" have to do with it? Is that word needed?

Here's what MATLAB reports for my toolboxes:
MATLAB Version 7.7 (R2008b)
Image Processing Toolbox Version 6.2 (R2008b)
MATLAB Builder NE Version 3.0 (R2008b)
MATLAB Compiler Version 4.9 (R2008b)
Signal Processing Toolbox Version 6.10 (R2008b)
ToolBox EXAMPLE_SCRIPTS Version 1.0.0

Just my 2 cents on a well done program.

25 Jan 2008 exfnjbdr exfnjbdr

[URL=http://fxbpibjx.com]guupplld[/URL] <a href="http://hjnyyjjr.com">jmtcnixm</a> zshmaoig http://spqkqjpu.com jqpjujjw apsdptbx

13 Nov 2007 Urs (us) Schwarz

andrew, can you get in touch with me?unfortunately, you didn't provide an email address.

13 Nov 2007 Andrew Walton

It falls over when mex files are used.

07 Nov 2007 urs (us) schwarz

to accommodate FDEP to JD's eyesight, an upgrade was just uploaded with these changes

1) candy colors were moved towards zero (still hoping that they group the various panels quickly for the eye...)

2) a JOHN D' button was added; its help section says:
utility in honor of John D'errico, a senior and most respected
FEX and CSSM contributor, with very poor eyesight
CLICKING on the button will grow the fontsize by 1 point every time

the version tag is 07-Nov-2007 21:10:00
us

07 Nov 2007 John D'Errico

As always, a fully featured, fully able tool from us. Well done.

I do have one comment - my older eyes had a moderately hard time with the tiny font size and color scheme in the resulting gui. Pastel colored text on a pastel background was hard to read. Time for a new prescription in my glasses?

06 Nov 2007 Caroline Herbst

Extremely helpful, indeed! Also, the author did very quickly add a new feature after a pleasant email exchange.

03 Nov 2007 The empror of Matlab

wow!

Updates
02 Nov 2007

added an option to display full contents of a module; removed an annoying typo; version tag is 02-Nov-2007 15:34:23

02 Nov 2007

the wrong zip was submitted! sorry. version tag 02-Nov-2007 17:47:40

02 Nov 2007

upload did not seem to work?! last try... version tag 02-Nov-2007 19:36:43

05 Nov 2007

user requests: added more functionality to several macros; added a section on how FDEP might help to debug an erroneous function with correct syntax; version tag 05-Nov-2007 03:55:35

06 Nov 2007

again, the latest upload caused a mix-up of newer and older files on the FEX(?) - this has been a real problem as of lately; version tag 05-Nov-2007 17:32:49

08 Nov 2007

changes to accomodate john d'errico: 1) moved candy colors towards white, 2) added a JOHN D' button to increase the font size by one point for every click... version tag 07-Nov-2007 21:10:00

12 Nov 2007

user requests: FDEP now dissects standalone as well as M-file associated P-files; changes in the module's full synopsis display; many more examples in the HTML file; version tag 11-Nov-2007 01:01:25

14 Nov 2007

now handles MEX/DLL and MDL files as well; version tag 14-Nov-2007 13:16:06

08 Jun 2009

added a runtime/modules tree display, more information in the module synopsis, new macros, version tag 08-Jun-2009 22:24:13

18 Jun 2009

the parser now accepts meta method class descriptors, which takes care of Andreas's problem; version tag 18-Jun-2009 09:41:57

29 Jan 2010

clicking on a toolbox in the tbx panel now highlights in the modules list all modules, which use this tbx (user request); a new output field contains a comprehensive listing of tbxs and the modules they use the tbx; version tag 30-Jan-2010 03:30:06

26 May 2010

changes in the lint-engine (r2010+); version tag 26-May-2010 11:15:35

17 Jun 2010

now takes care of a very rare anomaly; version tag 17-Jun-2010 20:28:11

20 Jun 2010

all files now are read by very fast low-level i/o subroutines; version tag 21-Jun-2010 02:16:53

Contact us