Model working directory

Use this forum to post Vensim related questions.
Post Reply
phuoc
Junior Member
Posts: 16
Joined: Sat Dec 25, 2010 10:59 pm

Model working directory

Post by phuoc »

Hello,

As I understand that the current working directory of the simulation is the same as the model directory. I try to load data in a parent directory in external C++ functions, forexample "..\data\file1.dat". My question is whether the reference to the parent directory of the current model, i.e. "..\", valid in external functions. It seems that I can do this in previous Vensim version but not the current version 6.0.

Thanks
etam

Re: Model working directory

Post by etam »

I'd suggest to use the absolute path of the current directory. As I remember you can add the relative to that as well (e.g. D:\MyProject\Model\..\data\file1.dat)
Check the vensim_get_info function in the DSS doc.

Code: Select all

char curr_dir[MAX_LEN];
(*VENGV->get_info)(4, curr_dir, MAX_LEN);
However, I don't know if the get_info has proper results in version 6.0. I have only a 5.11 license, in that it does.
tomfid
Administrator
Posts: 3816
Joined: Wed May 24, 2006 4:54 am

Re: Model working directory

Post by tomfid »

We haven't changed anything about external functions in 6.0 so whatever worked before should still work - if not, an example might help us diagnose the problem.
phuoc
Junior Member
Posts: 16
Joined: Sat Dec 25, 2010 10:59 pm

Re: Model working directory

Post by phuoc »

Hi etam and tomfid,

I am sorry for the late response. I can use the relative path in the external dll when I run the model directly in Vensim. However I cannot read or write to files when I run the same model under Vensim dll. Please find attached my example, adapting from Vensim's samples. The WORLDAPP.vmf model uses the external PSUM function in VENEXT.C. In the PSUM function I print out the current directory to a file. This works when I run it directly. Then I publish the model to WORLDAPP.vpm and run it through the Vensim dll sample 'C:\Documents and Settings\All Users\Vensim\dll\csharp\VensimDemo'. This time it doesn't print the current directory to a file but it does produce the output current.vdf. Does this means that Vensim dll ignore my code to print out to a file, both absolute and relative paths?

Thanks for your quick responds
Attachments
VENEXT.zip
(10.76 KiB) Downloaded 202 times
WORLDAPP.vmf
(53.7 KiB) Downloaded 194 times
Administrator
Super Administrator
Posts: 4613
Joined: Wed Mar 05, 2003 3:10 am

Re: Model working directory

Post by Administrator »

Have you loaded the external function library?

I'm writing on a phone, but you need to specify the external function lib in an ini file, and then call the loadini venapp command to load it.
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
phuoc
Junior Member
Posts: 16
Joined: Sat Dec 25, 2010 10:59 pm

Re: Model working directory

Post by phuoc »

That's my fault, I forgot to load the external dll. I fixed it and it works now.

Many thanks
Post Reply