首先,你的代码不是 Fortran77 的,至少是 Fortran90 的
其次,你这个格式确实不好读,需要绕一些弯。
[Fortran] 纯文本查看 复制代码 character( len = 64 ) :: cTemp
character( len = 64 ) , allocatable :: cImag(:)
character( len = 1 ) , allocatable :: cSign(:)
real , allocatable :: rReal(:)
real :: tImag , tSign
integer :: i , j , k
Open(12,File='in.txt')
allocate(cImag(n)) !// 如果 n 是列数
allocate(cSign(n))
allocate(rReal(n))
Do i = 1 , m
read( fid , * ) (( rReal(j) , cSign(j) , cImag(j) ) , j = 1 , n )
Do j = 1 , n
tSign = 1.0
if ( cSign(j) == '-' ) tSign = -1.0
cTemp = cImag(j)
k = Len_Trim(cTemp)
cTemp(k:k) = ''
read( cTemp , * ) tImag
A( i , j ) = cmplx(rReal(j) , tSign * tImag )
End Do
End Do |