vensim to matlab

Use this forum to post Vensim related questions.
Post Reply
samira15928
Junior Member
Posts: 16
Joined: Fri Jun 24, 2016 4:47 am
Vensim version: DSS

vensim to matlab

Post by samira15928 »

Hi All
I am using vensim 6.3D(32-bit) and matlab R2015b(64-bit), would like to call vensim from matlab with the command below:

if not(libisloaded('VenDLL32'))
hfile = ['C:\Users\Public\Vensim\dll\vendll.h'];
loadlibrary('VenDLL32',hfile);
end

and get an error:

Warning: Warnings messages were produced while parsing. Check the functions you intend to use for correctness.
Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary
Error loading library intermediate output follows.
The actual error is at the end of this output.
*********

Type 'HWND' was not found. Defaulting to type error.

Found on line 9 of input from line 112 of file C:\\Users\\Public\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 15 of input from line 118 of file C:\\Users\\Public\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 26 of input from line 129 of file C:\\Users\\Public\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 34 of input from line 137 of file C:\\Users\\Public\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 40 of input from line 143 of file C:\\Users\\Public\\Vensim\\dll\\vendll.h

Type 'HWND' was not found. Defaulting to type error.

Found on line 51 of input from line 154 of file C:\\Users\\Public\\Vensim\\dll\\vendll.h
*********
Error using loadlibrary
Building VenDLL32_thunk_pcwin64 failed. Compiler output is:
C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\bin\gcc -I"C:\Program Files\MATLAB\Research\R2015b\extern\include"
-fexceptions -fno-omit-frame-pointer -I"C:\Users\S.Mokhtar\Documents\MATLAB" -I"C:\Users\Public\Vensim\dll"
"VenDLL32_thunk_pcwin64.c" -o "VenDLL32_thunk_pcwin64.dll" -shared
In file included from VenDLL32_thunk_pcwin64.c:27:0:
C:\Users\Public\Vensim\dll/vendll.h:112:61: error: unknown type name 'HWND'
CFUNCTION int VEFCC vensim_tool_command(const char *command,HWND pwindow,int aswiptool) ; /* custom.c (not avail
for DLLMIN) */
^
C:\Users\Public\Vensim\dll/vendll.h:118:85: error: unknown type name 'HWND'
CFUNCTION int VEFCC vensim_show_sketch(int sketchnum,int wantscroll,int zoompercent,HWND pwindow) ; /* custom.c
(not avail dllmin) */
^
C:\Users\Public\Vensim\dll/vendll.h:129:46: error: unknown type name 'HWND'
CFUNCTION int VEFCC vensim_set_parent_window(HWND window,long r1,long r2) ;
^
C:\Users\Public\Vensim\dll/vendll.h:137:72: error: unknown type name 'HWND'
CFUNCTION int VEFCC VensimCToolCommand(int context,const char *command,HWND pwindow,int aswiptool) ; /* custom.c
(not avail for DLLMIN) */
^
C:\Users\Public\Vensim\dll/vendll.h:143:96: error: unknown type name 'HWND'
CFUNCTION int VEFCC VensimCShowSketch(int context,int sketchnum,int wantscroll,int zoompercent,HWND pwindow) ; /*
custom.c (int context,not avail dllmin) */
^
C:\Users\Public\Vensim\dll/vendll.h:154:56: error: unknown type name 'HWND'
CFUNCTION int VEFCC VensimCSetParentWindow(int context,HWND window,long r1,long r2) ;
^
VenDLL32_thunk_pcwin64.c: In function 'int32cstringHWNDint32Thunk':
VenDLL32_thunk_pcwin64.c:81:2: error: unknown type name 'HWND'
HWND p1;
^
VenDLL32_thunk_pcwin64.c:85:7: error: 'HWND' undeclared (first use in this function)
p1=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:85:7: note: each undeclared identifier is reported only once for each function it appears
in
VenDLL32_thunk_pcwin64.c:85:12: error: expected ')' before 'const'
p1=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:85:20: error: expected ';' before 'callstack'
p1=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:89:32: error: expected declaration specifiers or '...' before 'HWND'
return ((int32_T (*)(char * , HWND , int32_T ))fcn)(p0 , p1 , p2);
^
VenDLL32_thunk_pcwin64.c:89:49: error: expected ')' before 'fcn'
return ((int32_T (*)(char * , HWND , int32_T ))fcn)(p0 , p1 , p2);
^
VenDLL32_thunk_pcwin64.c: In function 'int32int32int32int32HWNDThunk':
VenDLL32_thunk_pcwin64.c:128:2: error: unknown type name 'HWND'
HWND p3;
^
VenDLL32_thunk_pcwin64.c:135:7: error: 'HWND' undeclared (first use in this function)
p3=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:135:12: error: expected ')' before 'const'
p3=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:135:20: error: expected ';' before 'callstack'
p3=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:137:53: error: expected declaration specifiers or '...' before 'HWND'
return ((int32_T (*)(int32_T , int32_T , int32_T , HWND ))fcn)(p0 , p1 , p2 , p3);
^
VenDLL32_thunk_pcwin64.c:137:60: error: expected ')' before 'fcn'
return ((int32_T (*)(int32_T , int32_T , int32_T , HWND ))fcn)(p0 , p1 , p2 , p3);
^
VenDLL32_thunk_pcwin64.c: In function 'int32HWNDlonglongThunk':
VenDLL32_thunk_pcwin64.c:200:2: error: unknown type name 'HWND'
HWND p0;
^
VenDLL32_thunk_pcwin64.c:203:7: error: 'HWND' undeclared (first use in this function)
p0=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:203:12: error: expected ')' before 'const'
p0=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:203:20: error: expected ';' before 'callstack'
p0=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:209:23: error: expected declaration specifiers or '...' before 'HWND'
return ((int32_T (*)(HWND , long , long ))fcn)(p0 , p1 , p2);
^
VenDLL32_thunk_pcwin64.c:209:44: error: expected ')' before 'fcn'
return ((int32_T (*)(HWND , long , long ))fcn)(p0 , p1 , p2);
^
VenDLL32_thunk_pcwin64.c: In function 'int32int32cstringHWNDint32Thunk':
VenDLL32_thunk_pcwin64.c:304:2: error: unknown type name 'HWND'
HWND p2;
^
VenDLL32_thunk_pcwin64.c:310:7: error: 'HWND' undeclared (first use in this function)
p2=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:310:12: error: expected ')' before 'const'
p2=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:310:20: error: expected ';' before 'callstack'
p2=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:314:42: error: expected declaration specifiers or '...' before 'HWND'
return ((int32_T (*)(int32_T , char * , HWND , int32_T ))fcn)(p0 , p1 , p2 , p3);
^
VenDLL32_thunk_pcwin64.c:314:59: error: expected ')' before 'fcn'
return ((int32_T (*)(int32_T , char * , HWND , int32_T ))fcn)(p0 , p1 , p2 , p3);
^
VenDLL32_thunk_pcwin64.c: In function 'int32int32int32int32int32HWNDThunk':
VenDLL32_thunk_pcwin64.c:369:2: error: unknown type name 'HWND'
HWND p4;
^
VenDLL32_thunk_pcwin64.c:378:7: error: 'HWND' undeclared (first use in this function)
p4=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:378:12: error: expected ')' before 'const'
p4=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:378:20: error: expected ';' before 'callstack'
p4=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:380:63: error: expected declaration specifiers or '...' before 'HWND'
return ((int32_T (*)(int32_T , int32_T , int32_T , int32_T , HWND ))fcn)(p0 , p1 , p2 , p3 , p4);
^
VenDLL32_thunk_pcwin64.c:380:70: error: expected ')' before 'fcn'
return ((int32_T (*)(int32_T , int32_T , int32_T , int32_T , HWND ))fcn)(p0 , p1 , p2 , p3 , p4);
^
VenDLL32_thunk_pcwin64.c: In function 'int32int32HWNDlonglongThunk':
VenDLL32_thunk_pcwin64.c:456:2: error: unknown type name 'HWND'
HWND p1;
^
VenDLL32_thunk_pcwin64.c:461:7: error: 'HWND' undeclared (first use in this function)
p1=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:461:12: error: expected ')' before 'const'
p1=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:461:20: error: expected ';' before 'callstack'
p1=*(HWND const *)callstack;
^
VenDLL32_thunk_pcwin64.c:467:33: error: expected declaration specifiers or '...' before 'HWND'
return ((int32_T (*)(int32_T , HWND , long , long ))fcn)(p0 , p1 , p2 , p3);
^
VenDLL32_thunk_pcwin64.c:467:54: error: expected ')' before 'fcn'
return ((int32_T (*)(int32_T , HWND , long , long ))fcn)(p0 , p1 , p2 , p3);[/b][/i][/i]



could anyone help me with this problem?
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: vensim to matlab

Post by Administrator »

Have you tried the Matlab demonstration code that comes with Vensim? Does that work for you?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: vensim to matlab

Post by Administrator »

The sample code is usually at
C:\Users\Public\Vensim\DLL\matlab
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: vensim to matlab

Post by tomfid »

Generally you can't call a 32 bit dll from a 64 bit application, unless there's some kind of bridge process. But the HWND error looks like the first issue.
samira15928
Junior Member
Posts: 16
Joined: Fri Jun 24, 2016 4:47 am
Vensim version: DSS

Re: vensim to matlab

Post by samira15928 »

Yes I have tried the code for matlab which comes with vensim, however the first step ( calling vensim dll) is not working.
do you have any idea to have bridge process or getting rid of HWnd error.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: vensim to matlab

Post by Administrator »

Have you tried running the 32 bit version of Matlab?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: vensim to matlab

Post by Administrator »

I replied to your email to us, unfortunately it looks like the email address you used is incorrect (it bounced back saying "The e-mail address you entered couldn't be found. Please check the recipient's e-mail address and try to resend the message. If the problem continues, please contact your helpdesk."
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: vensim to matlab

Post by Administrator »

Have you tried the 32 bit version of Matlab?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
samira15928
Junior Member
Posts: 16
Joined: Fri Jun 24, 2016 4:47 am
Vensim version: DSS

Re: vensim to matlab

Post by samira15928 »

Hi

What if I upgrade my Vensim to 64 bit? Do you think it would work and can I call the dll from Matlab 64 bit?
samira15928
Junior Member
Posts: 16
Joined: Fri Jun 24, 2016 4:47 am
Vensim version: DSS

Re: vensim to matlab

Post by samira15928 »

Sorry for the e mail address. it sounds my outlook had some issues. I resent the email, could you please reply that.
Thanks
Samira
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: vensim to matlab

Post by Administrator »

I'll ask again, have you tried the 32 bit version of Matlab?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
samira15928
Junior Member
Posts: 16
Joined: Fri Jun 24, 2016 4:47 am
Vensim version: DSS

Re: vensim to matlab

Post by samira15928 »

Hi
Yes and thanks for your help.
Matlabx32 installed and finally could load vendll32 there.Now I am figuring out how to call my Vensim file and special variables in the model.
samira15928
Junior Member
Posts: 16
Joined: Fri Jun 24, 2016 4:47 am
Vensim version: DSS

Re: vensim to matlab

Post by samira15928 »

Hi

When I use the given code for calling Vensim from Matlab, I don't get any error but the out put is just:
ans =

6


ans =

-6


ans =

-6


ans =

0
0
0
0
...

ans =

0
0
0
0


...

the code I use is:


%% MATLAB to VENSIM by-way-of DDL

% The code below documents a successful example using the Vensim DDL
% from Vensim DSS v6.3 32-bit in conjunction with calls from Matlab
% R2014a 32-bit.
%
% The SD model 'RABFOX.vpm' can be found in the Vensim DSS subdir DLL.
%
% I appreciate the helpful bread crumbs left in Olivia's posts a few
% years ago, and the help troubleshooting the vensim calls this is example
% by the forum administrator (Tony)!
%
% Raymond Smith, North Carolina State University, March 16, 2015

clear all
%*********************LOAD THE MODEL *************************

if not(libisloaded('VenDLL32'))
hfile = ['C:\Users\Public\Vensim\dll\vendll.h'];
loadlibrary('VenDLL32',hfile);
end

% Display Vensim DDL function calls and signatures
libfunctionsview VenDLL32

%% *********************EXECUTE SIMULATION *************************
% check calllib returns to verify initiation

str=['SPECIAL>LOADMODEL|RABFOX.vpm'];
calllib('VenDLL32','vensim_check_status')
calllib('VenDLL32','vensim_command',str)
str=['MENU>RUN|o'];
calllib('VenDLL32','vensim_command',str)


%% *********************RETRIEVE DATA *************************
% retrieve data from the post simulation execution

tnum = 201;
timepts = int32(tnum);

mytime = zeros(1,tnum);
mytimePtr1 = libpointer('singlePtr', mytime);

myrabpop = zeros(1,tnum);
myrabpopPtr1 = libpointer('singlePtr', myrabpop);

% vensim get data command
[int32_status, cstring_vdf, cstring_var1, cstring_var2, singlePtr_var1, ...
singlePtr_var2] = calllib('VenDLL32','vensim_get_data','CURRENT.vdf', ...
'Rabbit Population','time',myrabpopPtr1(1),mytimePtr1(1),timepts);

myrabpopPtr1(1).Value'
mytimePtr1(1).Value'

%% ******************** UNLOAD VENSIM DLL ********************
% unload the library

unloadlibrary VenDLL32

% end of command statements
>>



Could you please let me know how can I interpret the answer?
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: vensim to matlab

Post by Administrator »

None of us have Matlab, so there is little we can do to help unfortunately.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: vensim to matlab

Post by Administrator »

I know Hazhir Rahmandad is currently working with Matlab and Vensim if that helps.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Post Reply