谁能告诉我如何使用fortran来阅读.mat? 我需要使用fortran来处理matlab中的二维矩阵。 我用
open(unit = 9006, file = 'zmatrix.mat',status = 'unknown', form = 'unformatted')
do i=1,296
do j=1,278
read(9006,*) zmatrix(i,j)
end do
end do
但据说fortran运行时错误:格式化存在未格式化的数据传输。 赞赏任何建议!
答案 0 :(得分:0)
这个小程序读取.mat文件(name是exec行的第一个参数,即./a.out Jet0500。该文件包含一个二维变量,
!compile with gfortran Read_mesh.f90
Module Mat_Read
real, allocatable :: omega(:,:)
contains
Subroutine Read_mesh
implicit none
integer :: unitno=10
integer :: kx,ncolumn,nrow
character (len=30) :: filename
call getarg(1,filename)
open(unit=unitno,file=filename,form="formatted",&
&status="old",action="read")
do kx=1,3 ! read by 3 lines
read(unitno,fmt="(A1)")
end do
read(unitno,fmt="(8x,i14)")nrow
read(unitno,fmt="(10x,i14)")ncolumn
allocate (omega(nrow,ncolumn))
do kx=1,nrow
read(unitno,*) omega(kx,:)
end do
close(unitno)
End Subroutine Read_mesh
End Module Mat_Read
Program test_Read_mesh
use Mat_Read
call Read_mesh
print *,omega(1,1)
End Program test_Read_mesh