Silverfrost Forums

Welcome to our forums

Allocated array is smaller than requested size

26 Sep 2020 3:02 (Edited: 26 Sep 2020 7:44) #26399

The following stripped down program exhibits peculiar behavior when compiled with FTN95 8.65, with /64 and either /check or /checkmate. No error is seen when the test program is compiled with /64 /debug.

The size of the allocated array is 40, which is a fraction of the requested size, 130, even though there was no detected error when the ALLOCATE statement was executed (i.e., ISTAT was 0).

In the real program where this error was first encountered, the failure occurred with an array subscript bound error in another subroutine where the allocated array was accessed and the program had been compiled with /64 /check.

module globals
   implicit none
   integer, parameter :: double=kind(0.0d0)
end module globals

Program main
   use globals, only : double
   Implicit None
   Integer :: nf
   Integer :: i
   Real (double), Dimension (10) :: x = [(-1d0,1d0, i = 1,5)]
!
   nf = 10
   Call plisu (nf, x)
   Stop
End Program main

Subroutine plisu(NF,X)
   use globals, only : double
   implicit none
   integer  ::  NF, istat
   real(double), dimension(*)  ::  X
   integer  ::  lgf, ls, lxo, mf, lRA
   real(double), allocatable, dimension(:)  ::  ra
   mf = 5
   lRA = 2*NF+2*NF*mf+2*mf
   print *,'NF, MF, reqd. size = ',nf,mf,lRA
   allocate (ra(2*NF+2*NF*mf+2*mf), stat=istat)   ! <<<=== Problem?
   if (istat /= 0)stop 'Error allocating RA'
   print *,'Size (Ra) = ',size(ra)
   if (size(ra) /= lRA)stop 'Error in allocated size of RA'
   lgf = 1
   ls = lgf + NF
   lxo = ls + NF
   call plis(NF, X, ra(lgf), ra(ls), ra(lxo))
   deallocate (ra)
   return
end subroutine plisu
   
Subroutine plis(NF,X,GF,S,XO)
   use globals, only : double
   implicit none
   integer  ::  NF
   real(double), dimension(*)  ::  X, GF, S, XO
   print *,'PLIS Entered'
   Return
end subroutine plis

The output when the program is compiled with version 8.65, with /64 /check:

R:\MATH\LUKSAN\PLIS>tlisu
 NF, MF, reqd. size =           10           5         130
 Size (Ra) =                    40
**** STOP: Error in allocated size of RA
26 Sep 2020 6:56 #26401

mecej4

Many thanks for the feedback. Your help is much appreciated.

29 Sep 2020 10:09 #26418

This failure has now been fixed for the next release of FTN95.

Please login to reply.