[Fortran] 纯文本查看 复制代码 Program www_fcode_cn
Implicit None
Integer :: i , k , ierr , N , GetFileN
real , allocatable :: x(:) , y(:) , z(:)
character(len=32) :: c
Open( 12 , File = "gp_pos.txt" )
Open( 13 , File = "gp_pos_new.txt" )
N = GetFileN( 12 ) - 3
allocate( x(N) , y(N) , z(N) )
Do i = 1 , 3
read( 12 , * ) c
End Do
Do i = 1 , N
read( 12 , * , iostat = ierr ) c , c , x(i) , y(i) , c
if ( ierr /= 0 ) exit
k = len_trim( c )
read( c(1:k-1) , * ) z(i)
write( 13 , * ) x(i) , y(i) , z(i)
End Do
Close( 12 )
Close( 13 )
End Program www_fcode_cn
Integer Function GetFileN( iFileUnit )
!// 此函数应在打开文件后立即调用。调用后读取位置返回文件起始位置
Implicit None
Integer , Intent( IN ) :: iFileUnit
character( Len = 1 ) :: cDummy
integer :: ierr
GetFileN = 0
Rewind( iFileUnit )
Do
Read( iFileUnit , * , ioStat = ierr ) cDummy
If( ierr /= 0 ) Exit
GetFileN = GetFileN + 1
End Do
Rewind( iFileUnit )
End Function GetFileN |