Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Error

Status
Not open for further replies.

SoundUnbound

Programmer
Joined
Apr 13, 2006
Messages
3
Location
US
Hello. I am getting a very strange error. I am using a Visual Fortran 90 Ver 6.0 compiler and am getting a sqrt domain error, but I know that all the values being input to the square root are positive. I put a print statement before the declaration as a sanity check, and it printed a positive value and the program kept running as if there wasn't a problem. Then I removed the print statement, got the same error, then reinserted it, no error. I reinstalled the compiler, and still had the same problem. Any thoughts?

Adrian
 
As usually it's not a compiler error, it's this program error (99.999...%;). Present the code fragment at (and immediatly before) 'bad' sqrt call.
 
Sorry for taking such a long time to respond. Code fragment before and after:

print *, 'check'
dydx(1)=(d_hat/y(1))*(avg_r+y(1)**2*avg_r_4/(pi*d_hat*x))**0.5)
*(1 + 2*B_hat/(3*y(1)))**(-1)*(C_i/C_0 - avg_r_p/avg_r_4)
END SUBROUTINE

The variable of interest here is x. After further debugging, I found that a previous subroutine was passing an infinite value to x. But how can inserting a print statement prevent this from occuring? Btw, I am using an ODE solver from Numerical Recipes, if that sheds any light.

Regards
 
No idea why your error is happening but the expression could be optimized.
Code:
! instead of
(avg_r+y(1)**2*avg_r_4/(pi*d_hat*x))**0.5
! use
sqrt (avg_r+y(1)**2*avg_r_4/(pi*d_hat*x))

! instead of
(1 + 2*B_hat/(3*y(1)))**(-1)
! use
1.0/(1 + 2*B_hat/(3*y(1)))
The print statement may prevent a crash but is the result reliable? What happens if you
Code:
print *,'check ',x
 
Thanks for the tips xwb. Do you know why making those adjustments optimizes the code? I tried the print command you suggested, but it didn't seem to change anything. I am writing a lot of data to files, could that trigger this problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top