View previous topic :: View next topic |
Author |
Message |
technophobe
Joined: 28 May 2007 Posts: 29
|
Posted: Mon Oct 15, 2007 2:07 pm Post subject: Looping & numerical problems - please advise |
|
|
Hello Guys,
I'm having a few unusual problems and wondered if someone could please advise. I'm running a code that performs a number of calculations. When the code begins certain values are initialised and, after a prescribed number of loops, the values are changed. A simplified version of my code would be
Code: | IMPLICIT NONE
INTEGER :: I, flow
REAL(dp) :: z1, z2 !I've used double precision here
flow=4
z1=0._dp
z2=0._dp
DO I=1,10
IF ( (flow==4) .and. ( I>20 ) ) THEN
z1=0.1_dp
z2=0.1_dp
ENDIF
perform_calculations
ENDDO |
The loop goes up to 10 here and so I would imagine that the IF statement would be bypassed entirely as although the first condition is true (flow==4) the second is never true. The problem I'm having, however, is that the output of the code changes depending on whether the IF statement is present or not. The results of the 'perform_calculations' section depend upon what I put inside the IF statement - even though it should not be accessed.
I know this sounds strange: If I use different values of z within the IF statement then the output of "perform_calculations" should not change - as the IF statement is never true. The output does change however and I'm really confused!
My solution, for this simple case, should be an array of zeros. The numbers are exactly zero - there is no numerical error here due to the nature of the eqns I'm solving. If I use one value of z then I get 0e00 as my output (which is correct for the case I'm dealing with). If I change the values of z in the IF block, however, then I get an array of numbers *e-18.
Could someone please help me understand why this is happening? I cannot understand why the contents of the IF statement should cause this change of output.
many thanks,
B |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7926 Location: Salford, UK
|
Posted: Mon Oct 15, 2007 4:31 pm Post subject: |
|
|
I cannot think of an explanation for this.
Have you tried using /CHECKMATE?
If CHECKMATE does not help then I would need further information (i.e. the code) for the calculations. |
|
Back to top |
|
|
technophobe
Joined: 28 May 2007 Posts: 29
|
Posted: Tue Oct 16, 2007 1:56 am Post subject: doh! |
|
|
Hi Paul,
I have tried using checkmate and this didn't show up any errors. I have no idea why it's playing silly-buggers with me. The numerical wiggles are very small and so I suppose that I could ignore them but I'd not be too happy with that as I'm concerned that their appearance is caused by some underlying error elsewhere in the code.
I'm restricted as to how much information I can include in the forum so I can't include much of my code. I've checked it throughout (by commenting out sections of it in turn) and the errors seem to appear in the simplified section of code I posted previously.
I'll have another bash at it tomorrow (it's 2am here and I need my beauty sleep). Hopefully I'll get it working then.
Cheers,
B |
|
Back to top |
|
|
weaverwb
Joined: 04 Aug 2005 Posts: 37 Location: Monterey
|
Posted: Tue Oct 16, 2007 7:29 am Post subject: |
|
|
a couple questions come to mind: are any of the variables you list being declared as parameters or in a data statement anywhere? Are these variables used in the calculations? Is this section of code passed through more than once? |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Tue Oct 16, 2007 1:04 pm Post subject: |
|
|
I really must swat up on Fotran95 syntax! But your code did not compile for me.
Instead, I tried the old fashioned way:
Code: |
IMPLICIT NONE
INTEGER :: I, flow
REAL*8 :: z1, z2 !I've used double precision here
flow=4
z1=0d0
z2=0d0
DO I=1,10
IF ( (flow==4) .and. ( I>20 ) ) THEN
z1=0.1d0
z2=0.1d0
ENDIF
print *, i,flow,z1,z2
! perform_calculations
ENDDO
end
|
How are z1 & z2 passed to the "perform_calculations" code - is it a in-line code, a subroutine passed through call, common or module? |
|
Back to top |
|
|
technophobe
Joined: 28 May 2007 Posts: 29
|
Posted: Tue Oct 16, 2007 6:52 pm Post subject: doh! |
|
|
Hi Guys,
I have no idea why - but the problem I was having yesterday seems to have solved itself. I haven't changed anything in my code but for some reason it's working properly now.... it is really weird!
I'm going to uninstall FTN95 and re-install it. I'm wondering whether a file has become corrupt or something. I'll let you know if the problem continues once I've re-installed everything.
Thanks very much for your help,
B |
|
Back to top |
|
|
|