Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

0: arrays trouble

s8000_1
Beginner
1,027 Views
Hi. I found out that when using "0:" construction of arrays in subroutines following problem appears(example):
!main program
...
REAL, DIMENSION(0:3) :: x
REAL, DIMENSION(2) :: y
y=[1.,1.]
CALL myFunc(x,y)
...

!external module
...
SUBROUTINE myFunc(a,b)
REAL,DIMENSION(0:),INTENT(OUT) :: a
REAL,DIMENSION(2),INTENT(IN) :: b
a(0)=b(1)
!here is a breakpoint
...
then if i debug it there is following situation (printscreens):

and i can't use this "a"-array correctly,because of indexes shifting. so that i have to enter another parameter "N" in "myFunc" to fix this problem:
...
SUBROUTINE myFunc(a,b,N)
INTEGER,INTENT(IN) :: N
REAL,DIMENSION(0:N),INTENT(OUT) :: a
...
and in such case all next calculations work correctly.
My question: is it a feature or bug of a compilator? (Version 9.1.3291)
0 Kudos
8 Replies
Steven_L_Intel1
Employee
1,026 Views
Your printscreen output shows array Y in the caller - I don't see what is wrong when using A in the called routine.

Is function myfunc in a module? If not, do you have an interface block for it visible to the caller? One or the other is required when the array in the function is declared as an assumed-shape array (0:) or (:).
0 Kudos
s8000_1
Beginner
1,026 Views
when i assume "1." to "a" with index "0" (!)
...
a(0)=b(1) !b(1) is 1.
...
compiler applies "1." to "a" with index "1", and "a(0)" remains being "0.", if i use assumed-shape array ("0:"). If i don't use such construction all is ok ("a(0)" is "1.").
0 Kudos
Steven_L_Intel1
Employee
1,026 Views
Can you post a short but complete program that shows the problem you are seeing? I still don't understand it.
0 Kudos
s8000_1
Beginner
1,026 Views
There is problem while debugging next prog (read comments):

!file 1.f90
PROGRAM MainProgram
USE myModule
IMPLICIT NONE
REAL,DIMENSION(2) :: x
REAL,DIMENSION(0:5) :: y
x=[1.,1.]
CALL Test(y,x)
END PROGRAM MainProgram

!file 2.f90
MODULE myModule
IMPLICIT NONE
SUBROUTINE Test(a,b)
REAL,DIMENSION(0:),INTENT(OUT) :: a
REAL,DIMENSION(2), INTENT(IN) :: b
a(0:1)=b
a(5)=2. ! PLACE A BREAKPOINT HERE
!AND THEN CLICK "+" ON "a"
!VARIABLE
!(INCORRECT INDEXES)
END SUBROUTINE Test
END MODULE myModule



0 Kudos
Steven_L_Intel1
Employee
1,026 Views
Ok, thanks. I see the problem now. This would appear to be a bug in the debugger support. I'll pass it on to the developers.
0 Kudos
s8000_1
Beginner
1,026 Views
Hi again, and how to exlain this:

PROGRAM Test
IMPLICIT NONE
REAL,DIMENSION(0:3):: x
INTEGER i
x=[(i,i=0,3)]
CALL Test1(x)
END PROGRAM Test

SUBROUTINE Test1(Arr)
IMPLICIT NONE
REAL,DIMENSION(0:),INTENT(IN):: Arr
PRINT*, LBOUND(Arr)
END SUBROUTINE Test1

It prints "1", but when using this subr. in module all is ok (it prints "0").
0 Kudos
Steven_L_Intel1
Employee
1,026 Views
Because Arr is a deferred-shape array, an explicit interface is required to be visible to the caller. Without that, the behavior is unpredictable. It works when you put Test1 in a module because that creates an explicit interface.
0 Kudos
s8000_1
Beginner
1,026 Views
Thanks.
0 Kudos
Reply