Hey, I am working on a fortran program and ran into some strange problem. When I try to print some values ββof an array immediately before calling a particular routine, I get the correct values. Then I try to print some values ββof the same array immediately after starting the subroutine, and they are 0. I finally print the values ββof the array after the subroutine, and the values ββreturn to the expected values. Can someone help me understand why? My code is below:
Firstly, calling the subroutine in the main function with the values ββthat I want to display in the write statements:
if (iter .eq. 5) then write(*,*) 'vp vals: ',vp(0,23471), vp(0,23475) end if CALL GRID_DIVISION( & & NPTMAX, DIM, TYPEMAX, NEIGHMAX, NPTC, GRIDLIMIT, & & GRIDN, GRIDNUM, GRID, GNEIGH, XP, PTTYPE, TYPE, & & GRIDP, TEMP_GRIDP, GNEIGHMAX, PAINT, VP, ITER, gridvel & & ) if (iter .eq. 5) then write(*,*) 'vp vals: ',vp(0,23471), vp(0,23475) end if
This calls the following routine, from which I will publish only the relevant part:
SUBROUTINE GRID_DIVISION( & & NPTMAX, DIM, TYPEMAX, NEIGHMAX, NPTC, GRIDLIMIT, & & GRIDN, GRIDNUM, GRID, GNEIGH, XP, PTTYPE, TYPE, & & GRIDP, TEMP_GRIDP, GNEIGHMAX, PAINT,VP,ITER, gridvel & & ) IMPLICIT NONE INTEGER, INTENT(IN) :: NPTMAX, DIM, TYPEMAX, NEIGHMAX, GNEIGHMAX INTEGER, INTENT(IN) :: NPTC INTEGER, INTENT(IN) :: GRIDLIMIT INTEGER, INTENT(IN) :: GRIDN(0: DIM - 1) INTEGER, INTENT(IN) :: GRIDNUM INTEGER, INTENT(IN) :: PTTYPE(0: NPTMAX) INTEGER, INTENT(IN) :: TYPE(0: TYPEMAX) INTEGER, INTENT(INOUT) :: GRIDP(0: NPTMAX) INTEGER, INTENT(INOUT) :: GNEIGH(1: GRIDLIMIT, 0: GNEIGHMAX) REAL , INTENT(IN) :: GRID(1: GRIDLIMIT, 0: DIM - 1, 0: 1) REAL , INTENT(IN) :: XP(0: DIM - 1, 0: NPTMAX) REAL , INTENT(IN) :: VP(0: DIM - 1, 0: NPTMAX) INTEGER, INTENT(INOUT) :: TEMP_GRIDP(0: NPTMAX) INTEGER, INTENT(INOUT) :: PAINT(0:NPTMAX) INTEGER, INTENT(INOUT) :: ITER real, intent(inout) :: gridvel(GRIDNUM,0:1) INTEGER :: II, JJ, KK INTEGER :: DNUM INTEGER :: GRIDXP INTEGER :: SGRIDXP INTEGER :: EGRIDXP INTEGER :: SGRIDYP INTEGER :: EGRIDYP INTEGER :: SEARCH INTEGER :: SCOUNT INTEGER :: FCOUNT INTEGER :: ERROR INTEGER, PARAMETER :: CELL = 2 if (iter .eq. 5) then write(*,*) 'vp vals: ',vp(0,23471), vp(0,23475) end if ... end subroutine
With a lot of materials after this section, which does not exist. When I run the code, my outputs are at iteration 5 for this section:
vp vals: 75.00000 75.00000 vp vals: 0.00000000E+00 0.0000000E+00 vp vals: 75.00000 75.00000
I just can't understand why my VP array has no values ββin the routine.