Call vensim

Use this forum to post Vensim related questions.
mrj.hoseini
Junior Member
Posts: 4
Joined: Wed Aug 04, 2010 11:20 am

Call vensim

Post by mrj.hoseini »

I want to call Vensim from Matlab.For Example, For i=1:7 in matlab, I have to send i to vensim & run vensim & give the results in matlab & again for next i do again.

please help me.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

What version of Vensim do you have?
mrj.hoseini
Junior Member
Posts: 4
Joined: Wed Aug 04, 2010 11:20 am

Post by mrj.hoseini »

I work with Vensim Dss(Vensim 5.9b)
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

Just call the Vensim DLL - it looks like this should be pretty straightforward

http://www.mathworks.com/access/helpdes ... 43202.html

Then you can load and simulate a model, query the results and return the values for use in your Matlab routines.
mrj.hoseini
Junior Member
Posts: 4
Joined: Wed Aug 04, 2010 11:20 am

Post by mrj.hoseini »

Sincerely thank you very much
mrj.hoseini
Junior Member
Posts: 4
Joined: Wed Aug 04, 2010 11:20 am

Post by mrj.hoseini »

unfortunately I can't see the option "Vensim DLL" in vensim screen!& before I didn't work with vensim DLL . How can I find & open it? I'm a new user of vensim.

[Edited on 8-8-2010 by mrj.hoseini]
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

The Vensim DLL is a separate program - you don't access this from within Vensim. If you look at Chapters 11 and 12 of the Vensim DSS Reference Supplement you will find more info.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Then you can load and simulate a model, query the results and return the values for use in your Matlab routines.
That is exactly what I need to do.
Can anyone give me detailed instructions on how to do so?
I read through the link above, but didn't completely understand what I need to do explicitly.

Thank you very much for your help.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

If you're familiar with a programming language, take a look at the examples in your Vensim dll folder (e.g. C:\Program Files\Vensim\dll ).

Tom
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Thank you, but doesn't anyone have an example in Matlab?

The only programming language from the example folder I'm familiar with is Java, and translating that to Matlab would be quite ugly...

I'd really appreciate your help.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

I managed to load the vendll32 library into Matlab. I can't find a command to load a specific model, or to simulate one.

Can you help me?
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

The DLL use is described in Chapter3 11 and 12 of the DSS Reference Supplement. The commands to control Vensim (such as SPCIAL>LOADMODEL) are described in Chapter 5 of the Vensim DSS Reference Supplement.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Yes, I already found that out. However, there are still syntactical mistakes when I try to call a Vensim function from Matlab. Example:

After loading the library into Matlab, I want to load a model. For invoking an external function from Matlab one has to use the 'calllib' function:

calllib('libname', 'funcname', arg1, ..., argN)

Here I chose vendll32 as libname and vensim_command as funcname. But I can't find the correct syntax to pass the input argument to the function (which could be SPECIAL>LOADMODEL, e.g.). I thougt that the command would have to look like

calllib('vendll32','vensim_command',special>loadmodel|rabfox.vpm),

but Matlab returns an error ('undefined function or variable 'SPECIAL'). If I use quotes around the argument, I get an error as well.
Neither the Vensim manual nor the mathworks.com page give an answer on how to call the function syntactically correct.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

A few suggestions/notes.

1. Have you experimented with the full name of the DLL?

2. The SPECIAL>LOADMODEL should have quotes around it.

The header file, does that contain the correct things?

I think in this instance you need to refer to Matlab support. The Vensim DLL uses a standard calling convention that is tested and works with lots of applications.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

PS. What error do you get when you put quotes around the SPECIAL>LOADMODEL?
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Thanks for your help.
Have you experimented with the full name of the DLL?
I'm not sure what you mean by that. I know that the library has been loaded into Matlab; that part worked.
If you're asking whether I have tried to write 'vendll32.lib' instead of 'vendll32' - I have and it doesn't make a difference.
The SPECIAL>LOADMODEL should have quotes around it.
Also tried that. Still getting an error.

Concering the header file: Um, I have to admit that I was a bit insecure there, but first off the file vendll.h is the only header file in the dll folder. Second off: I thought that the file was okay since Matlab was able to display the loaded functions correctly.
There could be a mistake, though. Any ideas concering that?

Is there nobody who has called Vensim from Matlab himself? I'm quite sure that it isn't difficult at all, but one has to know the syntax.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

PS. What error do you get when you put quotes around the SPECIAL>LOADMODEL?
Error: The input character is not valid in MATLAB statements or expressions.

Should the name of the model have quotes around it, too?
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

I posted my question in a matlab forum as well. This is a part of an answer I got:

"Without knowing the signature for the vensim_command function in that library, I don't think anyone is going to be able to give you any specific advice."

Well, that's more or less the problem I have. What is the exact signature of vensim_command? The manual says, "Command is a null terminated string that indicates the command to execute".

Would that be syntactically correct:
vensim_command("SPECIAL>LOADMODEL|modelname.mdl") ?
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

Since Matlab can load and list the functions, I agree that the problem is not the header or dll name.

I think the next thing to try would be to see whether Vensim can call a function that takes only a numerical argument, like be_quiet. Matlab may require some particular argument to pass a string to Vensim.

Tom
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Functions with numerical arguments do indeed work! I think you're right, tomfid, and the problem is the string argument. I'll work on that now.
Thank you very much, at least now I know there are some things that work.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Oh, and again the question:

Would that be syntactically correct:
vensim_command("SPECIAL>LOADMODEL|modelname.mdl") ?
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Originally posted by arraywanted
Oh, and again the question:

Would that be syntactically correct:
vensim_command("SPECIAL>LOADMODEL|modelname.mdl") ?
Not quite. You need a published model when working with the Vensim DLL (publish the model from Vensim and then load that instead).
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

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

Would that be correct, then?
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Yes.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

I finally found out how to pass string arguments to vensim. You have to use the libpointer function in matlab.

All of you, thank you very much for your help. I may have more questions later, though... :)
Post Reply