- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a program. Sometime it works, sometime it does not. The code is:
ACOF = TAU * BETA/(2.0 * G * ATOP**2)
at sometime, the result is
ACOF =NaN.
But if when I break the line as 2 lines:
ACOF = 2.0 * G * ATOP**2
ACOF = TAU * BETA/ACOF
ACOF will always get a valid value.
I have hundreds test cases, when I change just this line, I get dozens of failures.
Any comments and suggestions on this mysterious problem for me?
Thanks
Victor Wang
ACOF = TAU * BETA/(2.0 * G * ATOP**2)
at sometime, the result is
ACOF =NaN.
But if when I break the line as 2 lines:
ACOF = 2.0 * G * ATOP**2
ACOF = TAU * BETA/ACOF
ACOF will always get a valid value.
I have hundreds test cases, when I change just this line, I get dozens of failures.
Any comments and suggestions on this mysterious problem for me?
Thanks
Victor Wang
Link Copied
11 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - ronghewang
I have a program. Sometime it works, sometime it does not. The code is:
ACOF = TAU * BETA/(2.0 * G * ATOP**2)
at sometime, the result is
ACOF =NaN.
But if when I break the line as 2 lines:
ACOF = 2.0 * G * ATOP**2
ACOF = TAU * BETA/ACOF
ACOF will always get a valid value.
I have hundreds test cases, when I change just this line, I get dozens of failures.
Any comments and suggestions on this mysterious problem for me?
Thanks
Victor Wang
ACOF = TAU * BETA/(2.0 * G * ATOP**2)
at sometime, the result is
ACOF =NaN.
But if when I break the line as 2 lines:
ACOF = 2.0 * G * ATOP**2
ACOF = TAU * BETA/ACOF
ACOF will always get a valid value.
I have hundreds test cases, when I change just this line, I get dozens of failures.
Any comments and suggestions on this mysterious problem for me?
Thanks
Victor Wang
Victor,
Can you please give input
I gave input as follows
parameter (tau=1.567d0,beta=2.0d0,g=34.987d0,atop=5.67d0)
i got ACOF=1.39314e-3
I think you migth have messed with type declaration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - ronghewang
Such as:
Tau =-1.000
Beta = 1.58000
G=32.2000
ATOP = 97.72558
then ACOF= -2.5689442E-06
If I used the single line, it will get: NaN.
Thanks,
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - peter
To make it clear, I copied the debug info as following:
TAU -1.000000 REAL(4)
BETA 1.580000 REAL(4)
G 32.20000 REAL(4)
ATOP 97.72558 REAL(4)
ACOF NaN REAL(4)
TAU * BETA/(2.0 * G * ATOP**2) -2.5689442E-06
Thanks,
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Victor,
Here is my code
program roghewang
real*4 ACOF,TAU,BETA, G , ATOP
parameter (Tau =-1.000,Beta = 1.58000,G=32.2000,ATOP = 97.72558)
ACOF = TAU * BETA/(2.0 * G * ATOP**2)
write(*,*) acof
end
Here is my code
program roghewang
real*4 ACOF,TAU,BETA, G , ATOP
parameter (Tau =-1.000,Beta = 1.58000,G=32.2000,ATOP = 97.72558)
ACOF = TAU * BETA/(2.0 * G * ATOP**2)
write(*,*) acof
end
I get -2.5689e-6 when i run the above code. Did you use format statement while writing output?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Peter
Hi peter,
I do not use the output. I just get the weird value.
Another finding: If I change the settings for "Fortran > Run-Time > Check Array and String Bounds" from "No" to "Yes", I can get the valid value. Why?
Thanks,
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - ronghewang
Quoting - Peter
Hi peter,
I do not use the output. I just get the weird value.
Another finding: If I change the settings for "Fortran > Run-Time > Check Array and String Bounds" from "No" to "Yes", I can get the valid value. Why?
Thanks,
Victor
Victor,
when you say'yes' to 'check array and string bounds',Fortran generates code to check for array subscripts.
It is all about checking if an array subscript is declared beyond the declared bounds of the array. Are you using subroutines, it might be with your dummy variables!
And do you get any error message when you get 'nan' for ACOf?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I really use subroutines, and I do not get any error/warning messages. In the subroutine, I have a loop which it works for the first few iterations, but it will break in the middle.
Thanks,
Victor
Thanks,
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Victor,
It might meanyour array is exceeding out of bounds. Fortran wont check array boundsfor arrays that are dummy arguments in which the last dimension bound is specified as * or when both upper and lower dimensions are 1.
For more information refer to compiler documentation and search for 'run time' and click on the second result ('check').
I tried to complile the previous code by calling a subroutine, but it doesnt show me any 'nan' values. Can you send me the subroutine that calls ACOF value??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Peter
Victor,
It might meanyour array is exceeding out of bounds. Fortran wont check array boundsfor arrays that are dummy arguments in which the last dimension bound is specified as * or when both upper and lower dimensions are 1.
For more information refer to compiler documentation and search for 'run time' and click on the second result ('check').
I tried to complile the previous code by calling a subroutine, but it doesnt show me any 'nan' values. Can you send me the subroutine that calls ACOF value??
I checked according your suggestion, and I can not find any problem for the array bounds and uninitialized variables. I got the random problem.
Such as the simple subroutine:
SUBROUTINE QUAD2 ( A,B,C,X,IRET )
IF ( B .EQ. 0. ) GOTO 99
E = -4.0 * A * C / B**2
IF ( E .LT. -1.0 ) GOTO 99
AE = ABS(E) - 0.1
IF ( AE .LE. 0. ) THEN
! X = -(C/B) *(1.0-E*(0.25-E*(0.125-E*0.078125)))
X = 0.125-E*0.078125
X = 0.25-E*X
X= -(C/B) *(1.0-E*X)
ELSE
X = SQRT(1.0 + E) - 1.0
X = (B / (2.0*A)) * X
ENDIF
IRET = 0 ! Root calculated
GOTO 200
99 WRITE (6,199) ! Error
199 FORMAT (' Entry error in subroutine "QUAD2" ')
write ( 6, '( a, 4e13.5 ) ') ! Error
* ' a, b, c and e are: ' , a, b, c, e
IRET = 1 ! Root not obtained.
200 RETURN
END
You will find that I broke "X = -(C/B) *(1.0-E*(0.25-E*(0.125-E*0.078125)))" as 3 lines. I think there is merrory problem for me.
Can anybody tell me how to find the problem?
Regards,
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Victor,
Ido not havedata for the variables in your subroutine. However I used my data and tried two cases.
Case 1. using X = -(C/B) *(1.0-E*(0.25-E*(0.125-E*0.078125)))
Case 2. Using your 3 part equations.Ido not havedata for the variables in your subroutine. However I used my data and tried two cases.
Case 1. using X = -(C/B) *(1.0-E*(0.25-E*(0.125-E*0.078125)))
For both the cases I get 0.39541 for 'X' . Following is the code slightly modified.
Note: 1. Implicit real*8 (a-z) is declared for my convenience. Its is not a good practice to use it very often
2. In Run-time it is Yes to 'check array subscrips and substrings'
[cpp]program main implicit real*8 (a-z) call quad2(u,v,w,y,z) write(*,10) y 10 format(2(/),f10.5,2(/)) end SUBROUTINE QUAD2 ( A,B,C,X,IRET ) implicit real*8 (a-z) a= 2.4 b=1.58 c=-1.d0 IF ( B .EQ. 0.) GOTO 99 E = -4.d0 * A * C / B**2 IF ( E .LT. -1.d0 ) GOTO 99 AE = ABS(E) - 0.1 IF ( AE .LE. 0.) THEN X = -(C/B) *(1.0-E*(0.25-E*(0.125-E*0.078125))) !X = 0.125-E*0.078125 !X = 0.25-E*X !X= -(C/B) *(1.d0-E*X) ELSE X = SQRT(1.d0 + E) - 1.d0 X = (B / (2.d0*A)) * X ENDIF IRET = 0 ! Root calculated GOTO 200 99 WRITE (6,199) ! Error 199 FORMAT (' Entry error in subroutine "QUAD2" ') write ( 6, '( a, 4e13.5 ,2(/)) ') ' a, b, c and e are: ' , a, b, c, e !! Error IRET = 1 ! Root not obtained. 200 RETURN END
[/cpp]
Try running this code and see if you get the same answer as mine. Otherwise we can check memory problems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - ronghewang
I have a program. Sometime it works, sometime it does not. The code is:
ACOF = TAU * BETA/(2.0 * G * ATOP**2)
at sometime, the result is
ACOF =NaN.
I have hundreds test cases, when I change just this line, I get dozens of failures.
Any comments and suggestions on this mysterious problem for me?
ACOF = TAU * BETA/(2.0 * G * ATOP**2)
at sometime, the result is
ACOF =NaN.
I have hundreds test cases, when I change just this line, I get dozens of failures.
Any comments and suggestions on this mysterious problem for me?
Victor, could you please zip and attach your source code, project files, and one test case where it fails? (Here are instructions for attaching -- it's a bit counterintuitive). It's almost impossible to tell what went wrong solely by looking at the code.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page