mecej4
Joined: 31 Oct 2006 Posts: 1887
|
Posted: Sat Sep 26, 2020 4:02 am Post subject: Allocated array is smaller than requested size |
|
|
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.
Code: | 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:
Code: | R:\MATH\LUKSAN\PLIS>tlisu
NF, MF, reqd. size = 10 5 130
Size (Ra) = 40
**** STOP: Error in allocated size of RA |
Last edited by mecej4 on Sat Sep 26, 2020 8:44 am; edited 1 time in total |
|