3.43 KB, 下载次数: 1
原数据文件
Program www_fcode_cn
Implicit None
Integer :: i , ierr
real :: x , y , z
character(len=32) :: c
Open( 12 , File = "gp_pos.txt" )
Open( 13 , File = "gp_pos_new.txt" )
Do i = 1 , 3
read( 12 , * ) c
End Do
Do
read( 12 , * , iostat = ierr ) i , c , x , y , c
if ( ierr /= 0 ) exit
i = len_trim( c )
read( c(1:i-1) , * ) z
write( 13 , * ) x , y , z
End Do
Close( 12 )
Close( 13 )
End Program www_fcode_cn
楚香饭 发表于 2015-8-17 20:35
[mw_shl_code=fortran,true]Program www_fcode_cn
Implicit None
Integer :: i , ierr
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
百事可乐 发表于 2015-8-18 21:24
[mw_shl_code=fortran,true]Program www_fcode_cn
Implicit None
Integer :: i , k , ierr , N , GetFi ...
vvt 发表于 2015-8-18 22:51
你乱改代码当然结果不正确
百事可乐 发表于 2015-8-18 21:24
[mw_shl_code=fortran,true]Program www_fcode_cn
Implicit None
Integer :: i , k , ierr , N , GetFi ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |