	program GetSIDEHKs
c get SIDE house keeping
c **16-Oct-18**
	character filen*30,stdy*6,cr*1,tf*1,df(2)*1,time*21
	integer*2 in(13,128)
	integer ifc(2),idt(2),kv(2),kt(2),sf(4)
	logical first,badt
	parameter (cr='0d'x)
	data ifc/70,85/,filen/'a17_side_1975_l1_arcsav_hk.tab'/
&	,time(1:15)/'1975-***T**:**:'/,stdy(3:3)/'.'/
c
	do j=1,2
	 idt(j)=nint(((ifc(j)-70)*64+32)*9.4336)
	 end do
	write(*,"('station: '$)")
	read(*,'(a2)') stdy(1:2)
	filen(2:3)=stdy(1:2)
	open(7,file='../sidel1aPDSs/'//filen)
	write(7,1) 
&	'year-dayThr:mn:sc.ms  f stat',1,2,cr,'time+ms  |    x',idt,cr
1	format(a28,2(' AI-',i1,' f'),a1/13xa15,2(i5,' |'),a1)
	idts=0
	do i=1,2
	 kv(i)=-9
	 df(i)='-'
	 end do
	first=.true.
	write(*,"('days: '$)")
	read(*,*) id1,id2
	do id=id1,id2
	 write(stdy(4:6),'(i3)') id
	 if (stdy(4:4).eq.' ') stdy(4:4)='0'
	 open(1,file='../sidel1b'//stdy(1:2)//'s/sidel1b.'//stdy
&	 ,access='direct',form='unformatted',recl=3328,status='old',err=29)
	 write(*,*) stdy
	 nr=1
10	 read(1,rec=nr,end=19) in
	 do k=1,128
	  if (in(1,k).eq.0) go to 17
c get frame count
	  kfc=and(in(6,k),'7f'x)
	  do j=1,2
	   if (kfc.eq.ifc(j)) go to 12
	   end do
	  go to 17
12	  in2=in(2,k)
	  in3=in(3,k)
	  in4=in(4,k)
	  in5=in(5,k)
	  in6=in(6,k)
	  ksyn=or(and(lshift(in5,8),'3fff00'x),and(rshift(in6,8),'ff'x))
	  if (ksyn.ne.'3890ed'x.or.and(in(7,k),'8000'x).ne.0) then
	   if(kfc.ne.nfc) then
	    nfc=mod(nfc+1,90)
	    go to 18
	    end if
	   end if
c get time/16 and write out if passed current range
	  if (and(in2,8).eq.0) then
	   ktt=or(or(and(lshift(in2,28),'70000000'x)
&	   ,and(lshift(in3,12),'ffff000'x)),and(rshift(in4,4),'fff'x))
	   badt=iabs(ktt-lit).gt.5400000
	   if (first.or.ktt.lt.lit.or.(badt.and.nr.ne.1)) go to 15
	  else
	   if (idt(j).gt.idts) go to 15
	   go to 18
	   end if
	  write(7,'(a21,1xa1,1x4i1,2(i5,1xa1),a1)')
&	   time,tf,sf,(kv(i),df(i),i=1,2),cr
	  first=.true.
	  do i=1,2
	   kv(i)=-9
	   df(i)='-'
	   end do
15	  if (first) then
c get full time
	   idts=idt(j)
	   tf='-'
	   if (and(in2,'4008'x).ne.0) tf='*'
           kt(1)=or(and(lshift(in2,16),'70000'x)
&          ,and(in(3,k),'ffff'x))
           kt(2)=and(in4,'ffff'x)-idt(j)+302
           if (kt(2).lt.0) then
            kt(2)=and(kt(2),'ffff'x)
            kt(1)=kt(1)-1
            end if                 
	   it=or(or(and(lshift(in2,28),'70000000'x)
&	   ,and(lshift(in3,12),'ffff000'x)),and(rshift(in4,4),'fff'x))
	   lit=it+3396
	   kd=it/5400000
	   it=mod(it,5400000)
	   kh=it/225000
	   it=mod(it,225000)
	   km=it/3750
	   sec=(mod(it,3750)*16+and(kt(2),15))/1000.
	   write(time(6:8),'(i3)') kd
	   if (time(6:6).eq.' ') time(6:6)='0'
	   if (time(7:7).eq.' ') time(7:7)='0'
	   write(time(10:11),'(i2)') kh
	   write(time(13:14),'(i2)') km
	   write(time(16:21),'(f6.3)') sec
	   do i=10,16
	    if (time(i:i).eq.' ') time(i:i)='0'
	    end do
	   isf=in(1,k)
	   do i=4,1,-1
	    sf(i)=and(isf,7)
	    isf=rshift(isf,4)
	    end do
	   first=.false.
	   end if
	  if (ksyn.ne.'3890ed'x.or.and(in(7,k),'8000'x).ne.0) df(j)='*'
	  kv(j)=in(7,k)
	  if (and(kv(j),'8000'x).ne.0) then
	   kv(j)=and(kv(j),'3ff'x)
	   df(j)='*'
	   end if
17	  nfc=mod(kfc+1,90)
18	  end do
	 nr=nr+1
	 go to 10
19	 close(1)
29	 end do
	close(7)
	stop
	end
