"Nested IF" Bugs and Bug Fixes

The Problem

In some circumstances, Release 8.0 TABLO-generated programs or GEMSIM could produce incorrect results when there are nested IF statements (that is, one IF statement inside another IF statement) in an equation. [We give examples below.]

Fortunately, nested IFs do not occur in many models so this bug is unlikely to have affected results for many modellers.

This problem is a long-standing one which could have affected results produced with Release 6.0 or later of GEMPACK.

The GEMPACK developers apologise for the inconvenience and uncertainty this bug causes.

We are grateful to Kevin Hanslow for pointing out this bug.

Example.

Equation eq2 x1 = 6.3*IF{ IF[ Coef2 < 5, 1.4] = 23, C3}*x2 ;

In the above equation, the coefficient of variable x2 is
6.3*IF{ IF[ Coef2 < 5, 1.4] = 23, C3}

TABLO-generated programs replace an expression of the form

exp1*IF(cond,exp2)

where "cond" is a condition, "exp1" and "exp2" are expressions, by

IF(cond,exp1*exp2).

[This produces more efficient code since then it is only necessary to evaluate "exp1" when "cond" is true.]

In the case of the coefficient above which contains nested IFs, this should be rewritten as

IF{ IF[ Coef2 < 5, 1.4] = 23, 6.3*C3}

[where the 6.3 is moved inside the outer IF.]

However Release 8.0 TABLO-generated programs and GEMSIM incorrectly rewrote this as

IF{ IF[ Coef2 < 5, 6.3*1.4] = 23, C3}

[where the 6.3 was moved inside the wrong IF].

Bug Fix for Release 8.0 of Source-code GEMPACK

The following fix is recommended for those

(i) working on a Windows PC, and

(ii) Release 8.0 (October 2002) or Release 8.0-001 (October 2003) of Source-Code GEMPACK.

If you have Release 8.0-002 (December 2003) or later of GEMPACK, you do not need to download this fix since it is already included in your source-code.

If you have a unix version of GEMPACK, please contact the GEMPACK developers to obtain a fix.

This fix can also be applied to any Release 7.0 version of Source-code GEMPACK for Windows PCs.

To install this fix on a Windows PC, proceed as follows.

1. Download the file IFFIX80.ZIP (30K) and put it into the TABLO subdirectory of the directory in which your GEMPACK is installed (usually, C:\GP\TABLO).

2. Go to a DOS box and change into this TABLO subdirectory.

3. Issue the following commands.
del tbrw*.for
unzip32 -o iffix80.zip
zip gen2 tbrw*.for
cd ..
mktablo

This will make a new version of TABLO.EXE.

You need to rerun TABLO on all relevant models after you install the fix.

Go back to
Release 8 bug fixes page