[Fortran] 纯文本查看 复制代码
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) = [31,28,31,30,31,30,31,31,30,31,30,31]
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进行如下操作[Fortran] 纯文本查看 复制代码
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)