macro variable and .mod inserted in .m

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

macro variable and .mod inserted in .m

Postby rudy » Wed Mar 11, 2015 6:11 pm

Dear all,

For some reasons, I included my .mod in a matlab file .m.
However in my .mod I use macro variables
(for instance I use @#define VARshock = 0 or 1 which I use with a if condition to define whether my shocks have AR or VAR structure).
But I would like to define the value of my macrovariable (o or 1) in the .m, i.e "decide" in the .m whether my shocks have a VAR structure or not, without having to open and modify the .mod file. How could I do that?

I hope my question is clear enough.

Thank you in advance,

best regards

Rudy
rudy
 
Posts: 10
Joined: Sat May 24, 2014 4:53 pm

Re: macro variable and .mod inserted in .m

Postby jpfeifer » Thu Mar 12, 2015 9:35 am

What you can do is write the definition statement
Code: Select all
 @#define VARshock = 0
into a txt file in your m-file using e.g.
Code: Select all
var_shock_indicator=1;
fid=fopen('par_def.txt','w+');
fprintf(fid,' @#define VARshock = %u \n',var_shock_indicator);
fclose(fid)

Then include this file in your mod-file using
Code: Select all
@#include "par_def.txt"
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: macro variable and .mod inserted in .m

Postby rudy » Thu Mar 12, 2015 10:59 am

Dear Prof Pfeifer,

Thank you very much for your answer, your solution works well and it helped a lot!

(Just in case someone also want to use it, I had to write @#include "par_def.txt" - ie don't forget to put the filename into quotation marks).

BR

Rudy
rudy
 
Posts: 10
Joined: Sat May 24, 2014 4:53 pm


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 7 guests