Silverfrost Forums

Welcome to our forums

Piece of FORTRAN code

1 Jul 2011 3:45 #8488

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--

1 Jul 2011 6:20 #8490

It is a REAL variable. Its type is governed by the Fortran standard relating to 'implicit' typing.

1 Jul 2011 4:36 #8498

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.

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
Please login to reply.