Hi Peter,
When you evaluate an _expression_ with grave-accents, the grave accents are evaluated as the command is parsed, filling in the value to make a new command, so that
let kbdix=`kbdi` becomes DEFINE VARIABLE kbdix=-9.696305
When the _expression_ in grave accents missing-value flag, it's replaced by the string BAD, so the result is
DEFINE VARIABLE kbdix=BAD
Then the Ferret parser sees that command and says, well BAD is not any defined variable name, and that's the error message you're getting.
At the end of REPEAT: L=7, you list dslr,lr,dkbdi_5,dkbdi,kbdi, with the results:because the variable kbdi evaluates to a bad-value, the "let kbdix=`kbdi`" command in the next iteration results in "let kbdix=bad". The loop can't continue.
I / *: 1.000 0.0000 0.0000 .... ....
You could do a "if `kbdi` then 1 else EXIT/LOOP" to gracefully exit out of the loop if you wish, or to reset kbdi to some desired value and continue.
Ansley
On 8/18/2014 5:35 AM, Peter Szabo wrote:
Dear Users,
I would like to find out what causes this error (during calculating Keetch-Byram index), also, how to fix this simple calculation.
The error message is BAD variable definition. Repetition until L=7 works fine, when an important variable becomes negative (-9), it defines during a calculation a BAD variable (the changing basic variable), and the next iteration stops.
When I removed the quotes(let kbdix=`kbdi`), naturally came stack overflow.
Here is what I used, and the bottom lines are the results of the script.
Thanks for you help and enjoy August wherever you are,
Peter Szabo
-------
yes? let kbdi=0
yes? repeat/l=2:365 (let kbdix=`kbdi`; let tempy=var15[d=2,l=`l-1`,k=1]-273.15; let lr=if var202[d=1,l=`l`,k=1] lt 0.05 then 0 else var202[d=1,l=`l`,k=1]; let dkbdi_5=if (dslr[l=`l`] eq 0) and (lr[l=`l`] ge 5) then (-1*lr[l=`l`]+5) else 0; let dkbdi=if (dslr[l=`l`] gt 0) then ((kbdix-800)*(-1)*(.968*Exp(.0486*(tempy*9/5+32))-8.3)*.001/(1+10.88*Exp(-.0441*annrf/25.4))*.254) else dkbdi_5; let kbdi=kbdix+dkbdi; list/nohead dslr,lr,dkbdi_5,dkbdi,kbdi)
---
!-> REPEAT: L=7
!-> DEFINE VARIABLE kbdix=0
!-> DEFINE VARIABLE tempy=var15[d=2,l=6,k=1]-273.15
!-> DEFINE VARIABLE lr=if var202[d=1,l=7,k=1] lt 0.05 then 0 else var202[d=1,l=7,k=1]
!-> DEFINE VARIABLE dkbdi_5=if (dslr[l=7] eq 0) and (lr[l=7] ge 5) then (-1*lr[l=7]+5) else 0
!-> DEFINE VARIABLE dkbdi=if (dslr[l=7] gt 0) then ((kbdix-800)*(-1)*(.968*Exp(.0486*(tempy*9/5+32))-8.3)*.001/(1+10.88*Exp(-.0441*annrf/25.4))*.254) else dkbdi_5
I / *: 0.0000 14.70 -9.696 -9.696 -9.696
!-> REPEAT: L=8
!-> DEFINE VARIABLE kbdix=-9.696305
!-> DEFINE VARIABLE tempy=var15[d=2,l=7,k=1]-273.15
!-> DEFINE VARIABLE lr=if var202[d=1,l=8,k=1] lt 0.05 then 0 else var202[d=1,l=8,k=1]
!-> DEFINE VARIABLE dkbdi_5=if (dslr[l=8] eq 0) and (lr[l=8] ge 5) then (-1*lr[l=8]+5) else 0
!-> DEFINE VARIABLE dkbdi=if (dslr[l=8] gt 0) then ((kbdix-800)*(-1)*(.968*Exp(.0486*(tempy*9/5+32))-8.3)*.001/(1+10.88*Exp(-.0441*annrf/25.4))*.254) else dkbdi_5
I / *: 1.000 0.0000 0.0000 .... ....
!-> REPEAT: L=9
!-> DEFINE VARIABLE kbdix=bad
!-> DEFINE VARIABLE tempy=var15[d=2,l=8,k=1]-273.15
!-> DEFINE VARIABLE lr=if var202[d=1,l=9,k=1] lt 0.05 then 0 else var202[d=1,l=9,k=1]
!-> DEFINE VARIABLE dkbdi_5=if (dslr[l=9] eq 0) and (lr[l=9] ge 5) then (-1*lr[l=9]+5) else 0
!-> DEFINE VARIABLE dkbdi=if (dslr[l=9] gt 0) then ((kbdix-800)*(-1)*(.968*Exp(.0486*(tempy*9/5+32))-8.3)*.001/(1+10.88*Exp(-.0441*annrf/25.4))*.254) else dkbdi_5
**ERROR: variable unknown or not in data set: BAD
list/nohead dslr,lr,dkbdi_5,dkbdi,kbdi
Command file, command group, or REPEAT execution aborted