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

Problem with array bounds

Jorge_Alonso
Beginner
822 Views
Dear all,
I used to compile and execute my code under earlier versions of ifort 11.x in ubuntu and it worked fine. I also tested the same code under compaq visual fortran and it worked. Right now I am using a Mac OS Lion and last version of ifort.
When I run my code I get the following error
"forrtl: severe (408): fort: (2): Subscript #1 of the array DK has value 40001 which is greater than the upper bound of 40000
Image PC Routine Line Source
Stack trace terminated abnormally."
After some experimenting I isolated the subroutine where my program collapse. I define in a module the parameter "np=40000". In the following subroutine this dimension is indexed by "it." I do not understand why the array index goes to 40001
Next I paste the shell compilation code and the subroutine is causing trouble... I appreciate in advance any suggestion
P.D. I include all my code in a zip file
****************************SHELL SCRIPT****************************************
## SHELL PROGRAM TO COMPILE AND EXECUTE THE BENCHMARK MODEL OF "SOCIAL SECURITY
## AND RETIREMENT ACROSS THE OECD"
ifort -debug all -warn all -noaltparam -fast -xHost -unroll -assume protect_constants -assume noaccuracy_sensitive -check bounds -fltconsistency -traceback -c nrtype.f90 nrutil.f90 \\
modvar.f90 norm_cdf.f90 norm_inv.f90 tauchen.f90 q1da.f90 q1dax.f90 idamax.f gl15t.f90 uni.f90 zbrent.f90 aime.f90 \\
golden_srch.f90 oecd_simulation.f90 pia.f90 sdist3.f90 slcprofiles.f90 soptlc2b.f90 soptvalg2.f90 sprice1c2.f90 \\
stauchen_adda_cooper.f90 sub_cumsum.f90 sub_grid_generation.f90 sub_linint2d.f90 sval_end2.f90 swelfare.f90
ifort -debug all -warn all -noaltparam -fast -xHost -unroll -assume protect_constants -assume noaccuracy_sensitive -check bounds -fltconsistency -traceback -o myprog nrtype.o nrutil.o\\
modvar.o norm_cdf.o norm_inv.o tauchen.o q1da.o q1dax.o idamax.o gl15t.o uni.o zbrent.o aime.o golden_srch.o \\
oecd_simulation.o pia.o sdist3.o slcprofiles.o soptlc2b.o soptvalg2.o sprice1c2.o stauchen_adda_cooper.o \\
sub_cumsum.o sub_grid_generation.o sub_linint2d.o sval_end2.o swelfare.o
rm *.o
./myprog
**************************SUBROUTINE****************************************
SUBROUTINE sdist3(dv,dc,dh,dk,dz,de,dai,dpn,vfcn,cfcn,hfcn,kpfcn,w,me,b)
USE modvar
IMPLICIT NONE
REAL(DP), INTENT(OUT), DIMENSION(np,na) :: dv,dc,dh,dk,de,dai,dpn
INTEGER, INTENT(OUT), DIMENSION(np,na) :: dz
REAL(DP), INTENT(IN), DIMENSION(na,nk,ne,nz) :: vfcn,cfcn,hfcn,kpfcn
REAL(DP), INTENT(IN) :: w,me,b
REAL(DP) :: rd(np,na),smss(nz),aime,pia,hint
INTEGER :: it,ia,iz
CALL RANDOM_SEED(PUT=(/13567879/))
CALL RANDOM_NUMBER(rd)
dk(:,1)=b
dai(:,1)=0.0
dpn(:,1)=0.0
DO it=1,np
CALL sub_cumsum(smss,mss,nz)
DO iz=1,nz
IF (rd(it,1) .le. smss(iz)) THEN
dz(it,1)=iz
EXIT
END IF
END DO
dh(it,1)=hfcn(1,1,1,dz(it,1))
dv(it,1)=vfcn(1,1,1,dz(it,1))
dc(it,1)=cfcn(1,1,1,dz(it,1))
de(it,1)=ga(1)*gz(dz(it,1))*dh(it,1)
END DO
DO ia=2,na
DO it=1,np
CALL sub_cumsum(smss,m(dz(it,ia-1),:),nz)
DO iz=1,nz
IF (rd(it,ia) .le. smss(iz)) THEN
dz(it,ia)=iz
EXIT
END IF
END DO
CALL sub_linint2d(nk,ne,dk(it,ia),gk,ge,kpfcn(ia-1,:,:,dz(it,ia-1)),dk(it,ia-1),dai(it,ia-1))
! dk(it,ia)=dmax1(dk(it,ia),gkmax)
dai(it,ia)=aime(dai(it,ia-1),w*de(it,ia-1),ia-1)
CALL sub_linint2d(nk,ne,hint,gk,ge,hfcn(ia,:,:,dz(it,ia)),dk(it,ia),dai(it,ia))
IF (hint .ge. ft/2.0) THEN
dh(it,ia)=ft
ELSE
dh(it,ia)=nw
END IF
CALL sub_linint2d(nk,ne,dv(it,ia),gk,ge,vfcn(ia,:,:,dz(it,ia)),dk(it,ia),dai(it,ia))
CALL sub_linint2d(nk,ne,dc(it,ia),gk,ge,cfcn(ia,:,:,dz(it,ia)),dk(it,ia),dai(it,ia))
de(it,ia)=ga(ia)*gz(dz(it,ia))*dh(it,ia)
dpn(it,ia)=dmax1(0.0,generosity*pia(dai(it,ia),ia,me)*(1.0-itax*(1.0-(ft-dh(it,ia))/ft)))
END DO
! print '(I2,3F10.5)', ia,dk(it,ia),dai(it,ia),dz(it,ia)
END DO
END SUBROUTINE sdist3
0 Kudos
1 Reply
mecej4
Honored Contributor III
822 Views
You did not provide the input files for units 16, 17 and 18, without which the program did not run far enough to display the subscript error that you reported.
0 Kudos
Reply