function intextime,days79,msecday
;+
; INTEXTIME v1.6 (IDL2)
;
;   Convert bda time from internal format 
;   to bsdtime format.
;   particularly useful for arrays of times to be converted, as 
;   it is considerably faster than int2ex.(factor 10) For scalars use int2ex.
;
; author:	Andy Phillips, MSSL 1991
; in:		days79   (array)   - days since 1979.0
;		msecday  (array)   - milliseconds of day
; out:		bsdtime    - 7 element lonarr time in format 
;			     hh mm ss msec dd mm yy
;
; syntax:  	time = intextime(days79,msecday)
;
; history:
;	v0.1 atp translation of RLSAC::MKC 's FORTRAN code 
;		 intext.for .
;	v0.9 atp release, cleaned up code a little.
;       v1.2 atp changed to do all at once.
;       v1.4 atp bugfix for leap year month handler.
;       v1.5 atp 20/3/92 changed to std ext time format.
;	v1.6 atp 27/6/92 changed to accept any sort of datatype
;
; notes:
;	no error checking is done on the time,
;	it is entirely possible to return an impossible time.
;       accepts an array, much faster.
;
;-
; declare variables
;
  msecday = long(msecday)
  days79  = long(days79)
;
  nent = n_elements(days79)
  bsdtime = lonarr(7,nent);
  mins = 0;
  secs = 0;
  ehrs = 0;
  emns = 0;
  escs = 0;
  emss = 0;
  edys = 0;
  emhs = intarr(nent);
  eyrs = intarr(nent);
  quit = 0;
;
; declare months array.
;          j  f  m  a  m  j  j  a  s  o  n  d
  month = [31,28,31,30,31,30,31,31,30,31,30,31]
;
; convert msecday to hrs mins secs + msecs
;
  secs = msecday/1000
  mins = secs/60
  ehrs = mins/60
  emns = mins - (ehrs*60)
  escs = secs - (mins*60)
  emss = msecday - (secs*1000)
;
; convert into date including leap yrs.
;
  eyrs(*) = 79
  edys = days79
  quit = 0
  while (quit eq 0) do begin

   alph = ((eyrs mod 4) eq 0)
   beta = ((edys - (alph + 365)) > 0) ge 1
  
   if (Total(beta) eq 0) then quit = 1
   
   eyrs = eyrs + beta
   edys = edys - beta*(alph + 365)
   endwhile

;
; set days in february, and do months
; 
  alph = ((eyrs mod 4) eq 0); /* this is a leap year */
  mnth = 0;
  emhs(*) = 0; /* conclusive proof that the calendar was designed by a 
  quit = 0;     * fortran nut, as everyone really knows january is month zero..*/

  while (quit eq 0) do begin
 
    beta = edys - month(mnth)
    if (mnth eq 1) then beta = beta - alph; leap year
    gamm = (beta > 0) ge 1
    if (total(gamm) eq 0) then quit = 1
    emhs = emhs + gamm
    edys = edys - gamm * (month(mnth)+(alph*(mnth eq 1))); /* only add 4 feb */
    mnth = mnth + 1
    endwhile

  emhs = emhs + 1;
;
; construct output array.
;
  bsdtime = [[ehrs],[emns],[escs],[emss],[edys],[emhs],[eyrs]]
  bsdtime = transpose(bsdtime); same format as before (date,ndset)
  bsdtime = long(bsdtime)
;
; This is where MKC checks the time. and I don't.
;
; Return, and Terminate
;  
  return,bsdtime

end
