module mod_year_info implicit none type year_info integer iyy ! year integer imm ! month integer idd ! day in year integer ihh ! hours integer iss ! seconds integer idm ! current day in month (1st day = 0 ) character(len=4) cyy ! year nr (char) character(len=2) cmm ! month nr (char) character(len=3) cdd ! day in year (char) character(len=2) chh ! hour nr (char) character(len=4) css ! second nr (char) character(len=3) month ! month 'JAN' etc character(len=2) cdm ! current day in month (char) character(len=8) cdate ! current date (yyyymmdd format) character(len=8) ctime ! current time (HH:MM:SS format) integer totdim(12) ! total Days In Months integer daysinyear ! total Days In year end type year_info integer, dimension(12),parameter :: months_standard = & (/31,28,31,30,31,30,31,31,30,31,30,31/) integer, dimension(12),parameter :: months_leapyear = & (/31,29,31,30,31,30,31,31,30,31,30,31/) integer, dimension(12),parameter :: months_360 = & (/30,30,30,30,30,30,30,30,30,30,30,30/) integer, dimension(12),parameter :: months_365 = & (/31,28,31,30,31,30,31,31,30,31,30,31/) integer, dimension(12),parameter :: months_366 = & (/31,29,31,30,31,30,31,31,30,31,30,31/) integer, save :: refyear ! Reference year ! integer, save :: hrefyear ! hycoms reference year ! real , save :: juld_offset! Offset between reference year and hycom reference year ! real , save :: juld1 ! Julian day of start of run rel hycom reference year ! real , save :: juld2 ! Julian day of end of run rel hycom reference year type(year_info), save :: rt real*8, save :: dtime_start contains subroutine year_day(dtime,refyear,tt,yrflag,refflag) implicit none ! Calculates current day and year knowing that ! 1992 was skuddaar, using model day (dtime) and ! model refyear. real*8, intent(in) :: dtime integer, intent(in) :: refyear !character(len=5), intent(in) :: rforce type(year_info), intent(out) :: tt integer, intent(in) :: yrflag logical, optional :: refflag ! if true, dtime is rel 1.1 of refyear integer days,days_in_year,i integer days_in_month(12) integer ttday,iyear, iday, ihour,imins integer*8 :: iss logical refflag2 real*8 dtime2 character(len=2) :: tmpc refflag2=.false. if (present(refflag)) refflag2=refflag ! Follow hycoms time convention if (refflag2) then call dayfor(dtime2,yrflag,refyear,1,0) dtime2=dtime+dtime2 else call forday(dtime,yrflag,iyear,iday,ihour) dtime2=dtime end if call forday(dtime2,yrflag,iyear,iday,ihour) iday = iday - 1 ! hycom starts at 1 - we start at 0 days_in_year =daysinyear (iyear,yrflag) days_in_month=monthsofyear(iyear,yrflag) tt%totdim=days_in_month iss=nint(((dtime2-floor(dtime2))*24.0d0 - ihour)*3600.0d0 ) tt%iyy=iyear tt%idd=iday tt%ihh=ihour tt%iss=iss write(tt%cyy,'(i4.4)')tt%iyy write(tt%cdd,'(i3.3)')tt%idd write(tt%chh,'(i2.2)')tt%ihh write(tt%css,'(i4.4)')tt%iss ttday=tt%idd do i=1,12 if (ttday >= days_in_month(i)) then ttday=ttday-days_in_month(i) else tt%imm=i write(tt%cmm,'(i2.2)')tt%imm tt%idm=ttday write(tt%cdm,'(i2.2)')ttday exit endif enddo !! calendar date: has most meaning if yrflag==3, !! but still works for other values of yrflag write(tmpc,'(i2.2)')tt%idm+1 tt%cdate = tt%cyy//tt%cmm//tmpc imins = tt%iss/60!mins write(tmpc,'(i2.2)')imins tt%ctime(1:5) = tt%chh//':'//tmpc!HH:MM write(tmpc,'(i2.2)')(tt%iss-60*imins) tt%ctime(6:8) = ':'//tmpc!HH:MM:SS select case (tt%imm) case (1) tt%month='JAN' case (2) tt%month='FEB' case (3) tt%month='MAR' case (4) tt%month='APR' case (5) tt%month='MAY' case (6) tt%month='JUN' case (7) tt%month='JUL' case (8) tt%month='AUG' case (9) tt%month='SEP' case (10) tt%month='OCT' case (11) tt%month='NOV' case (12) tt%month='DEC' end select tt%daysinyear=days_in_year end subroutine year_day ! integer function daysinyear(year,rforce) ! implicit none ! integer,intent(in) :: year ! character(len=5),intent(in) :: rforce ! ! If year is undivisible by 4, or if year is divisible by 100 and is ! ! undivisible by 400 (e.g. 1900), THEN year is not a leapyear ! if (mod(year,4)/=0 .or. (mod(year,100)==0.and.mod(year,400)/=0)) then ! daysinyear=365 ! else ! daysinyear=366 ! end if ! if (trim(rforce) == 'month') daysinyear = 360 ! end function daysinyear integer function daysinyear(year,yrflag) implicit none integer,intent(in) :: year,yrflag if (yrflag==0) then daysinyear=360 elseif (yrflag==1) then daysinyear=365 elseif (yrflag==2) then daysinyear=366 elseif (yrflag==3) then if (mod(year,4)/=0 .or. (mod(year,100)==0.and.mod(year,400)/=0)) then daysinyear=365 else daysinyear=366 end if end if end function daysinyear integer function datetojulian(year,month,day,ryear,rmonth,rday) implicit none integer, intent(in) :: year,month,day,ryear,rmonth,rday integer :: iyear,sum_days,months(12) sum_days=0 do iyear=ryear,year sum_days=sum_days+dayinyear(iyear) !print *,sum_days enddo ! Subtract from start of ref year to reference date months=monthsofyear(ryear,3) sum_days=sum_days & - sum(months(1:rmonth)) & + months(rmonth) - rday + 1 !print *,sum_days ! Subtract from end date in last year to end of year months=monthsofyear(year,3) sum_days=sum_days & - sum(months(month:12)) & + day -1 !print *,sum_days datetojulian=sum_days end function datetojulian subroutine juliantodate(jday,year,month,day,ryear,rmonth,rday) implicit none integer, intent(in) :: jday,ryear,rmonth,rday integer, intent(out):: year,month,day integer :: iyear,sum_days,months(12),imonth,iday sum_days=0 ! Subtract from start of ref year to reference date sum_days=sum_days+dayinyear(ryear) !print *,sum_days months=monthsofyear(ryear,3) sum_days=sum_days & - sum(months(1:rmonth)) & + months(rmonth) - rday + 1 !print *,sum_days ! Add years until beyond julian day iyear=ryear+1 do while (sum_daysjday) then iyear=iyear-1 end if imonth=12 months=monthsofyear(iyear,3) do while (sum_days>jday) sum_days=sum_days-months(imonth) !print *,sum_days imonth=imonth-1 enddo imonth=mod(imonth,12)+1 iday=1 do while (sum_days