soccer jersey forums.silverfrost.com :: View topic - Fortran 2003 and 2008 features
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 

Fortran 2003 and 2008 features
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Suggestions
View previous topic :: View next topic  
Author Message
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Mon Feb 06, 2023 7:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Tue Feb 07, 2023 8:51 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


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

PostPosted: Tue Feb 07, 2023 9:28 am    Post subject: Reply with quote

Simon

The failure for arrays declared in a module has now been fixed for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Tue Feb 28, 2023 9:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Wed Mar 01, 2023 9:07 am    Post subject: Reply with quote

Simon

Thanks. These have now been added for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



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

PostPosted: Fri Mar 24, 2023 12:42 pm    Post subject: Reply with quote

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)  = (i-1)/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:n-0) + y(1+0:n-1))*(x(1+1:n-0) - x(1+0:n-1)))/2.d0
    end associate
  end function
 
  end program p
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Suggestions All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Page 10 of 10

 
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