Fortran 我的分配中的什么导致了整数溢出?

Fortran 我的分配中的什么导致了整数溢出?,fortran,allocation,gfortran,integer-overflow,Fortran,Allocation,Gfortran,Integer Overflow,我有一组代码,其中声明了所有变量的大小。但是,我想更改它们,使一些变量是可分配的 这(我相信)是原件的相关代码 parameter (m=10**5,nchar=2000,ncols=110) character (LEN=*), PARAMETER :: FORM = "(A)" character(LEN=nchar),DIMENSION(m) :: data * determine the length of the data nlines = 0 do i = 1,m read(

我有一组代码,其中声明了所有变量的大小。但是,我想更改它们,使一些变量是可分配的

这(我相信)是原件的相关代码

parameter (m=10**5,nchar=2000,ncols=110)
character (LEN=*), PARAMETER :: FORM = "(A)"
character(LEN=nchar),DIMENSION(m) :: data

* determine the length of the data
nlines = 0
do i = 1,m
   read(12,*,end=10)
   nlines = nlines+1
end do
nlines = nlines+1

* read in the data
10  REWIND(unit = 12)
do i = 1,nlines
   read(12,FORM) data(i)
end do
这是我想要的表格

parameter (m=10**5,nchar=2000,ncols=110)
character (LEN=*), PARAMETER :: FORM = "(A)"
character(LEN=:),DIMENSION(:),allocatable :: data
integer j
character(LEN=100000) :: temp

* determine the length of the data
nlines = 0
j = 0
do while (ios == 0)
   read(12,FORM,end=10,iostat=ios) temp
   if (LEN(TRIM(temp)) .gt. j) THEN
      j = LEN(TRIM(temp))
   end if
   nlines = nlines+1
end do
nlines = nlines+1

10  REWIND(unit = 12)
ALLOCATE (character(LEN=j) :: data(nlines))

* read in the data
do i = 1,nlines
   read(12,FORM) data(i)
end do
问题是,这会导致整数溢出错误。“Fortran运行时错误:计算要分配的内存量时出现整数溢出”。我发现这非常令人困惑,因为我从测试数据集中获得的“nlines”和“j”值分别只有10和110

我发现,如果我不分配字符长度(即保持不变),这是可行的

我正在使用gfortran,版本4.8.0


我的代码/方法有什么问题

对不起,我忘了把它包括在原来的帖子里。在文本文件读入“数据”之前,它链接到一个倒带命令。我将更正原始帖子。使用tag获得更多关注。