Page 1 of 1

Function for reading from a vdf file

Posted: Thu Apr 02, 2020 2:11 pm
by kaveh.dianati
Dear Tom/Colleagues,

I was wondering whether there is a Vensim function for a variable to read values from inside a vdf file (e.g. a previous simulation).

The problem I need to solve is that in my model, I need to compare the values of a variable in various simulations against the values of the same variable in my baseline simulation. I am thinking whether I can define an additional variable which takes the values of my original variable in Baseline Simulation.vdf.

I hope my question is clear.

Many thanks.

Re: Function for reading from a vdf file

Posted: Thu Apr 02, 2020 2:16 pm
by Administrator
There is a GET_DATA_AT_TIME function, details on it are in the help system.

Does that do what you need?

Re: Function for reading from a vdf file

Posted: Thu Apr 02, 2020 2:19 pm
by tomfid
I think you want GET VDF DATA.

Re: Function for reading from a vdf file

Posted: Thu Apr 02, 2020 2:42 pm
by kaveh.dianati
Oh thanks. I didn't know about this function. It works beautifully!

Re: Function for reading from a vdf file

Posted: Thu Apr 02, 2020 4:09 pm
by tomfid
Great!

It's been a while since I've done this, but there's always a chicken-egg problem when the Base run that you're looking up comparison values from doesn't exist yet. I think I've solved this with some kind of IF THEN ELSE( base data = :NA:, 0, base data) logic, but I don't remember the details. Hopefully you've worked it out.

Re: Function for reading from a vdf file

Posted: Thu Apr 02, 2020 4:22 pm
by kaveh.dianati
I was just facing the exact same problem actually. Decided to delete that particular variable for my Base model, which leaves me with two model versions (not ideal). What you're suggesting is more elegant. I'm going to try and see if I can implement it now.

Thanks!!

Re: Function for reading from a vdf file

Posted: Thu Apr 02, 2020 4:41 pm
by tomfid
Another trick that I used ages ago, before GET VDF existed, was to create a separate model containing just a pair of variables that transform the base value into a data variable with a different name. Something like:

Main model:

price of cheese = {some simulated stuff}
data price of cheese {data variable, no equation}

Data model:

price of cheese {data variable, no equation}
data price of cheese := price of cheese

Then you do a run of the main model (base.vdf), and run the data model using base.vdf as input, to generate baseData.vdf. In subsequent runs of the main model, you load baseData.vdf which will populate the data variable.

The GET VDF solution is more elegant though.