get_DDMonYYTimeZone Subroutine

public subroutine get_DDMonYYTimeZone(dt_time)

Routine to get date, time and timezone author: M Kumar, CCFE, Culham Science Centre dt_time : output string : String containing formatted time and date This routine calls the intrinsic DATE_AND_TIME subroutine and format the output in DD Mon YYYY hr:minute:second time difference from UTC.

Arguments

Type IntentOptional AttributesName
character(len=*), intent(out) :: dt_time

Contents

Source Code


Source Code

subroutine get_DDMonYYTimeZone(dt_time)
  !! Routine to get date, time and timezone
  !! author: M Kumar, CCFE, Culham Science Centre
  !! dt_time : output string  : String containing formatted time and date
  !! This routine calls the intrinsic DATE_AND_TIME subroutine
  !! and format the output in
  !! DD Mon YYYY hr:minute:second time difference from UTC.

! Arguments
    CHARACTER(len = *), INTENT(OUT) :: dt_time
! Local variables
    INTEGER :: values(8)
    CHARACTER(len = 1), parameter :: tspt = ":"
    CHARACTER(len = 1), parameter :: spspt = " "

    CHARACTER(len = 2)  :: dd
    CHARACTER(len = 5)  :: mons(12)
    CHARACTER(len = 4)  :: yyyy
    CHARACTER(len = 2)  :: hr    ! Hour of the day
    CHARACTER(len = 2)  :: mnt   ! Minute of the hour
    CHARACTER(len = 2)  :: scnd  ! The seconds of the minute
    CHARACTER(len = 5)  :: zn    ! In form (+-)hhmm, representing the difference with respect to Coordinated Universal Time (UTC).
    CHARACTER(len = 20) :: znfrmt

    mons = [' Jan ',' Feb ',' Mar ',' Apr ',' May ',' Jun ',&
      ' Jul ',' Aug ',' Sep ',' Oct ',' Nov ',' Dec ']

    CALL DATE_AND_TIME(ZONE = zn, VALUES = values)
    znfrmt = zn(1:3)//":"//zn(4:5)//"(hh:mm) UTC"
    znfrmt = trim(znfrmt)
    WRITE(  dd,'(i2)') values(3)
    WRITE(yyyy,'(i4)') values(1)
    write(hr, '(i2)')  values(5)
    write(mnt, '(i2)')  values(6)
    write(scnd, '(i2)')  values(7)
    if(mnt(1:1) == " ")   mnt(1:1) = "0"
    if(scnd(1:1) == " ") scnd(1:1) = "0"

    dt_time = dd//mons(values(2))//yyyy//spspt// &
             hr//tspt//mnt//tspt//scnd//spspt//znfrmt
    dt_time = trim(dt_time)

  END subroutine get_DDMonYYTimeZone