일부 포트란 코드는 서브 루틴과 호출로 구성되어 있습니다. 정의 된 창 크기를 사용하여 행렬의 요소 평균을 계산합니다. 예를 들어, winsize = 2를 사용하여 (10,10) 배열에서 서브 루틴을 호출하면 (5,5) 배열을 반환합니다.Fortran의 "end program"문에서 분할 오류
이 코드는 다음과 같이 표시됩니다 :
SUBROUTINE avgwin(ts, sizelat,sizelon,winsize,size2,size3,ts_new)
implicit none
double precision, dimension(10,sizelat,sizelon) :: ts
double precision, dimension(winsize,winsize) :: store
double precision, dimension(10,size2,size3) :: ts_new
double precision :: par,ave
integer :: sizelat, sizelon,i,j,k,winsize,size2,size3
integer :: A, B,p,m,numb
A=0
B=0
par = 11 !Hypothetical value to be excluded
do i=1,10 !Looping through time
do j=1,sizelat !Looping through latitude
if ((j+winsize) > sizelat) then !Checks if it will exceed bounds
exit !If it'll exceed, discard remaining cells
end if
do k=1,sizelon !Looping through longitude
if ((k+winsize)>sizelon) then
exit
end if
store = ts(i,j:j+winsize,k:k+winsize) !Gets the values for that window
where (store == par) store = -99 !Replaces masked with -99
ave = 0
numb = 0 !Variable to count
do p=1,winsize
do m=1,winsize
if (store(p,m)==-99) then !Evaluates if it's masked, i.e., =-99
ave = ave
else
ave = ave + store(p,m) !Sum of existent values
numb = numb +1 !Updates counting variable
end if
end do
end do
ave = ave/numb !Calculates the mean
ts_new(i,A,B) = ave
B=B+1
end do
B=0
A=A+1
end do
A=0
B=0
end do
END SUBROUTINE
program testefor
implicit none
double precision, dimension(10,10,10) :: teste
double precision, dimension(10,5,5) :: oi
integer :: i,j,k
do i=1,10
do j=1,10
do k=1,10
teste(i,j,k)=i
end do
end do
end do
CALL avgwin(teste,10,10,2,5,5,oi)
print*, oi(1,5,5)
end program testefor
나는 그것을 실행 해요, 그러나 나는 세그먼트 오류를 얻을. 놀랍게도, GDB를 사용하여 디버깅을 시도했지만 정확한 결과를 반환하지만 프로그램을 종료 할 때 segfaults를 반환합니다. gdb에서 얻은 결과는 아래에서 확인할 수 있습니다 :
Breakpoint 1, testefor() at testefor.f90:56
56 do i=1,10
(gdb) cont
Continuing.
1.0000000000000000
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400f73 in testefor() at testefor.f90:67
67 end program testefor
따라서 프로그램은 올바른 (1,5,5) 요소 = 1.0을 반환하지만 다른 곳에서는 오류가 발생합니다.
누군가가 나를 식별하는 데 도움을 줄 수 있습니까? 감사합니다