I am using Vensim DSS 6.3 (32-bit) and Matlab 2014a (32-bit).
I have included below an example of the Matlab code attempting to interface with the RABFOX.vpm model provided in the /dll subdirectory. I expected that the pointers for rvalPtr1 and tvalPtr1 would provide me with results, or reference to variables rpop and time, respectively; however, I am only left with an array of zeros as initially generated. My knowledge string/pointer handling in Matlab is low. I attempted to follow questions by others on the forum - in particular, Olivia's questions regarding similar type inquiry - but I could not get a good result.
I would appreciate some guidance and suggestions. Thanks, Raymond
code attached:
Code: Select all
%% MATLAB to VENSIM by-way-of DDL
clear all
%*********************LOAD THE MODEL *************************
if not(libisloaded('VenDLL32'))
addpath('C:\Users\Raymond\Documents\MATLAB\project_vensimdll');
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|C:\Users\Public\Vensim\dll\RABFOX.vpm'];
calllib('VenDLL32','vensim_check_status')
calllib('VenDLL32','vensim_command',str)
calllib('VenDLL32','vensim_start_simulation',0,0,1)
calllib('VenDLL32','vensim_finish_simulation')
%% *********************RETRIEVE DATA *************************
time = zeros(250);
rpop = zeros(250);
rvalPtr1 = libpointer('singlePtr', rpop);
tvalPtr1 = libpointer('singlePtr', time);
tpoints1 = calllib('VenDLL32','vensim_get_data','RABFOX.vdf','Rabbit Population','time',rvalPtr1(1),tvalPtr1(1),250);
rvalPtr1(1).Value
tvalPtr1(1).Value
%******************** UNLOAD VENSIM DLL ********************
%% Now unload the library
unloadlibrary VenDLL32
% end of command statements