
forums.silverfrost.com Welcome to the Silverfrost forums

View previous topic :: View next topic 
Author 
Message 
simon
Joined: 05 Jul 2006 Posts: 270

Posted: Mon Feb 06, 2023 7:06 pm Post subject: 


I was pleased to see that Source= has become available for the allocate statement. But when I get a rather unclear error message for the following code:
Code:  Module m
Integer, Dimension(:), Allocatable :: a
Integer, Dimension(5) :: b
End Module m
!
Program p
Use m
Allocate (a, Source=b)
End Program p 
When the documentation qualifies "for arrays only" what exactly does that mean? 

Back to top 


PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK

Posted: Tue Feb 07, 2023 8:51 am Post subject: 


Simon
Your code reveals a bug in the new FTN95 feature. At the moment it doesn't work when the arrays are declared in a module. I will log this as a bug that needs fixing.
The new feature has not yet been programmed for scalars so the following code will fail at runtime.
Code:  integer,allocatable::a
integer::b
b = 7
Allocate(a, source=b)



Back to top 


PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK

Posted: Tue Feb 07, 2023 9:28 am Post subject: 


Simon
The failure for arrays declared in a module has now been fixed for the next release of FTN95. 

Back to top 


simon
Joined: 05 Jul 2006 Posts: 270

Posted: Tue Feb 28, 2023 9:06 pm Post subject: 


Could we please get Nint, Aint and Anint added to the list of intrinsic functions that can be used in an initialisation expression. 

Back to top 


PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK

Posted: Wed Mar 01, 2023 9:07 am Post subject: 


Simon
Thanks. These have now been added for the next release of FTN95. 

Back to top 


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

Posted: Fri Mar 24, 2023 12:42 pm Post subject: 


Earlier in this discussion we talked about exactly what the ASSOCIATE construct does.
Following its recent addition to FTN95, the program below which uses the trapezoidal method to integrate a set of data points can now be compiled successfully and run.
I find the *three* lines of code that define the trapezoidal method rather mind blowing!
An very interesting and educational example, which I thought was worth sharing.
Code:  program p
implicit none
integer, parameter :: n = 101
double precision x(n), y(n), r1(n), omega
integer i
omega = 2.d0*4.d0*atan(1.d0)*50.d0
forall (i=1:n) x(i) = (i1)/5000.d0 ! x
forall (i=1:n) y(i) = cos(omega*x(i)) ! f(x)
forall (i=1:n) r1(i) = integrate(x(1:i),y(1:i)) ! Integral of f(x).dx
r1 = omega*r1 ! Normalise integral
i = winio@('%pl[native,frame,x_array,n_graphs=1,width=2,y_max=1,Title="f(x)"]&', 600,300,n,x,y)
i = winio@('%ff&')
i = winio@('%pl[native,frame,x_array,n_graphs=1,width=2,y_max=1,Title="Omega * Integral of f(x)"]', 600,300,n,x,r1)
contains
pure function integrate(x, y) result(r)
!! Calculates the integral of an array y with respect to x using the trapezoid
!! approximation. Note that the mesh spacing of x does not have to be uniform.
!!
!! Source: https://fortranwiki.org/fortran/show/integration
!!
double precision, intent(in) :: x(:) !! Variable x
double precision, intent(in) :: y(size(x)) !! Function y(x)
double precision :: r !! Integral y(x)�dx
! Integrate using the trapezoidal rule
associate(n => size(x))
r = sum((y(1+1:n0) + y(1+0:n1))*(x(1+1:n0)  x(1+0:n1)))/2.d0
end associate
end function
end program p



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
