芥子纳须弥 发表于 2022-9-28 20:50:41

想从TXT读40位的整数,读不出来

想TXT读40位的整数,读不出来。试了很多遍,发现代码30行取I15时能读出来,读15位后就报错了,怎么解决?program test
implicit none

integer                           :: Npop,tmin
INTEGER(KIND=2)                   ::Run_time
integer( kind = 8 )               :: Gene


CALL Get_Best (8,10,1,Gene)
write(*,*)'Gene:',Gene

end program test

    !   ******************** Get_Best *****************
subroutine Get_Best (tmin,Npop,Run_time,Gene)
implicit none
integer,intent(in)                        :: tmin,Npop
integer                                     :: Run_time
integer(KIND=8)                           :: Gene
integer(KIND=8),dimension(Npop)             :: GeneZ
integer                                     :: i,l
CHARACTER(LEN = 2)                                    :: cRun_time
character(LEN=100)                        :: Nome,annotation
CHARACTER(*), PARAMETER                     :: fileplace = "D:/simulation/"

write(cRun_time,'(I2)') Run_time
Nome = TRIM(ADJUSTL(cRun_time))//'namlist_in.txt'
OPEN(1,file = fileplace//Nome,status='old',FORM='FORMATTED')
read(1,'(A)') annotation
read(1,'(6X,I40)') (GeneZ(i),i=1,Npop)
close(1)
write(*,*)'GeneZ:',GeneZ
Gene=GeneZ(tmin)
end subroutine Get_Best

Transpose 发表于 2022-9-28 21:00:53

无法解决,integer(8)最大是9223372036854775807,总共19位,没法读取这么大的数。

li913 发表于 2022-9-28 21:36:12

首先从需求分析,你是否需要这么多位?
fortran做不到,可否用变通的方法,比如用多个数来存储,或者用字符串。

fcode 发表于 2022-9-29 08:48:28

有些看起来像数字的东西,如果不会参与计算的话,就用字符串来存储和读写吧。

比如身份证号码,你几乎不需要对他做计算。

芥子纳须弥 发表于 2022-9-29 09:39:06

Transpose 发表于 2022-9-28 21:00
无法解决,integer(8)最大是9223372036854775807,总共19位,没法读取这么大的数。

好的,谢谢

芥子纳须弥 发表于 2022-9-29 09:39:38

fcode 发表于 2022-9-29 08:48
有些看起来像数字的东西,如果不会参与计算的话,就用字符串来存储和读写吧。

比如身份证号码,你几乎不需 ...

谢谢建议:-handshake

芥子纳须弥 发表于 2022-9-29 09:40:12

li913 发表于 2022-9-28 21:36
首先从需求分析,你是否需要这么多位?
fortran做不到,可否用变通的方法,比如用多个数来存储,或者用字符 ...

谢谢建议:-handshake
页: [1]
查看完整版本: 想从TXT读40位的整数,读不出来