;+
; NAME:
;     GET_DUT
; PURPOSE:
;     Return the time difference DUT = UT1-UTC for a given Julian date.
; CATEGORY:
;     OVRO APC EPHEMERIS
; CALLING SEQUENCE:
;     dut = get_dut(jd)
; INPUTS:
;     jd      Julian date of the day for which the DUT is wanted.
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; ROUTINES CALLED:
; OUTPUTS:
;     dut     UT1-UTC [msec]
; COMMENTS:
;   Requires the file !DEFAULTS.EPHEMIR+'DUT.USN', which is to be FTP'd
;   weekly from ftp://maia.usno.navy.mil/ser7/ser7.dat.  This is
;   done with the !DEFAULTS.CMDDIR+'NEWDUT.BAT' file.
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     Written 12-Jan-1999 by Dale E. Gary
;     11-Jan-2000  DG
;       Eliminated hardwired directory locations
;-

function get_dut,jd

   ; Open the IERS-A file (obtained from
   ;        ftp://maia.usno.navy.mil/ser7/ser7.dat)
   openr,/get_lun,lun,!defaults.ephemdir+'dut.usn'
   line = ''

   ON_IOERROR,bail

   ; Read a data line
   readf,lun,line

   ; Loop until Julian date is found
   mjdstr = string(long(jd-2400000.D),format='(I5)')
   while (strmid(line,19,5) ne mjdstr) do begin
      readf,lun,line
   endwhile

   ; Found the appropriate line, so extract DUT from it
   junk = fltarr(6)
   reads,line,junk,dut

   ; Close the file and free the logical unit number
   free_lun,lun
   return,fix(dut*1000.)
bail:
   return,-1
end
