CFD Online Discussion Forums

CFD Online Discussion Forums (
-   CFX (
-   -   One question about macro (

oldarmy January 24, 2003 19:24

One question about macro
What's wrong in the following macro?

calc i = 1 while ( $i < 100 )




calc ms$i=masstotal



. echo $ms$i

If the value of "i" is 7, the result is "$ms7". What I want is to get an valute stored in variable "ms7". How can I fix this problem?

Jim February 14, 2003 09:36

Re: One question about macro
(I'm assuming your first line, "calc i=1 while ($i < 100)" is actually two lines. This message board did the same thing to me, sticking two lines together unless I left a blank line between them.)

You should be getting a value stored in parameter ms7 (and all of ms1 through ms99, presumably). The problem is in the "echo" command. You want TASCtool to substitute 7 for $i, then substitute the value of ms7 for $ms7. This requires sort of a nesting of dollar signs; it's got to substitute the $i and then use the first dollar sign after that's done. I haven't found any way to get TASCtool to do that either. Instead, it's just reading left to right, trying to evaluate $ms (which has no value set, so it just echoes "$ms"), then $i (which it correctly replaces with "7").

The workaround I use is to use "calc" to put the value into a simple parameter name just for output. After all, the correct value has been placed into ms7. Instead of "echo $ms$i", try:

calc ms_output=ms$i

echo $ms_output

This ought to work. Just let ms_output keep getting replaced by the current value of ms$i as the loop goes.


oldarmy February 17, 2003 21:21

Re: One question about macro
Thank you very very much, Jim!

All times are GMT -4. The time now is 02:18.