Wednesday, November 29, 2006

Debugging TK Procedure Functions

Here are some ways to debug TK procedures that may not be generating the results you expect.

1. Use TK's DEBUG function. Insert a line in your procedure with a call to DEBUG. DEBUG reports the values of the expressions you include as its arguments. For example,

call DEBUG(i,x,cos(x*y))

When TK processes this statement, it pauses and displays the values of variables i and x as well as the cos function expression. If a value is not available, TK displays ??? instead. When you click ok to continue, TK continues processing the model and may run into the same statement again. TK displays the current values each time.

2. Insert a "bad" statement to trigger an error at a specific location. This trick is useful for determining where TK goes or has been. In some procedures, you may have programmed the logic such that some statements simply get skipped. To test this, insert a statement such as y = SQRT(-1) which will always stop TK. Keep moving it around until it's clear where your logic is leading TK astray.

3. In combination with the previous trick, use the Examine Command after TK generates an error. This is useful for learning what the last values were of local variables in functions prior to stopping for the error.

These tips can also be useful on the Rule Sheet but are more appropriate for procedure functions which follow a logical sequence. TK makes repeated passes through the rule sheet to solve the rules. Each pass will trigger a call to a DEBUG function used there. The Tracer Log and Solution Tracer Report are better options for understanding TK's journey through the rules.

Drop me a line if you find this useful.

- Todd
(todd@uts.com)

amazing 

counters
Dell Computer Deals