读取txt文件中指定列的数据
有一个18627行,15列的txt文件,需读取其中第5,6,7行的数据,如何用read语句实现 本帖最后由 kyra 于 2020-3-7 09:03 编辑subroutine turn(year,mon,day)
Implicit none
integer :: y , m , d , t
open(55,file='ztzl-1.txt')
Do
do
read( 55 , * , ioStat = t ) y , m , d
if ( t/= 0 ) exit
End Do
Close(55)
contains
Integer Function DaysInYear( year , mon , day )
Integer :: year , mon , day
Integer :: DaysInMonth(12) =
if ( ( (MOD(year,4)==0).and.(MOD(year,100)/=0) ) .or. (mod(year,400)==0) ) then
DaysInMonth(2) = 29
else
DaysInMonth(2) = 28
end if
DaysInYear = sum( DaysInMonth(:mon-1) ) + day
End Function DaysInYear
End sunroutine turn如上即为整段函数,读取后还需使用y,m,d进行如下操作 open(55,file='ztzl-1.txt')
Do i=1,4
read(55,*)
End Do
do i=5,7
read( 55 , * , ioStat = t ) y , m , d
if ( t/= 0 ) exit
!调用函数
End Do
Close(55) li913 发表于 2020-3-6 12:21
open(55,file='ztzl-1.txt')
Do i=1,4
read(55,*)
谢谢您了,我想了挺长时间也没想到这么处理,还是懂的太少了
页:
[1]