Call vensim

Use this forum to post Vensim related questions.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Can you offer any assistance to ahmadi2010 in the following thread?

http://www.ventanasystems.co.uk/forum/v ... php?t=4193

[Edited on 25-8-2010 by Administrator]
ahmadi2010
Senior Member
Posts: 77
Joined: Thu Aug 19, 2010 3:34 pm

Post by ahmadi2010 »

vensim_command("SPECIAL>LOADMODEL|modelname.vpm")

could you please tell me from where, I can write above sentence?

for load my vensim model from matlab what can I do?

Could you please help me with more details? now I only write a model in vensim & can run it in vensim.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

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.
ahmadi2010
Senior Member
Posts: 77
Joined: Thu Aug 19, 2010 3:34 pm

Post by ahmadi2010 »

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
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

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?
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

Using the SETVAL you can only set one subscript element at a time. You can loop over the subscripts in the calling program.

An alternative would be to create a .cin file and then pass SIMULATE>ADDCIN to Vensim. This will actually allow you to set multiple constants at the same time.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Thank you, it works with a loop. I haven't tried the option with the cin-file, but I probably will because with loops it is quite ugly.

Next question right away:
Is there any way to display the graph of a variable after a simulation when calling the vensim dll? Or is it impossible from the outside?
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

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
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

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?
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

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.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

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.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

I also tried moving the files to another directory, but that didn't help.

I really have no clue what the problem is... anyone? :(
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

No ideas? I am still stuck here and would be really grateful!
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

Are you using version 5.10a of Vensim?
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

No, version 5.9e.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

If I try other functions like vensim_check_status or start_simulation, it works. But I just can't load a model.

Please, can anyone help me? I'm getting a bit desperate.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

I don't know if that was clear: I'm not getting a matlab error this time, vensim_command(SPECIAL>LOADMODEL...) just always returns 0.

By the way, the windows 7-computer has also a 64bit operating system. Connection with my problem possible?
khalediwm
Member
Posts: 42
Joined: Sun Mar 07, 2010 9:58 am

Post by khalediwm »

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.
khalediwm
Member
Posts: 42
Joined: Sun Mar 07, 2010 9:58 am

Post by khalediwm »

Sorry, I just forgot the attachment
Attachments
del2.doc
(88.5 KiB) Downloaded 222 times
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

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.
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

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.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

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.
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.

I already posted what the vendll.err file contains, see above.

I still have no clue here.
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

The only reason that it appears a model load will fail with no message is if it is not possible to change the working directory to the location of the model.

So again do not put the model in locations such as c:\program files(x86)\vensim...
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

The model is, and always was, located in Users\Username\Documents\MATLAB\Vensim.

Is there any attribute of the model I can check which could cause the failure? It is not write-protected.

[Edited on 9-3-2010 by arraywanted]
khalediwm
Member
Posts: 42
Joined: Sun Mar 07, 2010 9:58 am

Post by khalediwm »

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
Post Reply