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 

implied do loop

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



Joined: 20 Sep 2007
Posts: 2

PostPosted: Mon Sep 24, 2007 10:05 pm    Post subject: implied do loop Reply with quote

Hi, I think I was wrong using implied-do loops for several years!
I used CVF since I started programming in F90.
Consider the following example:0

vector1 = (/ ( dot_product( matrix(i,: ),vector2 ), i=1,N ) /)

This example compiled nicely in CVF (which I used for many years), but when I moved to FTN95 it didn't work.
Reading more carefully, I could only find implied do loops examples in read, write and declaration statements, but not in assignment statements like the one above. Was I wrong all this years and CVF didn't tell me?

Thanks

pezze
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Tue Sep 25, 2007 8:59 am    Post subject: Reply with quote

This appears to be valid Fortran 90 code.

FTN95 has a go at it but fails to compute matrxi(i, : ).
We will take a look at it.
Back to top
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Wed Sep 26, 2007 12:56 am    Post subject: Reply with quote

Why don't you simply write the following ?

do i=1,n
vector1(i) = dot_product ( matrix(i,: ), vector2 )
end do

Having worked through fortran 4 and early attempts at fortran 77 on pc's, I become uncomfortable looking at such complex single line statements, which ( I think ) can be restated without losing any clarity.

I don't think, because the standard allows it, being able to write "vector1 = (/ ( dot_product( matrix(i,: ),vector2 ), i=1,N ) /)" as a valid fortran statement is progress.

Just my personal opinion,

John
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Wed Sep 26, 2007 12:37 pm    Post subject: Reply with quote

I'm with John on this one!

I have always felt inferior by not fully taking on all the syntax improvements of Fortran 90/95. So I decided to see what all this was about and am now completely confused. Here is my test program.



Code:

      real*8 vector1(10),matrix(10,3),matrix2(3,10), vector2(3)
      n=10
      do i=1,3
        vector2(i) = i
      enddo
      do j=1,10
        do i=1,3
          matrix(j,i) = i+j**2
          matrix2(i,j) = matrix(j,i)
        enddo
      enddo
 1000 format(3f12.3)
      print 1000,vector2,((matrix(j,i),i=1,3),j=1,10)
! try the syntax both ways for both vector and matrix
! try changing do loop upper bound to 10 and it crashes on the line
! following the do loop - something is carried over! 
      do i=1,9
        print *,i,dot_product( vector2, matrix(i,:)  )
        print *,i,dot_product( matrix(i,:), vector2  )
        print *,i,dot_product( matrix2(:,i), vector2 )
        print *,i,dot_product( vector2, matrix2(:,i) )
       enddo
      print *,'===================='
      print *,( dot_product( vector2, matrix(i,:) ), i=1,1 )
      print *,'===================='
      vector1 = (/ ( dot_product( vector2, matrix(i,:) ), i=1,N ) /)
      print *,'vector1',vector1
      print *,'===================='
      print *,( dot_product( vector2, matrix(i,:) ), i=1,2 )
      print *,'===================='
      vector1 = (/ ( dot_product( vector2, matrix(i,:) ), i=1,N ) /)
      print *,'vector1',vector1
       print *,'===================='
      print *,( dot_product( vector2, matrix(i,:) ), i=1,3 )
      print *,'===================='
      vector1 = (/ ( dot_product( vector2, matrix(i,:) ), i=1,N ) /)
      print *,'vector1',vector1
      print *,'===================='
      print *,( dot_product( vector2, matrix(i,:) ), i=1,4 )
      print *,'===================='
      vector1 = (/ ( dot_product( vector2, matrix(i,:) ), i=1,N ) /)
      print *,'vector1',vector1
       end
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 -> 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