View previous topic :: View next topic |
Author |
Message |
mecej4
Joined: 31 Oct 2006 Posts: 1895
|
Posted: Sun May 01, 2022 1:19 pm Post subject: False error reports for correct program |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Mon May 02, 2022 9:40 am Post subject: |
|
|
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 |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1895
|
Posted: Mon May 02, 2022 9:53 am Post subject: |
|
|
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 |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2560 Location: Sydney
|
Posted: Mon May 02, 2022 9:54 am Post subject: |
|
|
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 |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1895
|
Posted: Mon May 02, 2022 11:01 am Post subject: |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Mon Aug 01, 2022 7:38 am Post subject: |
|
|
The missing functionality for RESHAPE has now been added for the next release of FTN95. |
|
Back to top |
|
|
|