Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29235 Discussions

Debugging NaN -- ISNAN() in debugger?

gacwest
Beginner
2,689 Views

How can I create a breakpoint that tests for NaN?

I am using Visual Studio 2005 and Intel Fortran 10to debug a legacy Fortran77 program in which elements in a large array (~100000 elements) inexplicably take on NaN values.

If I create a watchpoint conditionsuch as ISNAN(x) to test whether the variable x is NaN, the message in the watch window is "Undefinded variable isnan."

Thanks.

Glenn

0 Kudos
3 Replies
TimP
Honored Contributor III
2,689 Views
Does it accept the condition x /= x ?
0 Kudos
gacwest
Beginner
2,689 Views
Quoting - tim18
Does it accept the condition x /= x ?

Thank you for your quick response.

The debugger doesn't stop at abreakpoint testing for NaN with a condition x/=x nor isnan(x) Consider this code snippet --

logical isxnan1,isxnan2
x=sqrt(-1.)
isxnan1=isnan(x)
isxnan2=x/=x

As shown in the watch window, the returned values are

x = NaN
isxnan1 = .TRUE.
isxnan2 = .TRUE.

But if I enter x/=x directly into the watch window, the returned value is .FALSE.

Apparently the debugger --

1. Doesn't recognize the function ISNAN() and,
2. For x = NaN, evaluates x/=x exactly opposite (!?!) to the compiled code.

Setting a breakpoint that tests for '.not. x/=x' won't work since '.not. x/=x' is also true whenx is any number.

The only solution seems to be to modify the code to assign the result of isnan(x) to some new logical variable and to test for whether that variable is true.

logical isxnan
x=sqrt(-1.)
isxnan=isnan(x)
... ! set breakpoint to test whether isxnan = .true.

Not very elegant, but it works.

I'm open to other suggestions.

Thanks again.

Glenn

0 Kudos
bendel_boy1
Beginner
2,689 Views
Quoting - gacwest

How can I create a breakpoint that tests for NaN?

I am using Visual Studio 2005 and Intel Fortran 10to debug a legacy Fortran77 program in which elements in a large array (~100000 elements) inexplicably take on NaN values.

If I create a watchpoint conditionsuch as ISNAN(x) to test whether the variable x is NaN, the message in the watch window is "Undefinded variable isnan."

Thanks.

Glenn


I had code of the form

IF (IsNan(x)) THEN
x = 0.0 ! Place breakpoint here
END IF

and

IF (ANY(IsNan(x))) THEN
WHERE (IsNan(x)) ! Breakpoint here
x = 0.0
END WHERE
END IF

Replace assignment of 0.0 with whatever makes most sense for your program - PRINT *, for example.
0 Kudos
Reply