[Fortran] 纯文本查看 复制代码
program interp2_line_pwv
implicit none
integer :: stat,stat2,stat3,yr_1,dayofyear_1,hr_1
integer :: yr_2,dayofyear_2,hr_2,yr,Days_Of_Year,m,n,dayofyear,hr
character :: filename*13,filename_new*14
real*8 :: timeall,time_all_1,pwv_mm_1,time_all_2,pwv_mm_2,fake
open (11,file='file.txt')
close (11,status='delete')
call system('for %f in (*_wave.pwv) do echo %f >> file.txt' )
open (11,file='file.txt')
stat=0
do while (stat==0)
read (11,*,iostat=stat) filename
if (stat/=0) exit
filename_new = filename(1:9)//'2.pwv'
open (22,file=filename)
open (33,file=filename_new)
stat2=0
do while (stat2==0)
read (22,*,iostat=stat2) time_all_1,pwv_mm_1,yr_1,dayofyear_1,hr_1
read (22,*,iostat=stat2) time_all_2,pwv_mm_2,yr_2,dayofyear_2,hr_2
if (stat2 /= 0 ) exit
backspace (22)
if (yr_1 == yr_2) then
write (33,100) time_all_1,pwv_mm_1,yr_1,dayofyear_1,hr_1
100 format(f12.7,3x,f12.7,3x,i4.4,3x,i3.3,3x,i2.2)
else !( yr_1 /= yr_2 )
write (33,150) time_all_1,pwv_mm_1,yr_1,dayofyear_1,hr_1
150 format (f12.7,3x,f12.7,3x,i4.4,3x,i3.3,3x,i2.2)
fake=1D0
!------------------------------------> part 1
yr=yr_1
call determine1 (yr,Days_Of_Year)
m=0
n=0
do while (.true.)
m=m+1
if (m==1) then
dayofyear=dayofyear_1
dayofyear=dayofyear+1
else ! m>1
dayofyear=dayofyear+1
end if
if (dayofyear > Days_Of_Year ) exit
hr=-2
do while (.true.)
n=n+1
if (n==1) then
hr=hr_1
hr=hr+2
else ! n>1
hr=hr+2
end if
if (hr==24) exit
call convertday (yr,hr,dayofyear,timeall)
write(33,200) timeall,fake,yr,dayofyear,hr
200 format(f12.7,3x,f12.7,3x,i4.4,3x,i3.3,3x,i2.2)
end do
end do
!------------------------------------> part 1
!------------------------------------> part 2
if (yr_2-yr_1 > 1) then
yr=yr_1
do while (.true.)
yr=yr+1
if (yr==yr_2) exit
call determine1 (yr,Days_Of_Year)
dayofyear=0
do while (.true.)
dayofyear=dayofyear+1
if (dayofyear > Days_Of_Year) exit
hr=-2
do while (.true.)
hr=hr+2
if (hr==24) exit
call convertday (yr,hr,dayofyear,timeall)
write (33,250) timeall,fake,yr,dayofyear,hr
250 format (f12.7,3x,f12.7,3x,i4.4,3x,i3.3,3x,i2.2)
end do
end do
end do
end if
!------------------------------------> part 2
!------------------------------------> part 3
yr=yr_2
dayofyear=0
do while (.true.)
dayofyear=dayofyear+1
if (dayofyear > dayofyear_2) exit
hr=-2
do while (.true.)
hr=hr+2
if (hr==24) exit
if (dayofyear == dayofyear_2 .and. hr == hr_2) exit
call convertday (yr,hr,dayofyear,timeall)
write (33,300) timeall,fake,yr,dayofyear,hr
300 format (f12.7,3x,f12.7,3x,i4.4,3x,i3.3,3x,i2.2)
end do
end do
!------------------------------------> part 3
write (33,350) time_all_2,pwv_mm_2,yr_2,dayofyear_2,hr_2
350 format (f12.7,3x,f12.7,3x,i4.4,3x,i3.3,3x,i2.2)
end if
end do
end do
end program
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine determine1 (yr,Days_Of_Year)
integer :: yr,Days_Of_Year
if (MOD(yr,4)==0 .and. MOD(yr,100)/=0) then
Days_Of_Year = 366
else if(MOD(yr,4)==0 .and. MOD(yr,100)==0 .and. MOD(yr,400)==0) then
Days_Of_Year = 366
else !(MOD(yr,4)==0 .and. MOD(yr,100)==0 .and. MOD(yr,400)/=0) then
Days_Of_Year = 365
end if
end subroutine
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine convertday (yr,hr,dayofyear,timeall)
integer :: yr,hr,dayofyear
real*8 :: timeall
integer :: Days_Of_Year
! DAY_OF_MONTH = (/31,28,31,30,31,30,31,31,30,31,30,31/)
if (MOD(yr,4)==0 .and. MOD(yr,100)/=0) then
! DAY_OF_MONTH(2) = 29
Days_Of_Year = 366
else if(MOD(yr,4)==0 .and. MOD(yr,100)==0 .and. MOD(yr,400)==0) then
! DAY_OF_MONTH(2) = 29
Days_Of_Year = 366
else !(MOD(yr,4)==0 .and. MOD(yr,100)==0 .and. MOD(yr,400)/=0) then
Days_Of_Year = 365
end if
! if ( mon > 1 ) then
! dayofyear = day + sum( DAY_OF_MONTH(1:mon-1) )
! else
! dayofyear = day
! end if
timeall = yr*1.0D0+(dayofyear-0.99D0)/Days_Of_Year + 1.0D0*hr/(Days_Of_Year*24.0D0)
end subroutine