Page 1 of 1

Macro-processor conditionals with loops

PostPosted: Sat Dec 31, 2011 9:46 pm
by wiczerd
I'm trying to simulate a multi-sector model with search frictions and running into problems with the macro preprocessor when I try to create an integer value for a conditional test using loop indices. Code like this:


Code: Select all
@#for l in 0:JJ
   @#for j in 1:JJ
      @#if (@{l} == @{j} || @{l}==0)
         Equation
      @#else
         Equation
      @#endif   
   @#endfor
@#endfor


Gives me the error
ERROR in macro-processor: occbc.mod:66.9: Macro lexer error: '@'


Should this operation be kosher, or does it make sense that I'd have trouble?
In the attached code, the problem first occurs on line 66, though I use a similar test elsewhere and get the same error.

Thanks very much,
David

Re: Macro-processor conditionals with loops

PostPosted: Mon Jan 02, 2012 11:09 am
by HoutanBastani
Once

Code: Select all
@#


is encountered, the macroprocessor interprets/expands everything else on that line. So, since l and j are macro variables, you do not need to dereference them with the

Code: Select all
@{}


; you would only do this when you are NOT on a line that's already being interpreted by the macroprocessor. Thus, the correction to the above buggy line is:

Code: Select all
@#if (l==j || l==0)


For more details, see the macroprocessor.pdf file in the doc directory of your Dynare distribution.