!========================================
! Open file in ANSI mode
open(UNIT = fid, FILE = strFileName,
& ACCESS = 'SEQUENTIAL', ACTION = 'READ',
& FORM = 'FORMATTED', STATUS = 'OLD')
! This is a m X n complex matrix as:
read(fid, *) strBuf, strBuf, strBuf,
& m, strBuf, n, strBuf, strBuf, strBuf
! Memory allocation for A
allocate(A(m,n), STAT = ierr)
! Out of memory
if (ierr .ne. 0) then
close(fid, STATUS = 'KEEP')
print *, 'Out of memory!'
ReadZMatrixFromFile32 = .false.
return
end if
! Read matrix from file in row-major format
! 下一行肯定是错的,但我真心不知道咋整了。。。
read(fid, *) ((A(i,j), j=1,n), i=1,m)
! Close file
close(fid, STATUS = 'KEEP')
!======================================
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
山大克鲁士 发表于 2014-5-8 22:50
再次膜拜大神,学生的接口函数全弄好了,多亏了大神才能让学生实现Matlab、C、Fortran的数据文件无缝衔接~ ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |