Call vensim
-
- Super Administrator
- Posts: 4610
- Joined: Wed Mar 05, 2003 3:10 am
-
- Senior Member
- Posts: 77
- Joined: Thu Aug 19, 2010 3:34 pm
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
Did you solve the problem posted in the other thread?
Here is a subroutine I wrote to load a model:
-----------------------
function loadModel(modelName)
% Loads a Vensim model specified by the string ModelName
% The vendll32 library must have been loaded
str=['SPECIAL>LOADMODEL|',ModelName,'.vpm'];
lp=libpointer('voidPtr',[int8(str) 0]);
calllib('vendll32','vensim_command',lp);
-----------------------
There may be an easier way to load a model (or to execute commands in general), but that one at least works.
Here is a subroutine I wrote to load a model:
-----------------------
function loadModel(modelName)
% Loads a Vensim model specified by the string ModelName
% The vendll32 library must have been loaded
str=['SPECIAL>LOADMODEL|',ModelName,'.vpm'];
lp=libpointer('voidPtr',[int8(str) 0]);
calllib('vendll32','vensim_command',lp);
-----------------------
There may be an easier way to load a model (or to execute commands in general), but that one at least works.
-
- Senior Member
- Posts: 77
- Joined: Thu Aug 19, 2010 3:34 pm
Thanks for your help.no I didn't solve.
I work with these software only a few weeks. & I’m not familiar with them correctly.So I need more help & with more details.
My vensim model name is : S
As you say I run this :
clc
%function loadModel(S)
% Loads a Vensim model specified by the string ModelName
% The vendll32 library must have been loaded
str=['SPECIAL>LOADMODEL|','S','.vpm'];
lp=libpointer('voidPtr',[int8(str) 0]);
calllib('vendll32','vensim_command',lp);
…………………………………
It’s response is :
??? Error using ==> calllib
Library was not found
Error in ==> bb at 8
calllib('vendll32','vensim_command',lp);
…………………………………………………………….
And How dose it show me the result in matlab after run the vensim?
Again thank you very much
I work with these software only a few weeks. & I’m not familiar with them correctly.So I need more help & with more details.
My vensim model name is : S
As you say I run this :
clc
%function loadModel(S)
% Loads a Vensim model specified by the string ModelName
% The vendll32 library must have been loaded
str=['SPECIAL>LOADMODEL|','S','.vpm'];
lp=libpointer('voidPtr',[int8(str) 0]);
calllib('vendll32','vensim_command',lp);
…………………………………
It’s response is :
??? Error using ==> calllib
Library was not found
Error in ==> bb at 8
calllib('vendll32','vensim_command',lp);
…………………………………………………………….
And How dose it show me the result in matlab after run the vensim?
Again thank you very much
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
Well of course, if you haven't managed to load the library, you won't be able to load a model. You will have to fix that first.
Unfortunately, I don't understand the error message you posted in the other thread. Maybe one of the others does?
I have a question myself:
I want to set the value of a subscripted variable. How can I set it as a whole and not every component individually?
If e.g. I have the subscript
stime=t1,t2,t3
and the variable var[stime].
How can I set all three values at the same time? I tried for example
SIMULATE>SETVAL|var[stime]=1,2,3
but in that case only var[t1] would be set to 1 and the other components stay the same.
How can I fix this?
Unfortunately, I don't understand the error message you posted in the other thread. Maybe one of the others does?
I have a question myself:
I want to set the value of a subscripted variable. How can I set it as a whole and not every component individually?
If e.g. I have the subscript
stime=t1,t2,t3
and the variable var[stime].
How can I set all three values at the same time? I tried for example
SIMULATE>SETVAL|var[stime]=1,2,3
but in that case only var[t1] would be set to 1 and the other components stay the same.
How can I fix this?
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
Presumably you can retrieve the model output into matlab with vensim_get_data and plot it that way, though I don't know how the matlab syntax for passing arrays would work.
It's also possible to get the .dll to generate graphs with vensim_tool_command, but you have to be able to pass it a handle to a window (HWND) - again, I don't know what's possible in Matlab.
Tom
It's also possible to get the .dll to generate graphs with vensim_tool_command, but you have to be able to pass it a handle to a window (HWND) - again, I don't know what's possible in Matlab.
Tom
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
I have a new problem:
I tried to call vensim from matlab on another computer, namely my notebook with win7 as operating system. Loading the library does work, but I cannot load any model although I use the exact same commands as on the other computer (which has win xp).
Do you have any idea how to make this work under win7?
I tried to call vensim from matlab on another computer, namely my notebook with win7 as operating system. Loading the library does work, but I cannot load any model although I use the exact same commands as on the other computer (which has win xp).
Do you have any idea how to make this work under win7?
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
What location do you have the models you are trying to open? Win 7 is very picky about allowing any activity within restricted folders so moving them to another location might help.
You should also search your computer for vensimdll.err (probably in c:\Documents and Settings\username\AppData\Local\Vensim) and see what this file contains - normally it will list the errors encountered by the DLL.
You should also search your computer for vensimdll.err (probably in c:\Documents and Settings\username\AppData\Local\Vensim) and see what this file contains - normally it will list the errors encountered by the DLL.
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
I moved all files necessary to the MATLAB folder in Username\Documents, to be on the safe side. Doesn't work still.
The vensim.err file contains errors, which I don't really understand:
The model which I tried to load has been simulated several times from vensim before and the runs were saved under, say, run1.vdf, run2.vdf,...
To load the model in matlab I published it under modelname.vpm.
Now the vensim.err file contains error messages like:
Unable to open file C:\...path...\run1.vdf
What has loading the model in matlab to do with old runs of that model?
The vensim.err on the other computer (where loading works) does not contain these errors, so my problem seems to have something to do with that.
The vensim.err file contains errors, which I don't really understand:
The model which I tried to load has been simulated several times from vensim before and the runs were saved under, say, run1.vdf, run2.vdf,...
To load the model in matlab I published it under modelname.vpm.
Now the vensim.err file contains error messages like:
Unable to open file C:\...path...\run1.vdf
What has loading the model in matlab to do with old runs of that model?
The vensim.err on the other computer (where loading works) does not contain these errors, so my problem seems to have something to do with that.
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
I am having moe or less same problem like ''ahmadi2010''.'
I tried to open Vensim model from MATLAB by :
function loadModel(testlink)
hfile=['C:\Program Files\Vensim\Vensim\dll\Vendll.h'];
loadlibrary('VenDLL32',hfile);
str=('SPECIAL>loadModel|testlink.vpm')
calllib('VenDLL32','vensim_command',str);
In response I am getting vensim error (STOP VENSIM): Open the file C:\Program Files\Vensim\models\sample\testlink.vpm using the Vensim Model Reader
Can anybody tell me what's going on in my command? I am using version 10.a and working directory is C:\Program Files\Vensim\models\sample. I am Windows XP, user. If any of you succeded then please let me have the detailed command.
I tried to open Vensim model from MATLAB by :
function loadModel(testlink)
hfile=['C:\Program Files\Vensim\Vensim\dll\Vendll.h'];
loadlibrary('VenDLL32',hfile);
str=('SPECIAL>loadModel|testlink.vpm')
calllib('VenDLL32','vensim_command',str);
In response I am getting vensim error (STOP VENSIM): Open the file C:\Program Files\Vensim\models\sample\testlink.vpm using the Vensim Model Reader
Can anybody tell me what's going on in my command? I am using version 10.a and working directory is C:\Program Files\Vensim\models\sample. I am Windows XP, user. If any of you succeded then please let me have the detailed command.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
You need to tell Vensim where the model is located (that is include a full path in the LOADMODEL command) - and that should not be program files (this might work on WinXP but will not on Win 7).
However, the error message you are getting suggests that you have installed the Vensim Model Reader after installing Vensim DSS. You will need to reinstall Vensim DSS to correct this.
However, the error message you are getting suggests that you have installed the Vensim Model Reader after installing Vensim DSS. You will need to reinstall Vensim DSS to correct this.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
No, there is no dialog showing, LOADMODEL just returns 0 and that's it. I called venim_be_quiet(0) to be sure - that's the command to let dialogues etc. show, right? - , but that didn't change anything.arraywanted - if LOADMODEL returns 0 it should put up an error dialog - if you set BEQUIET take that setting away. Otherwise see if you can find vendll.err as that may hold a clue.
I already posted what the vendll.err file contains, see above.
I still have no clue here.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Member
- Posts: 36
- Joined: Fri Aug 20, 2010 11:03 am
Hi Bob
Thanks for your suggestion. However, I installed both Model reader and DSS respectively on C drive, under 'Vensimfolder'. After that I modefied the path but it is showing the same problem like before.
function loadModel(testlink)
hfile=['C:\Vensimfloder\dll\Vendll.h'];
loadlibrary('VenDLL32',hfile);
%loadlibrary('C:\Vensimfloder\dll\VenDLL32',hfile);
str=('SPECIAL>loadModel|C:\Vensimfloder\models\sample\'testlink.vpm')
%calllib('C:\Vensimfloder\dll\VenDLL32','vensim_command',str);
calllib('VenDLL32','vensim_command',str);
You suggested me to tell Vensim where the model is located (that is include a full path in the LOADMODEL command. I failed to follow your instruction, because of time limitation and etc. So, please have a look at the code and if possible make the necessary checking/modification
Thanks for your suggestion. However, I installed both Model reader and DSS respectively on C drive, under 'Vensimfolder'. After that I modefied the path but it is showing the same problem like before.
function loadModel(testlink)
hfile=['C:\Vensimfloder\dll\Vendll.h'];
loadlibrary('VenDLL32',hfile);
%loadlibrary('C:\Vensimfloder\dll\VenDLL32',hfile);
str=('SPECIAL>loadModel|C:\Vensimfloder\models\sample\'testlink.vpm')
%calllib('C:\Vensimfloder\dll\VenDLL32','vensim_command',str);
calllib('VenDLL32','vensim_command',str);
You suggested me to tell Vensim where the model is located (that is include a full path in the LOADMODEL command. I failed to follow your instruction, because of time limitation and etc. So, please have a look at the code and if possible make the necessary checking/modification