Silverfrost Forums

Welcome to our forums

False error reports for correct program

1 May 2022 12:19 #28957

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

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

     Error: Nonconformant arrays

With /64 /check, the program aborts with

     Integer arithmetic overflow
2 May 2022 8:40 #28959

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

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.

2 May 2022 8:53 #28960

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'.

2 May 2022 8:54 #28961

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 ?

2 May 2022 10:01 #28964

Indeed, Fortran 95 requires:

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.

1 Aug 2022 6:38 #29212

The missing functionality for RESHAPE has now been added for the next release of FTN95.

Please login to reply.