|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Fri Jul 01, 2011 4:45 am Post subject: Piece of FORTRAN code |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7926 Location: Salford, UK
|
Posted: Fri Jul 01, 2011 7:20 am Post subject: |
|
|
It is a REAL variable. Its type is governed by the Fortran standard relating to "implicit" typing. |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Jul 01, 2011 5:36 pm Post subject: Re: Piece of FORTRAN code |
|
|
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 |
|
|
|
|
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
|