Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
29 Views

range checking misinformation

I am seeing a range checking fault on windows that does not make sense so far. program output: test2:Enter routine test2: allocate xx at nn= 8 test2: allocated xx at lbound= 1 upper bound= 8 forrtl: severe (408): fort: (10): Subscript #1 of the array XX has value 8 which is greater than the upper bound of 7 Image PC Routine Line Source libifcoremdd.dll 000007FECE2DECC2 Unknown Unknown Unknown testcase.exe 000000013FE82140 MAIN__ 33 testcase.f90 testcase.exe 000000013FE824CE Unknown Unknown Unknown testcase.exe 000000013FE83E74 Unknown Unknown Unknown testcase.exe 000000013FE83D87 Unknown Unknown Unknown testcase.exe 000000013FE83C4E Unknown Unknown Unknown testcase.exe 000000013FE83E89 Unknown Unknown Unknown kernel32.dll 000000007771556D Unknown Unknown Unknown ntdll.dll 000000007797372D Unknown Unknown Unknown I think this is on windows 7 but would not swear to it. intel 17.1 Intel® Parallel Studio XE 2017 Update 1 Composer Edition for Fortran Windows* Integration for Microsoft Visual Studio* 2015, Version 17.0.0040.14, Copyright © 2002-2016 Intel Corporation. All rights reserved. * Other names and brands may be claimed as the property of others. source code: program test2 implicit none ! Variables character(len=6) :: rout = 'test2: ' logical :: local_debug = .true., opt=.true. logical :: closed=.true. integer :: n1st, n1nd, nn real(kind=8), dimension(:),allocatable :: xx,yy real(kind=8), dimension(1:7) :: x,y ! Body of testp if ( local_debug ) print *,rout,'Enter routine' n1st = 1 n1nd = 7 x(n1st:n1nd) = [1,2,3,4,5,6,7] y = x nn = n1nd - n1st + 1 if ( opt ) then closed = .false. nn = nn + 1 else closed = .true. end if print *,rout,' allocate xx at nn= ',nn allocate(xx(nn),yy(nn)) print *,rout,' allocated xx at lbound= ',lbound(xx,1),' upper bound=',ubound(xx,1) ! check coordinates if ( .true. ) then xx = x(n1st:n1nd) yy = y(n1st:n1nd) if ( .not. closed ) then xx(nn) = x(n1st) yy(nn) = y(n1st) end if end if stop end program test2 It runs on Linux in release mode. I have not tested release mode on windows. any advice would be appreciated. thanks, scott
0 Kudos
3 Replies
Highlighted
29 Views

What appears to be happening is

xx = x(n1st:n1nd)

is

xx = x(1:7)

Which with realloc left hand side enabled resized (reallocates) xx to size of 7.

Try adding -assume:norealloc_lhs to your compiler options.

or use

xx(n1st:n1nd) = x(n1st:n1nd) ! *** with knowledge that xx(8) has not changed.

Jim Dempsey

 

0 Kudos
Highlighted
New Contributor I
29 Views

brilliant. that did it (xx(n1st:n1nd) = x(n1st:n1nd) ! *** ). I did not locate the -assume:norealloc_lhs in visual studio, but this makes sense now. thanks Jim!
0 Kudos
Highlighted
Black Belt Retired Employee
29 Views

Please use Jim's second suggestion rather than norealloc_lhs, which disables a major feature of the Fortran standard.

0 Kudos