DLL vensim_get_vecvals

Use this forum to post Vensim related questions.
Post Reply
valen0205
Junior Member
Posts: 3
Joined: Tue Jul 30, 2024 10:53 pm
Vensim version: DSS

DLL vensim_get_vecvals

Post by valen0205 »

Hello,

I’m currently working on a Vensim model from Python using the DLL.

I’m trying to get the values of a vector, and while the code is running, it’s not returning the correct result (it’s returning -1.2980742e+33 when the value should be 10).

Any ideas on what might be happening?

Here is a sample of the code I’m using:
import numpy as np
from ctypes import c_float, POINTER

Variable = ['A', 'B', 'C', 'D', 'E', 'F']

def GetData(Variable):
vec = np.zeros(len(Variable), dtype=np.float32)
fp = (c_float * len(Variable))(*vec)

# Retrieving the values of the variable
var = ['Offer [' + t + ']' for t in Variable]
for t in range(len(Variable)):
vec[t] = vensim_dll.vensim_get_varoff(var[t].encode('utf-8'))

vensim_dll.vensim_get_vecvals(vec.ctypes.data_as(POINTER(c_float)), fp, len(Variable))
dOffer = np.ctypeslib.as_array(fp)

return dOffer

dOffer = GetData(Variable)
print(dOffer)
Thanks in advance
Administrator
Super Administrator
Posts: 4667
Joined: Wed Mar 05, 2003 3:10 am

Re: DLL vensim_get_vecvals

Post by Administrator »

Always check the return value when calling into the DLL, if it returns zero, something has not worked correctly. For example, you are not checking the result of the call
vensim_dll.vensim_get_vecvals(vec.ctypes.data_as(POINTER(c_float)), fp, len(Variable))
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