Program PointTS
Implicit none
! Integer(kind=1)
Integer(kind=4) i, j, k, m
Real(kind=8) EETIME
Real(kind=8) EETIME_1
Integer(kind=4), Allocatable :: KSZ_Global(:,:), KSZ_Global_1(:,:)
Allocate(KSZ_Global(2,3))
Allocate(KSZ_Global_1(2,3))
EETIME = 1
k = 0
Do i = 1, 3
Do j = 1,2
KSZ_Global(j,i) = i+j+k
k = k + 1
End Do
End Do
Open (Unit=32, File="Matrix.bin", Status='Unknown')
Close(Unit=32, Status='DELETE')
Open(Unit=32,File="Matrix.bin",Status="new",Access='sequential',FORM='unformatted')
Do k = 1, 3
Write(32) EETIME
Write(32) ((KSZ_Global(i,j),j=1,3), i=1,2)
EETIME = EETIME + 1.0
KSZ_Global = KSZ_Global + 1
End Do
Close(32)
Open(Unit=32,File="Matrix.bin",Status="old",Access='stream',FORM='unformatted')
Do k = 1, 3
Inquire(32, Pos = m)
Read(32) EETIME_1
Inquire(32, Pos = m)
Write(6,*) EETIME_1
Read(32) ((KSZ_Global_1(i,j),j=1,3), i=1,2)
Inquire(32, Pos = m)
Write(6,*) ((KSZ_Global_1(i,j),j=1,3), i=1,2)
End Do
Close(32)
End Program
微信图片_20221002124611.png (7.47 KB, 下载次数: 165)
Transpose 发表于 2022-10-3 09:40
Fortran流文件-读写二进制任意位置
二进制的读写比较推荐流文件的格式,只需要按照顺序读取即可,旧的方式 ...
Program PointTS
Implicit none
Integer(kind=4) :: i, j, k = 0, m
Real(kind=8) :: EETIME=1,EETIME_1
Integer(kind=4), Allocatable,dimension(:,:) :: KSZ_Global, KSZ_Global_1
Allocate(KSZ_Global(2,3),KSZ_Global_1(2,3))
Do i = 1, 3
Do j = 1,2
KSZ_Global(j,i) = i+j+k
k = k + 1
End Do
End Do
Open(Unit=32,File="Matrix.bin",Status="replace",Access='sequential',FORM='unformatted')
Do k = 1, 3
Write(32) EETIME
Write(32) KSZ_Global
EETIME = EETIME + 1.0
KSZ_Global = KSZ_Global + 1
End Do
Close(32)
Open(Unit=32,File="Matrix.bin",Status="old",Access='stream')
Do k = 1, 3
Read(32) m,EETIME_1,m
Read(32) m,KSZ_Global_1,m
Write(*,*) EETIME_1
Write(*,*) KSZ_Global_1
End Do
Close(32)
End Program PointTS
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |