V3.0 Jun. 18, 2015.
Rogelio Oliva <roliva@tamu.edu>
Mays Business School
This utility creates the binary adjacency matrix and a
column vector with all the variable names for a Vensim model (*.mdl format). The
output is an *.m file formatted to work with MATLAB, specifically, with the
Model Structural Analysis (MSA) functions with the Model
Structural Analysis (MSA) functions as described in Oliva (2004). The MSA functions
and documentation are available here.
Input file:
-
Vensim *.mdl format file
Output file:
-
MATLAB *.m file with a function, named as the original model, that returns the
adjacency matrix and the name list for model variables into a single structured
array with components .adj and .nms.
The following transformations are done to the model
variables:
-
variables introduced by Vensim (INITIAL TIME, etc.)
are eliminated.
- variable names are clipped to
60 characters.
- apostrophes are removed from
variable names
--
difficult string character to handle in MATLAB.
- macros are treated as functions
not as variables.
- arrays are eliminated
--
only the first equation for a variable is considered.
- links from stock-initialization
equations are removed
--
not accurate if the initialization eq. contains a
comma
The core functionality of the utility is in a Perl script named
mdl2bin.pl and can be downloaded here. The script is downloaded as a *.zip file, so you will have to uncompress it before runing it.
To run the script, Perl needs to be installed in your
computer. Perl is Open Source Software available for Unix, Linux, Windows and
Macintosh computers. Perl is pre-installed in most Unix, Linux and the
Macintosh OSX environments (see http://learn.perl.org/installing/
for directions on how to install Perl in your computer and http://learn.perl.org/first_steps/
for instructions on how to run a script).
If the Perl script and the *.mdl file are in the same
directory, and the command prompt is pointing to that directory, then the
following command from the Unix prompt (Terminal prompt in Mac OSX, Command
prompt in Windows) will pipe the *.mdl file to the Perl script:
% perl mdl2bin.pl my_model.mdl
Note that is it not necessary for the script and the *.mdl
file to be in the same directory as the two inputs to Perl can be specified
independently. For example:
% perl
/Users/Shared/bin/mdl2bin.pl /Users/roliva/xref/my_model.mdl
Where "~/mdl2bin.pl" and "~/my_model.mdl"
stand for the full path to the Perl script and the *.mdl file to be processed.
The output file will be placed in the same directory as
the input file and will have the same name as the input file but with the
standard MATLAB command termination (*.m).
Note that the output file is also a text file and can be reviewed and
edited with a word processor.
After placing the *.m file in a directory visible to
MATLAB, all you need to do to load the model information into MATLAB variable y
is type (at the MATLAB) prompt:
>> y=my_model;
v0.1 01/1997. Core functionality for rLab
v0.2 02/1997. Output format changed to match MATLAB
v0.3 02/1998. Changed to work with Perl 5.1
v0.4 02/1998. Implemented work around Vensim 3.0 bug on document tool
v0.5 02/1998. Implemented the creation of a vector w/variable names
v1.0 06/2003. Implemented to work with *.mdl format
Introduced the ability to processes models with arrays
Integrated MATLAB output to structured array (.adj and .nms)
Fully automated generation of MATLAB code
Changed to work in Perl 5.6
Developed OSX functionality and application
v1.1 11/2004. Fixed processing of variables with digits in name
Expanded name string to 60 characters
v2.0 02/2006. Implement functionality over the Internet
v3.0 06/2015. Reverted functionality to work as Perl script
Tested with Perl 5.16
© Rogelio Oliva, 1997, 1998, 2003, 2004, 2006, 2015.