Tuesday, December 22, 2009

MATLAB gem II

Recently I had to figure out which MATLAB toolboxes a massive program is using. The program itself is a smorgasbord of over 5000 (!!) function written by a small army of developers over a number of years. It is a form of spaghetti code based on OOP ideals. Seemingly, no start and no end.
Normally I would not care. I would approach the code as a basic developer and write my new code as needed. I know that applying patches is not a good practice (I really dislike the idea) but my time is a lot more valuable than trying to follow calls forever. However, in this case all that code needs to be installed on more machines. And the installation is temporary. Therefore it makes no sense to buy the full-MATLAB-with-all-toolboxes-plus-Simulink-and-everything-else kind of license we typically buy. Therefore, I had to figure out what exactly that particular program is using.
So I Googled the problem and found exactly what I was looking for in the file exchange of MATLAB Central. The function contributed by us; The contribution is titled fdep: a pedestrian function dependencies finder and it is exactly what I was looking for.
The function (set of functions really) is well written and documented. It very quickly goes through a MATLAB program and displays information about users defined functions, sub-functions, MATLAB functions, toolboxes, calls, etc. Toolboxes!! There is a command line interface and a graphical one. It even comes with an HTML help file. Great work!
One caveat: At least when it comes to the toolboxes the result could be inaccurate. The reason for that is that if a developer is using a parameter name that shadows the name of an existing MATLAB function the the conflict is resolved in favor of MATLAB. For example, if a developer programmed the statement
step = 1;

then fdep will determine that step is the MATLAB function from the Control System Toolbox. That is a problem with namespace littering. And with all the toolboxes available for MATLAB pretty soon all normal dictionary words will shadow some MATLAB function. Anyway…
For my case I used the function fdep in a script that navigated through the mess of code and interrogated each function and printed back the toolbox result. The function worked quickly with few hick-ups and returned reasonable results: A few toolboxes in addition to core MATLAB. It might be that a couple of them seem suspicious but the effort required to uncover details is out of scope!
Technorati Tags: ,,,,

No comments:

Post a Comment