本帖最后由 vvt 于 2017-1-31 21:54 编辑
把 print 放到循环外面不就可以了?
[Fortran] 纯文本查看 复制代码 do i=start,end
read(7,*)dy , t(i)%tmax , t(i)%tmin , rain
t(i)%average=(t(i)%tmax+t(i)%tmin)/2 !日均温
total%average=total%average+t(i)%average !日均温累加=积温
enddo
print *, dy,total%average !
如果你要全部365个都读完,然后再计算start到end的平均值,可以这样
[Fortran] 纯文本查看 复制代码 PROGRAM MAIN
USE typedef
implicit none
real::rain
INTEGER,PARAMETER::temp=366
type(tdd)::t(temp)! 保存气温值
type(tdd):: total !日均温累加
integer i , dy , start , end
open(7,file="CN019067")
read(7,*)
write(*,*)"start:"
read(*,*) start
write(*,*)"end:"
read(*,*) end
do i=1,temp
read(7,*)dy , t(i)%tmax , t(i)%tmin , rain
t(i)%average=(t(i)%tmax+t(i)%tmin)/2 !日均温
end do
total%average = 0
do i=start,end
total%average=total%average+t(i)%average !日均温累加=积温
enddo
print *, dy,total%average !
end PROGRAM
|