forums.silverfrost.com
Welcome to the Silverfrost forums

Author Message
Kenneth_Smith

Joined: 18 May 2012
Posts: 682
Location: Hamilton, Lanarkshire, Scotland.

Posted: Wed Sep 20, 2023 12:11 pm    Post subject: Array argument for a statement function

I am trying very hard to break the habit of using nested do loops for everything, i.e. use array operations where possible.

In the following code, I think I am breaking the rules of Fortran, but FTN95 does not report any ERROR or WARNING.

What I see here is FTN95 accepting an array argument for a one line statement function, which I think is not allowed?

Is my understanding correct (a bug) or am I missing something in my understanding?

 Code: program p2 implicit none integer, parameter :: n = 4 real*8 :: x(n) = 0, y(n) = 0, z(n,n) = 0 integer i,j real*8  f, a, b !Statement function to define a function f of two scalars x and y.    f(a,b) = a + b      x = [1,2,3,4]    y = [1,2,3,4]    do i = 1, n      z(:,i) = f(x(:), y(i))    ! Should FTN95 not generate a fatal ERROR here?    end do    print*, 'Using array operation to eliminate one do loop and a statement function'    do i = 1, n      print*, (z(i,j),j = 1,n)    end do    print* !  This is allowed because f2 is elemental    do i = 1, n      z(:,i) = f2(x(:), y(i))    end do    print*, 'Using array operation to eliminate one do loop using elemental function'    do i = 1, n      print*, (z(i,j),j = 1,n)    end do    contains    real*8 elemental function f2(c,d)    real*8, intent(in) :: c, d      f2 = c+d    end function f2     end program p2

i.e. Is the assigment:
 Code: z(:,i) = f(x(:), y(i))

valid fortran in this context?
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1

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