pro fixhk,dummy
;
;   reads in all hk files one at a time and writes them out such
;   that the information is on hour boundaries.
;
; @(#)fixhk.pro	1.2 01/23/98 :LASCO IDL LIBRARY
;
f=findfile('LASHK93123*')
g=sort(f)
nb = 157		; number of words per packet
n = n_elements(f)
nf = 0
get_lun,luin 
get_lun,luout
hh = -1			; initialize
lastday = -1
repeat begin
    inname = f(g(nf))
    print,'Input file = '+inname
    openr,luin,inname
    a = assoc(luin,intarr(nb))
    recin = 0
    while not eof(luin) do begin
       b = a(recin)
       if ((b(2) ne lastday) or (b(3) ne hh)) then begin
          if hh ge 0 then begin
	     print,'   Closing file after ',recout,' records'
             close,luout
          endif
          kday,1,1,b(1),kd
          kd = kd+b(2)
          kdate,kd,dd,mm,yy
          hh = b(3)
          lastday = b(2)
          outname = string(yy,mm,dd,hh,format='("LASHK",3i2.2,"_",i2.2,".rsim")')
          print,'Creating file '+outname
          recout = 0
          openw,luout,outname
          aa=assoc(luout,intarr(nb))
       endif
       aa(recout) = b
       recin = recin+1
       recout = recout+1
    endwhile
    close,luin
    nf = nf+1
endrep until n eq nf
close,luout
free_lun,luin
free_lun,luout
return
end
