forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Looping & numerical problems - please advise

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
technophobe



Joined: 28 May 2007
Posts: 29

PostPosted: Mon Oct 15, 2007 2:07 pm    Post subject: Looping & numerical problems - please advise Reply with quote

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
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7926
Location: Salford, UK

PostPosted: Mon Oct 15, 2007 4:31 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
technophobe



Joined: 28 May 2007
Posts: 29

PostPosted: Tue Oct 16, 2007 1:56 am    Post subject: doh! Reply with quote

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
View user's profile Send private message Send e-mail
weaverwb



Joined: 04 Aug 2005
Posts: 37
Location: Monterey

PostPosted: Tue Oct 16, 2007 7:29 am    Post subject: Reply with quote

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
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Tue Oct 16, 2007 1:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
technophobe



Joined: 28 May 2007
Posts: 29

PostPosted: Tue Oct 16, 2007 6:52 pm    Post subject: doh! Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group