bas_to_date(3f) - [M_time:BAS] converts a BAS(Baseday and Seconds) to a DAT date-time array. (LICENSE:MIT)
Synopsis
Description
Options
Returns
Example
Author
License
subroutine bas_to_date(bas,dat,ierr)
type(BAStime),intent(in) :: bas integer,intent(out) :: dat(8) integer,intent(out) :: ierr
Converts a Baseday and Seconds(BAS) value to a DAT date-time array.In this module the MJD date and time is stored internally as a structure named BAStime, containing the number of days since the beginning of the MJD Epoch and a double representing the seconds offset from the start of this day.
type BAStime integer :: base_day ! number of days since the MJD Epoch date real(kind=real64) :: secs ! seconds from start of base_day end type BAStimeA Modified Julian Date (MJD) measures days (and fractional days) since the start of 17 Nov 1858 CE in Universal Time (UTC).
A Julian Date (JD) measures days (and fractional days) since noon on 1 January, 4713 BCE in Universal Time (UTC).
That is,
Julian Date (MJD) = Julian Date (JD) - 2400000.5Using a structure allows for storing a date at a higher precision that other formats used by the library, although sometimes that lower precision is limited primarily by the definition (ie. the milliseconds in a DAT could be smaller units).
MJD starts at midnight (00:00:00) so truncating the fractional component of MJD always gives the same Civil Calendar day whatever the time of day (unlike JD).
The seconds offset may take any double-precision value, so that any date/time may be expressed in terms of an offset from the same MJD day. The seconds field thus may exceed a single day, and may also be negative.
bas A Baseday and Seconds (BAS) measures days since the start of 17 Nov 1858 CE in Universal Time (UTC) and contains an offset value in seconds from that base date.
dat Integer array holding a "DAT" array, similar in structure to the array returned by the intrinsic DATE_AND_TIME(3f): dat=[ year,month,day,timezone,hour,& & minutes,seconds,milliseconds]
ierr | Error code. If 0 no error occurred. |
Sample program:
program demo_bas_to_date use M_time, only : bas_to_date, fmtdate, realtime, BAStime implicit none integer,parameter :: dp=kind(0.0d0) type(BAStime) :: bas, tomorrow, yesterday integer :: dat(8) integer :: ierr character(len=*),parameter :: g=(*(g0,1x)) write(*,g)bas_to_date: ! set sample Baseday and Seconds date bas=BAStime( 60700, 0.213682349771_dp) ! create DAT array for this date call bas_to_date(bas,dat,ierr) write(*,g)Sample Date=,fmtdate(dat) ! write(*,g)add and subtract days from base_day: ! go back one day yesterday= BAStime(bas%base_day-1,bas%secs) call bas_to_date(yesterday,dat,ierr) write(*,g)Day Before =,fmtdate(dat) ! ! go forward one day tomorrow= BAStime(bas%base_day+1,bas%secs) call bas_to_date(tomorrow,dat,ierr) write(*,g)Day After =,fmtdate(dat)Results:write(*,g)add and subtract seconds from BAS: ! go back one day yesterday=bas-86400 call bas_to_date(yesterday,dat,ierr) write(*,g)Day Before =,fmtdate(dat) ! ! go forward one day yesterday=bas+86400 call bas_to_date(tomorrow,dat,ierr) write(*,g)Day After =,fmtdate(dat) ! end program demo_bas_to_date
> bas_to_date: > Sample Date= Friday, January 24th, 2025 7:00:00 PM UTC-05:00 > add and subtract days from base_day: > Day Before = Thursday, January 23rd, 2025 7:00:00 PM UTC-05:00 > Day After = Saturday, January 25th, 2025 7:00:00 PM UTC-05:00 > add and subtract seconds from BAS: > Day Before = Thursday, January 23rd, 2025 7:00:00 PM UTC-05:00 > Day After = Saturday, January 25th, 2025 7:00:00 PM UTC-05:00
John S. Urban, 2025
Nemo Release 3.1 | bas_to_date (3) | February 23, 2025 |