[Fortran] 纯文本查看 复制代码
program example
implicit none
integer :: i , o
real :: x , y , l , m , n , t , s ,d
real :: x1 , x2 , y1 , y2 , t1 , t2 , t0
d = 0
s = 0
x = 0
y = 0
open ( 13 , File = '222.txt' )
do o = 1 , 100
t = o * 0.01
do i = 1 ,100
read ( 13 , * ) x1 , y1 , t1
read ( 13 , * ) x2 , y2 , t2
d = ( t1 - t ) * ( t1 - t ) - ( t2 - t ) * ( t2 - t )
if ( d < 0 ) then
l = ( x1 - x ) * ( x1 - x ) + ( y1 - y ) * ( y1 - y )
s = s + l
else
end if
x = x1
y = y1
end do
end do
close( 13 )
write ( * ,* ) s
end program example
[Fortran] 纯文本查看 复制代码
Program www_fcode_cn
implicit none
Type ST_R
Real :: x , y , t
End Type ST_R
Type ( ST_R ) , target :: stRead , stLast , stLastRec !// 当前读取记录,上次读取记录,上次位移位置
Type ( ST_R ) , pointer :: pst
Real :: rTE = 0.0001 !// 时间精度
Real :: rSep = 0.01 !// 时间间隔
real :: s , t !// 平方和 , 当前搜索的时间
integer :: iErr
s = 0.0
open ( 13 , File = '222.txt' )
Read( 13 , * ) stLast%x , stLast%y , stLast%t
stLastRec = stLast
t = rSep
Do
Read( 13 , * , ioStat = iErr ) stRead%x , stRead%y , stRead%t
If ( iErr /= 0 ) Exit
If ( ( stRead%t > (t-rTE) ).and.( stLast%t < (t+rTE) ) ) then !// 等效于 stRead%t>=t and stLast%t<=t
if ( abs(stRead%t - t ) > abs(stLast%t - t ) ) then !// 比较前后两组哪个更接近
pst => stLast
else
pst => stRead
end if
write(*,'(4f13.6)') pst , t
s = s + (pst%x - stLastRec%x)**2 + (pst%y - stLastRec%y)**2
stLastRec = pst !// 上次记录位移位置为 pst
t = t + rSep
End If
stLast = stRead
End Do
write( * , * ) s
close( 13 )
End Program www_fcode_cn