# XML: Using Macros

Possibly the clearest example of XML Macro usage was posted by Tom (taquillo) in the avsim.com Aircraft & Panel Design forum:

(A:VELOCITY WORLD X, m/s) (A:VELOCITY WORLD Z, m/s) atg2 rnor

(L:Cage switch,bool)
if{ 0 }
els{ @Macro1 l0 - abs 0.5 <
if{ @Macro1 l0 - }
els{ @Macro1 l0 <
if{ @Macro1 3.14159 + l0 - }
els{ l0 3.14159 + @Macro1 - /-/ }
}
}

Wherever you see "@Macro1" used, simply substitute whatever is contained in the Macro1 code!

Now it truly makes NO sense to bother with creating a @Macro unless you are planning to use the same calculation more than once or twice in any given gauge project!

Notice that in Tom's example he's used the @Macro1 five times!!! thus making the code much easier to write, read and understand...

Now, parsing the code above, the first thing Tom's done is store the value of (A:PLANE HEADING DEGREES TRUE, radians) in register s0 (s0 is a temporary memory location used only during this calculation.

This allows Tom to further simplify the if/else code because anytime he needs the value of (A:PLANE HEADING DEGREES TRUE, radians), all he needs to do is write l0 (lowercase L for "load" register 0). Note that Tom's used the l0 register five times in the if/else clause as well.

Had all of this been written out without the use of the register and the @Macro, the result would have been a very long and messy bit of code!!!!!

(L:Cage switch,bool)
if{ 0 }
els{ (A:VELOCITY WORLD X, m/s) (A:VELOCITY WORLD Z, m/s) atg2 rnor (A:PLANE HEADING DEGREES TRUE, radians) - abs 0.5 <
if{ (A:VELOCITY WORLD X, m/s) (A:VELOCITY WORLD Z, m/s) atg2 rnor (A:PLANE HEADING DEGREES TRUE, radians) - }
els{ (A:VELOCITY WORLD X, m/s) (A:VELOCITY WORLD Z, m/s) atg2 rnor (A:PLANE HEADING DEGREES TRUE, radians) <
if{ (A:VELOCITY WORLD X, m/s) (A:VELOCITY WORLD Z, m/s) atg2 rnor 3.14159 + (ALANE HEADING DEGREES TRUE, radians) - }
els{ (A:PLANE HEADING DEGREES TRUE, radians) 3.14159 + (A:VELOCITY WORLD X, m/s) (A:VELOCITY WORLD Z, m/s) atg2 rnor - /-/ }
}
}

Which do you suppose is the easier to write/read/understand and most importantly, maintain?

Panel & Gauge Design|XML