Page 1 of 1

Include file stored as string variable

PostPosted: Mon Feb 23, 2015 12:55 pm
by ChrisZ
Hi,

when using Dynare 4.4.2, I usually split the model files in calibration, model equations, and others. Some of these files are not located in the same folder but in a subfolder or an other folder on the same directory level. I have already figured out that dynare can handle expressions as
Code: Select all
@#include "../model_specs/calibration.mod"
to get the file located somewhere else. However, I have a MATLAB path function running in background which returns the absolute path to the specific files. Is there any possibility to load the string variable returned from the path function e.g. xy directly with something like
Code: Select all
@#inlcude xy
?

Thanks in advance. Best,
Chris

Re: Include file stored as string variable

PostPosted: Tue Feb 24, 2015 11:05 am
by HoutanBastani
Not at the moment.

The macroprocessor does text expansion within the preprocessor and thus does not have direct access to the matlab workspace.

However, I say not at the moment, because it would be possible to add this functionality. In essence, you would pass the matlab variable of your choice at the dynare command line using the -D switch. At the current time, this does not work with the @#include macro command as it's expecting a quoted string. This could be changed, and I'll add it to our long to do list and it might just be done in the next version of dynare. It also might not. So, in the meanwhile, you'll have to hard code these strings.

Re: Include file stored as string variable

PostPosted: Tue Feb 24, 2015 1:56 pm
by HoutanBastani
So this has just been fixed in unstable, and will be available in tomorrrow's snapshot package.

To summarize, you need to do something of the order of the following in Matlab:
Code: Select all
>> xy='/path/to/dir/with/other/modfile/';
>> dynare modfile.mod -Dpath=xy


and then, in your modfile, you'll have:
Code: Select all
@#define othermodfile=path+'othermodfile.mod'
@#include othermodfile