[Fortran] 纯文本查看 复制代码
Program www_fcode_cn Implicit None
Integer*4 :: iVar1 ,iVar2,iVar1M , iVar2M
Real*4 :: rVar1 , rVar2,rVar1M , rVar2M
Character(Len=16) :: cStr,cStrM
C 写二进制数据----------------------------------------------------
C 方法1 直接写入文件(Access = 'Direct' )
Open( 12 , File = 'TestBin.Bin' , Access = 'Direct' ,
& Form = 'Unformatted' , RecL = 4 )
Write( 12 , Rec = 1 ) 271 , 783 , 2581.192_4 , 1.6892716E-07
Write( 12 , Rec = 2 ) "ABCDEFGHIGKLMNOP"
Close( 12 )
C 方法2 顺序写入文件(Access = 'Sequential' )写入
Open( 14 , File = 'TestBin2.Bin' ,Access = 'Sequential' ,
& Form = 'Unformatted' )
Write(14) 271 , 783 , 2581.192_4 , 1.6892716E-07
Write(14) "ABCDEFGHIGKLMNOP"
Close(14 )
C 读二进制文件------------------------------------------------------
c ****读二进制文件(Access = 'Direct' )
Open( 12 , File = 'TestBin.Bin' , Access = 'Direct' ,
& Form = 'Unformatted' , RecL = 4 )
Read( 12 , Rec = 1) iVar1 , iVar2 , rVar1 , rVar2
Read( 12 , Rec = 2) cStr
Write(* , * ) iVar1 , iVar2 , rVar1 , rVar2
Write(* , * ) cStr
Close( 12 )
c ****读二进制文件(Access = 'Sequential' )
Open( 14 , File = 'TestBin2.Bin',form='Unformatted',
& Access = 'Sequential')
Read( 14 ) iVar1M , iVar2M , rVar1M , rVar2M
Read( 14 ) cStrM
Write(* , * ) iVar1M , iVar2M , rVar1M , rVar2M
Write(* , * ) cStrM
Close( 14 )
End Program www_fcode_cn