文件读取程序,显示Segmentation fault invalid memory...
网上的一个Fortran程序,读取土壤数据,数据可下载(http://www.seevccc.rs/GMINER30/FERRUM30/),但是在程序运行的时候,显示如下错误Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0ffffffff
我这里的系统是WIN10 64位,IDE是Code::Blocks 17.12,Fortran编译器是配套的GNU GCC Compiler,出问题的代码如下,核心的就是循环里面的open和read函数,那里有个注释说!!for pgf90,不知道是否意味着我的编译器等使用错误。
Fortran刚接手,基本不会,望指教,万分感谢!
program ferrum30
implicit none
!====================================================================
! FERRUM30 is a global database of Ferrum fractions (%) in
! potentially erodible soils.
! The database is available for download: wwww.seevccc.rs/GMINER30
! Data are on 30-seconds gird (~ km) and are organized in 27 tiles
! with NXT x NYT points each.
! The Ferrum fractions are normalized to 100% with respect to clay
! and silt content of soil.
!
! This program is intended for reading Ferrum fractions (%)
! from the database.
!====================================================================
integer :: i, j, it, jj
real, parameter :: dlo=1./120.,dla=1./120.
integer, parameter :: nxt=40./dlo+1, nyt=50./dla+1
integer, parameter :: ntile=27
real, dimension (nxt,nyt) :: minf
character*7, dimension (ntile) :: ctile
data ctile / &
'W180N90', 'W140N90', 'W100N90', 'W060N90', 'W020N90', &
'E020N90', 'E060N90', 'E100N90', 'E140N90', &
'W180N40', 'W140N40', 'W100N40', 'W060N40', 'W020N40', &
'E020N40', 'E060N40', 'E100N40', 'E140N40', &
'W180S10', 'W140S10', 'W100S10', 'W060S10', 'W020S10', &
'E020S10', 'E060S10', 'E100S10', 'E140S10'/
print*, 'Dimensions of each tile:', nxt,'x', nyt
do it=1,ntile
minf=0
open(31,file=ctile(it)//'.TFE', form='unformatted', &
status='unknown', access='direct', recl=nxt*nyt*4) !! for pgf90
read(31,rec=1) ((minf(i,j),i=1,nxt),j=1,nyt)
close(31)
enddo
endprogram ferrum30
换一个 Code::Blocks 的版本或者 gfortran 的版本。这是 gfortran 的一个 Bug fcode 发表于 2018-11-15 08:20
换一个 Code::Blocks 的版本或者 gfortran 的版本。这是 gfortran 的一个 Bug
非常感谢,按照你的建议,我更换了Code::Blocks 16.01,运行之后确实没有出现帖子中的问题了。:-handshake
页:
[1]