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 

False error reports for correct program

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



Joined: 31 Oct 2006
Posts: 1707

PostPosted: Sun May 01, 2022 1:19 pm    Post subject: False error reports for correct program Reply with quote

The following program is quite simple and it should be possible to compile and run this program with no errors.

Code:
program pgm
   implicit none
   real, dimension(:,:), allocatable :: ev
   integer i, nsub, mi

   nsub = 10
   mi = 5
   ev = reshape( gaussian(nsub*mi),(/mi,nsub/) )
   print *,(ev(1,i),i=1,5)

   contains

   function gaussian(n)
! return an array of gaussian random variates with variance 1
   integer :: n
   real, dimension(n) :: gaussian
   real, dimension(n) :: rn
   real :: rn1,rn2,arg,x1,x2,x3
   real, parameter :: pi=4.0d0*atan(1.0)
   integer :: i
   if(mod(n,2) /= 0)stop 'Gaussian: argument must be an even integer'
   call random_number(rn)
   do i=1,n/2
      rn1=rn(2*i-1)
      rn2=rn(2*i)
      arg=2.0*pi*rn1
      x1=sin(arg)
      x2=cos(arg)
      x3=sqrt(-2.0*log(rn2))
      gaussian(2*i-1)=x1*x3
      gaussian(2*i)=x2*x3
   enddo
   end function gaussian

end program


With no options or with /debug, the program aborts with

Code:
     Error: Nonconformant arrays


With /64 /check, the program aborts with

Code:
     Integer arithmetic overflow
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon May 02, 2022 9:40 am    Post subject: Reply with quote

mecej4

Thank you for the feedback on this false error report. This is another instance of "allocate on assignment" not working. At the moment an explicit allocate

Code:
allocate(ev(mi,nsub))


is required before the call to RESHAPE.

It is interesting that you class this as a "simple" program. My first impression is that a fix will be quite difficult.
Back to top
View user's profile Send private message AIM Address
mecej4



Joined: 31 Oct 2006
Posts: 1707

PostPosted: Mon May 02, 2022 9:53 am    Post subject: Reply with quote

Quote:
It is interesting that you class this as a "simple" program.


Sorry, I guessed that because the allocation size of the array is knowable at compile time the compiler's job could be "simple".
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2405
Location: Sydney

PostPosted: Mon May 02, 2022 9:54 am    Post subject: Reply with quote

Does function gaussian require a RESULT statement for where the value of the function is an array?

I thought this was a requirement for Fortran 95 ?
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1707

PostPosted: Mon May 02, 2022 11:01 am    Post subject: Reply with quote

Indeed, Fortran 95 requires:

Quote:
If the function result is array valued or a pointer, this shall be specified by specifications of the name of the result variable within the function body


Later version of Fortran allow a declaration type spec to be used as a prefix spec in the FUNCTION statement as an alternative to a RESULTS clause.

We are grateful that FTN95 supports many of these features, although they did not exist in Fortran 95.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Aug 01, 2022 7:38 am    Post subject: Reply with quote

The missing functionality for RESHAPE has now been added for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support 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