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 

Piece of FORTRAN code

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



Joined: 08 Apr 2011
Posts: 155

PostPosted: Fri Jul 01, 2011 4:45 am    Post subject: Piece of FORTRAN code Reply with quote

Hi,

I am relatively new to Fortran and havce a piece of code from smeone which I am not abe to fully follow;

dimension x(3,*),y(3,*)
character*70 check

undef = -1.0d30
icount = 0
do i = 1 , nav
if(scr(3,i) .ne. undef) then
icount = icount + 1
x(1,icount) = y(1,i)
x(2,icount) = y(2,i)
x(3,icount) = y(3,i)
endif

if(x(3,i).eq.undef)then

call something()
endif

enddo

Please can anyone help?

What is undef here? Is it a FORTRAN keyword?

Please help--
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Jul 01, 2011 7:20 am    Post subject: Reply with quote

It is a REAL variable. Its type is governed by the Fortran standard relating to "implicit" typing.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Jul 01, 2011 5:36 pm    Post subject: Re: Piece of FORTRAN code Reply with quote

I can't follow it either, but for different reasons. As Paul says undef is just a real variable in this code. However, you should not be assigning it the
value of a double precision constant (-1.0d-30). Moreover, x(3,i) which you use in the test is not defined, e.g. if the first test gives .false. it is not defined with i = 1.

Your code basically copies the elements of y where scr(1:3,:) is not equal to undef to x(1:3,:).

Here is my version of the copy part.

Code:

icount = 0
copy: do i=1, nav
   if (scr(3,i) .ne. 1.0e-30) then
      ! Copy co-ordinates to first free column of x
      icount = icount + 1
      x(1:3, icount) = y(1:3, i)
   end if
end do copy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General 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