|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Tue Jan 27, 2015 4:49 pm Post subject: Run-time Error 11 |
|
|
When running my program I got the following error:
Error 11, Array subscript(s) out-of-bounds
RANK - in file freeformat2.f95 at line 48 [+014a]
TEST - in file freeformat2.f95 at line 36 [+0d99]
But in line 36 and 48, I didn't find any question there. Does anyone have any ideas what the problem is please?[/b] |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Tue Jan 27, 2015 5:18 pm Post subject: |
|
|
If the program is short then you could post it here so that we can see the lines of code that are causing the problem. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Tue Jan 27, 2015 5:31 pm Post subject: |
|
|
And, if the program is long and you feel that creating a short example with the same problematic behavior would take more effort than you are willing to provide, please zip up the whole program (source files, data files, build instructions) and post the zip on a public-access folder in the cloud. Provide a link to that zip file in this forum. There may be some forum readers willing to take a look despite the size. |
|
Back to top |
|
|
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Tue Jan 27, 2015 5:39 pm Post subject: Re: |
|
|
Code: | n=n1+n2
call rank(xp,n,xr)
call rank(y,n,yr)
end program test |
line 36 is call rank(xp,n,xr)
Last edited by star2066 on Tue Jan 27, 2015 5:42 pm; edited 1 time in total |
|
Back to top |
|
|
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Tue Jan 27, 2015 5:40 pm Post subject: |
|
|
Code: | SUBROUTINE RANK(X,N,XR)
DIMENSION X(1),XR(1)
COMMON /BLOCK4/ XS(500)
AN=N
IPR=6
HOLD=X(1)
DO 60 I=2,N
IF(X(I).NE.HOLD)GOTO 90
60 CONTINUE
WRITE(IPR, *)HOLD
AVRANK=(AN+1.0)/2.0
DO I=1,N
XR(I)=AVRANK
end do
90 CONTINUE
CALL SORT(X,N,XS)
NM1=N-1
XPREV=X(1)
DO 700 I=1,N
JMIN=1
IF(X(I).GT.XPREV)GOTO 770
IF(I.EQ.1)GOTO 790
IF(X(I).EQ.XPREV)GOTO 750
GOTO 790
750 CONTINUE
XR(I)=RPREV
GOTO 880
770 CONTINUE
JMIN=K
IF(JMIN.LT.N)GOTO 790
IF(JMIN.EQ.N)GOTO 820
IBRAN=1
WRITE(IPR,*)IBRAN
WRITE(IPR,*)JMIN
STOP
790 CONTINUE
DO 800 J=JMIN,NM1
IF(X(I).NE.XS(J))GOTO 800
JP1=J+1
DO 900 K=JP1,N
IF(XS(K).NE.XS(J))GOTO 950
900 CONTINUE
K=N+1
950 CONTINUE
AVRANK=J+K-1
AVRANK=AVRANK/2.0
XR(I)=AVRANK
GOTO 880
800 CONTINUE
820 CONTINUE
J=N
K=N+1
IF(X(I).EQ.XS(J))GOTO 850
IBRAN=2
WRITE(IPR,*)IBRAN
WRITE(IPR,*)X(I),XS(J)
STOP
850 CONTINUE
XR(I)=N
880 CONTINUE
XPREV=X(I)
RPREV=XR(I)
700 CONTINUE
RETURN
END subroutine rank
!++++++++++++++++++++++++++++++++++++++++++++++++
SUBROUTINE SORT(X,N,Y)
DIMENSION X(:),Y(:)
integer,DIMENSION(500):: IU,IL
IPR=6
HOLD=X(1)
DO 60 I=2,N
IF(X(I).NE.HOLD)GOTO 90
60 CONTINUE
WRITE(IPR,*)HOLD
DO 61 I=1,N
Y(I)=X(I)
61 CONTINUE
RETURN
90 CONTINUE
DO 100 I=1,N
Y(I)=X(I)
100 CONTINUE
NM1=N-1
DO 200 I=1,NM1
IP1=I+1
IF(Y(I).LE.Y(IP1))GOTO 200
GOTO 250
200 CONTINUE
RETURN
250 M=1
I=1
J=N
305 IF(I.GE.J)GOTO 370
310 K=I
MID=(I+J)/2
AMED=Y(MID)
IF(Y(I).LE.AMED)GOTO 320
Y(MID)=Y(I)
Y(I)=AMED
AMED=Y(MID)
320 L=J
IF(Y(J).GE.AMED)GOTO 340
Y(MID)=Y(J)
Y(J)=AMED
AMED=Y(MID)
IF(Y(I).LE.AMED)GOTO 340
Y(MID)=Y(I)
Y(I)=AMED
AMED=Y(MID)
GOTO 340
330 Y(L)=Y(K)
Y(K)=TT
340 L=L-1
IF(Y(L).GT.AMED)GOTO 340
TT=Y(L)
350 K=K+1
IF(Y(K).LT.AMED)GOTO 350
IF(K.LE.L)GOTO 330
LMI=L-I
JMK=J-K
IF(LMI.LE.JMK)GOTO 360
IL(M)=I
IU(M)=L
I=K
M=M+1
GOTO 380
360 IL(M)=K
IU(M)=J
J=L
M=M+1
GOTO 380
370 M=M-1
IF(M.EQ.0)RETURN
I=IL(M)
J=IU(M)
380 JMI=J-I
IF(JMI.GE.11)GOTO 310
IF(I.EQ.1)GOTO 305
I=I-1
390 I=I+1
IF(I.EQ.J)GOTO 370
AMED=Y(I+1)
IF(Y(I).LE.AMED)GOTO 390
K=I
395 Y(K+1)=Y(K)
K=K-1
IF(AMED.LT.Y(K))GOTO 395
Y(K+1)=AMED
GOTO 390
END subroutine sort |
|
|
Back to top |
|
|
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Tue Jan 27, 2015 5:46 pm Post subject: |
|
|
And here is my subroutines. I found them on NIST website, I believe they are fortran 77 code, but I think them can be used in ftn 95 with a little change. |
|
Back to top |
|
|
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Tue Jan 27, 2015 5:52 pm Post subject: Re: |
|
|
PaulLaidler wrote: | If the program is short then you could post it here so that we can see the lines of code that are causing the problem. |
Thank you for your reply, my code is on above |
|
Back to top |
|
|
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Tue Jan 27, 2015 5:55 pm Post subject: Re: |
|
|
mecej4 wrote: | And, if the program is long and you feel that creating a short example with the same problematic behavior would take more effort than you are willing to provide, please zip up the whole program (source files, data files, build instructions) and post the zip on a public-access folder in the cloud. Provide a link to that zip file in this forum. There may be some forum readers willing to take a look despite the size. |
Got u. Thank u for your reply so quick. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Tue Jan 27, 2015 5:59 pm Post subject: |
|
|
We would need to see the whole of the main program.
That is where the value of n is set and it is this value that appears to be too large. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Tue Jan 27, 2015 6:00 pm Post subject: |
|
|
Star2066: Old code such as the one that you posted, with dummy argument arrays with declared size of (1), as in your subroutine RANK, will not behave properly when you use a checking option such as /CHECK. Either compile your entire program without subscript checking, or modify/modernize the subroutines to make them survive subscript checking, or see if FTN95 contains a library function that will do the same task (sorting, in this case). |
|
Back to top |
|
|
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Tue Jan 27, 2015 6:39 pm Post subject: Re: |
|
|
PaulLaidler wrote: | We would need to see the whole of the main program.
That is where the value of n is set and it is this value that appears to be too large. |
Code: |
program test
implicit none
real :: r1,r2,c1,c2,e,x
real,dimension(500) :: xp
real,dimension(500) :: y
real,dimension(500) :: xr
real,dimension(500) :: yr
integer :: i,n1,n2,n
print *,'input numbers before change point to continue'
read *, n1
print *,'input numbers after change point to continue'
read *, n2
print *,'input coefficient of relationship before change point to continue'
read *, r1
print *,'input coefficient of relationship after change point to continue'
read *, r2
open(unit=1, file='results.txt')
c1 = sqrt(1-r1**2)
c2 = sqrt(1-r2**2)
write(1,*) 'c1=', c1,'c2=', c2
y=0
do i = 1,n1+n2 ! call random_seed(0)
call random_number(e)
if (i<n1) goto 10
if (i>=n1) goto 20 ! call random_seed(0)
10 call random_number(x)
xp(i) = x
y(i) = xp(i)*r1+e*c1 ! call random_seed(0)
20 call random_number(x)
xp(i)=x
y(i) = xp(i)*r2+e*c2
write(1,*)'i=',i,' x price=', xp(i),' y price=',y(i)
print *,'i=',i,' x price=', xp(i),' y price=',y(i)
end do
n=n1+n2
call rank(xp,n,xr)
call rank(y,n,yr)
end program test
|
This is my main program. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Tue Jan 27, 2015 7:18 pm Post subject: |
|
|
With two changes, your program runs fine with /check. The first is to replace (1) by (N) in the DIMENSION statement in subroutine RANK; the second is to replace ( (darn smileys; that was left-paren, colon, right-paren) by (N) in subroutine SORT. You may not use assumed size arrays as formal arguments to a subprogram unless you also provide an explicit interface to the subprogram in the caller. |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Tue Jan 27, 2015 7:38 pm Post subject: Re: |
|
|
mecej4 wrote: | Star2066: Old code such as the one that you posted, with dummy argument arrays with declared size of (1), as in your subroutine RANK, will not behave properly when you use a checking option such as /CHECK. |
I would leave checking on. The compiler should be able to cope with the (1) sized arrays if the option \OLD_ARRAYS is enabled. In Plato this is on the language tab (Allow old arrays) in the Properties window. It effectively changes (1) to (*). _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Wed Jan 28, 2015 5:10 am Post subject: Re: |
|
|
mecej4 wrote: | With two changes, your program runs fine with /check. The first is to replace (1) by (N) in the DIMENSION statement in subroutine RANK; the second is to replace ( (darn smileys; that was left-paren, colon, right-paren) by (N) in subroutine SORT. You may not use assumed size arrays as formal arguments to a subprogram unless you also provide an explicit interface to the subprogram in the caller. |
Thank you for you answer, it works. But I have a new problem:
*** Error 112, Reference to undefined variable, array element or function result (/UNDEF)
TEST - in file freeformat2.f95 at line 39 [+0efb]
Code: |
program test
implicit none
real :: r1,r2,c1,c2,e,x
real,dimension(500) :: xp
real,dimension(500) :: y
real,dimension(500) :: xr
real,dimension(500) :: yr
integer :: i,n1,n2,n
print *,'input numbers before change point to continue'
read *, n1
print *,'input numbers after change point to continue'
read *, n2
print *,'input coefficient of relationship before change point to continue'
read *, r1
print *,'input coefficient of relationship after change point to continue'
read *, r2
open(unit=1, file='results.txt')
open(unit=2, file='rankresults.txt')
c1 = sqrt(1-r1**2)
c2 = sqrt(1-r2**2)
write(1,*) 'c1=', c1,'c2=', c2
y=0
do i = 1,n1+n2 ! call random_seed(0)
call random_number(e)
if (i<n1) goto 10
if (i>=n1) goto 20 ! call random_seed(0)
10 call random_number(x)
xp(i) = x
y(i) = xp(i)*r1+e*c1 ! call random_seed(0)
20 call random_number(x)
xp(i)=x
y(i) = xp(i)*r2+e*c2
write(1,*)'i=',i,' x price=', xp(i),' y price=',y(i)
print *,'i=',i,' x price=', xp(i),' y price=',y(i)
end do
n=n1+n2
call rank(xp,n,xr)
call rank(y,n,yr)
write(2,*)' x rank=', xr,' y rank=',yr
end program test
|
|
|
Back to top |
|
|
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Wed Jan 28, 2015 5:11 am Post subject: Re: |
|
|
mecej4 wrote: | With two changes, your program runs fine with /check. The first is to replace (1) by (N) in the DIMENSION statement in subroutine RANK; the second is to replace ( (darn smileys; that was left-paren, colon, right-paren) by (N) in subroutine SORT. You may not use assumed size arrays as formal arguments to a subprogram unless you also provide an explicit interface to the subprogram in the caller. |
by the way, how to use that "/check", could you please tell me about that? |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|