C Library Functions  - date_to_bas (3)

NAME

date_to_bas(3f) - [M_time:BAS] converts DAT date-time array to Baseday and Seconds (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Returns
Example
Author
License

SYNOPSIS

subroutine date_to_bas(dat,bas,ierr)

    integer,intent(in)        :: dat(8)
    type(BAStime),intent(out) :: bas
    integer,intent(out)       :: ierr

DESCRIPTION

Converts a DAT date-time array to a Baseday and Seconds type.

In this module the BAS 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 BAStime

Modified Julian Date (MJD) measures days (and fractional days) since the start of 17 Nov 1858 CE in Universal Time (UTC). Put another way

       Modified Julian Date (MJD) = Julian Date (JD) - 2400000.5

This allows for storing a date at a higher precision that the 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).

BAS (and MJD) starts at midnight (00:00:00) so truncating the fractional component of BAS 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. Note that in floating-point math larger numbers will have a wider spacing between representable values, possibly decreasing the precision of results.

OPTIONS

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]

RETURNS

bas A Baseday and Seconds variable representing the date and time found in the DAT array
ierr Error code. If 0 no error occurred.

EXAMPLE

Sample Program:

    program demo_date_to_bas
    use M_time, only : date_to_bas, realtime, BAStime
    use M_time, only : date_to_julian
    implicit none
    integer                    :: dat(8)
    type(BAStime)              :: bas
    real(kind=realtime)        :: juliandate
    integer                    :: ierr
    character(len=*),parameter :: g=’(*(g0,1x))’
       !
       write(*,g)’date_to_bas:’
       ! generate DAT array
       call date_and_time(values=dat)
       !
       ! show DAT array
       write(*,’("Today is:",*(i0:,":"))’)dat
       !
       ! convert DAT to Julian
       call date_to_julian(dat,juliandate,ierr)
       ! show as Modified Julian Date
       write(*,g) ’Expecting Modified Julian Date:’, &
       & juliandate - 2400000.5_realtime
       !
       ! convert DAT to BAS
       call date_to_bas(dat,bas,ierr)
       write(*,g)’Baseday and Seconds is ’, bas
       write(*,g)’converted to Modified Julian Date:’, &
       & bas%base_day +  bas%secs/86400.0d0

end program demo_date_to_bas

Results:

    > date_to_bas:
    > Today is:2025:1:26:-300:1:9:0:914
    > Expecting Modified Julian Date: 60701.256260578521
    > Baseday and Seconds is  60701 22140.913984179497
    > converted to Modified Julian Date: 60701.256260578521

AUTHOR

John S. Urban, 2025

LICENSE

    MIT


Nemo Release 3.1 date_to_bas (3) February 23, 2025
Generated by manServer 1.08 from 42b5d5a4-2094-4733-a585-fd433667f2b7 using man macros.