      subroutine dtcvt(yyyy,ddd,hh,mm,ss,string)

C Normalizes  date-time  yyyy, dd, hh, mm, ss  if any value is out of range (too large).
C Converts to  YYYY-MM-DDThh:mm:ss  in 19-character string.  Valid for non-leap-years.

      integer*4     yyyy, ddd    ! year and day-of-year
      integer*4     hh, mm, ss   ! hours, minutes, seconds
      integer*4     mon,dd       ! month and day-of-month
      integer*4     i            ! miscellaneous index
      character*19  string       ! YYYY-MM-DDThh:mm:ss (PDS date-time format)

      integer*4     dom(12)      ! days in months


C Initializations for non-leap year

      dom(01) = 31
      dom(02) = 28
      dom(03) = 31
      dom(04) = 30
      dom(05) = 31
      dom(06) = 30
      dom(07) = 31
      dom(08) = 31
      dom(09) = 30
      dom(10) = 31
      dom(11) = 30
      dom(12) = 31


C Begin normalization, if needed

 10   continue
      if (ss .gt. 59) then
        ss = ss - 60
        mm = mm + 1
        go to 10
      else if (ss .lt. 00) then
        ss = ss + 60
        mm = mm - 1
        go to 10
      end if

 20   continue
      if (mm .gt. 59) then
        mm = mm - 60
        hh = hh + 1
        go to 20
      else if (mm .lt. 00) then
        mm = mm + 60
        hh = hh - 1
        go to 20
      end if

 30   continue
      if (hh .gt. 23) then
        hh = hh - 24
        ddd = ddd + 1
        go to 30
      else if (hh .lt. 00) then
        hh = hh + 24
        ddd = ddd - 1
        go to 30
      end if

 40   continue

      if (ddd .gt. 365) then
        if (mod(yyyy,004) .eq. 0) then
          if ((mod(yyyy,100) .ne. 0) .or.
     *        (mod(yyyy,400) .eq. 0)) then
                if (ddd. gt. 366) then
                  ddd = ddd - 366
                  yyyy = yyyy + 1
                  go to 40
                end if
          end if
        else
          ddd = ddd - 365
          yyyy = yyyy + 1
          go to 40
        end if
      end if

      if (ddd .lt. 001) then
        if (mod(yyyy-1,004) .eq. 0) then
          if ((mod(yyyy-1,100) .ne. 0) .or.
     *        (mod(yyyy-1,400) .eq. 0)) then
                ddd = ddd + 366
                yyyy = yyyy - 1
                go to 40
          end if
        else
          ddd = ddd + 365
          yyyy = yyyy - 1
          go to 40
        end if
      end if


C Convert day-of-year to months and days

      if (mod(yyyy,004) .eq. 0) then
        if ((mod(yyyy,100) .ne. 0) .or.
     *      (mod(yyyy,400) .eq. 0)) then
              dom(02) = 29
        end if
      end if

      i = 1
      dd = ddd
      mon = 01
 60   continue
      if (dd .gt. dom(i)) then
        dd = dd - dom(i)
        mon = mon + 1
        i = i + 1
        go to 60
      end if

      write(string(01:19),'(i4.4,2("-",i2.2),"T",2(i2.2,":"),i2.2)')
     *    yyyy,mon,dd,hh,mm,ss


      return
      end
