GetDateInt8
— Returns a new date/time from an initial date/time and offset
This subroutine returns a new date and time in yyyymmdd and hhmmss format given and initial date, time, and offset in seconds. The routine converts the input date and time to julian seconds, adds the offset, and converts back to yyyymmdd and hhmmss format. This routine has been tested for Y2K compiance.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer | :: | yyyymmdd_1 |
Initial date in YYYYYMMDD format |
|||
integer | :: | hhmmss_1 |
Initial time in HHMMSS format |
|||
integer(kind=INT64) | :: | offset |
Offset to add (in seconds) |
|||
integer | :: | yyyymmdd_2 |
New date in YYYYMMDD format |
|||
integer | :: | hhmmss_2 |
New time in HHMMSS format |
|||
integer | :: | rc |
Return code. (<0 = error) |
subroutine GetDateInt8 (yyyymmdd_1,hhmmss_1,offset, & yyyymmdd_2,hhmmss_2,rc) implicit none ! ! !INPUT PARAMETERS: ! integer yyyymmdd_1 !! Initial date in YYYYYMMDD format integer hhmmss_1 !! Initial time in HHMMSS format integer(kind=INT64) offset !! Offset to add (in seconds) ! ! !OUTPUT PARAMETERS: ! integer yyyymmdd_2 !! New date in YYYYMMDD format integer hhmmss_2 !! New time in HHMMSS format integer rc !! Return code. (<0 = error) ! !------------------------------------------------------------------------- integer year1,mon1,day1,hour1,min1,sec1 integer year2,mon2,day2,hour2,min2,sec2 integer(kind=INT64) julian1 integer(kind=INT64) julsec, remainder !character(len=8) dateString ! Error checking. if (yyyymmdd_1 .lt. 19000000 .or. yyyymmdd_1 .gt. 21000000 ) then rc=-1 return endif if (hhmmss_1 .lt. 0 .or. hhmmss_1 .ge. 240000 ) then rc=-1 return endif ! Convert Date/Time strings to integer variables. !ams write (dateString, 200) yyyymmdd_1 !ams 200 format (I8) !ams read (dateString, 201) year1, mon1, day1 !ams 201 format (I4,2I2) !ams write (dateString, 202) hhmmss_1 !ams 202 format (I6) !ams read (dateString, 203) hour1, min1, sec1 !ams 203 format (3I2) call CFIO_parseIntTime ( yyyymmdd_1, year1, mon1, day1 ) call CFIO_parseIntTime ( hhmmss_1, hour1, min1, sec1 ) ! Get Julian Day and subtract off a constant (Julian days since 7/14/66) julian1 = julday (mon1, day1, year1) ! Calculcate Julian seconds julsec = (julian1-1)*86400 + hour1*3600 + min1*60 + sec1 ! Add offset and calculate new julian day. julsec = julsec + offset julian1 = INT(julsec/86400) + 1 remainder = MOD(julsec,86400_INT64) ! Convert julian day to YYYYMMDD. call caldat (julian1, mon2, day2, year2) ! Calculate HHMMSS from the remainder. hour2 = INT(remainder/3600) remainder = MOD(remainder,3600_INT64) min2 = INT(remainder/60) sec2 = MOD(remainder,60_INT64) ! Build YYYYMMDD and HHMMSS variables. yyyymmdd_2 = year2*10000 + mon2*100 + day2 hhmmss_2 = hour2*10000 + min2*100 + sec2 rc = 0 return end subroutine GetDateInt8