SUB_WAVELET/Fortran/SUB_Date_to_Num.f90
2025-04-17 11:06:03 +08:00

59 lines
1.5 KiB
Fortran
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

!日期转为数值与matlab中Datenum函数相同
subroutine Date_to_Num(date,N,OutLine)
implicit none
integer :: date(1000,5)
integer :: N
real*8 :: OutLine(1000)
real*8 :: day1(1000),day2(1000),day3(1000),day4(1000)
real*8 :: day(1000)
integer :: i
day1 = 0
day2 = 0
day3 = 0
day4 = 0
day = 0
day1 = int((date(:,1)-1)/400) !400年个数146097
day2 = int(((date(:,1)-1)-day1*400)/100) !剩余100年的个数
day3 = int(((date(:,1)-1)-day1*400-day2*100)/4) !剩余4年的个数
day4 = int((date(:,1)-1)-day1*400-day2*100-day3*4) !剩余1年的个数
day = 366+day1*146097+day2*36524+day3*1461+day4*365
do i=1,N
select case(date(i,2))
case(2)
day(i) = day(i)+31
case(3)
day(i) = day(i)+59
case(4)
day(i) = day(i)+90
case(5)
day(i) = day(i)+120
case(6)
day(i) = day(i)+151
case(7)
day(i) = day(i)+181
case(8)
day(i) = day(i)+212
case(9)
day(i) = day(i)+243
case(10)
day(i) = day(i)+273
case(11)
day(i) = day(i)+304
case(12)
day(i) = day(i)+334
end select
if(day4(i)==3.and.(.not.(day3(i)==24.and.day2(i)/=3)).and.date(i,2)>2) then
day(i) = day(i)+1
end if
end do
day = day+date(:,3)+date(:,4)/24.0+date(:,5)/1440.0
day(N+1:) = 0.0
OutLine = day
end subroutine