2007-06-21 14:25:01 -04:00
|
|
|
!---------------------------------------------------- recvpkt
|
|
|
|
subroutine recvpkt(iarg)
|
|
|
|
|
|
|
|
! Receive timf2 packets from Linrad, stuff data into id().
|
|
|
|
! This routine runs in a background thread and will never return.
|
|
|
|
|
|
|
|
#ifdef Win32
|
|
|
|
use dflib
|
|
|
|
#endif
|
|
|
|
|
2007-06-23 14:12:39 -04:00
|
|
|
parameter (NSZ=2*60*96000)
|
2007-06-21 14:25:01 -04:00
|
|
|
real*8 d8(NSZ)
|
|
|
|
integer*1 userx_no,iusb
|
|
|
|
integer*2 nblock,nblock0
|
|
|
|
logical first
|
|
|
|
real*8 center_freq,buf8
|
|
|
|
common/plrscom/center_freq,msec,fqso,iptr,nblock,userx_no,iusb,buf8(174)
|
|
|
|
! 8 4 4 4 2 1 1 1392
|
|
|
|
include 'datcom.f90'
|
2007-06-22 16:32:58 -04:00
|
|
|
include 'gcom1.f90'
|
2007-06-21 14:25:01 -04:00
|
|
|
include 'gcom2.f90'
|
|
|
|
equivalence (id,d8)
|
2007-06-26 10:20:11 -04:00
|
|
|
data nblock0/0/,first/.true./,kb/1/,ntx/0/,npkt/0/,nw/0/
|
2007-06-24 12:31:38 -04:00
|
|
|
data sqave/0.0/,u/0.001/,rxnoise/0.0/
|
2007-06-21 14:25:01 -04:00
|
|
|
save
|
|
|
|
|
|
|
|
! Open a socket to receive multicast data from Linrad
|
|
|
|
call setup_rsocket
|
|
|
|
nreset=-1
|
|
|
|
k=0
|
|
|
|
nsec0=-999
|
|
|
|
|
|
|
|
10 call recv_pkt(center_freq)
|
|
|
|
if(monitoring.eq.1) then
|
2007-06-26 10:20:11 -04:00
|
|
|
lost=nblock-nblock0-1
|
|
|
|
nblock0=nblock
|
|
|
|
|
|
|
|
if(lost.ne.0 .and. .not.first) then
|
|
|
|
! print*,'Lost packets?',nblock,nblock0,lost,rxnoise,mode
|
|
|
|
! Fill in zeros for the lost data.
|
|
|
|
nlost=nlost + lost
|
|
|
|
do i=1,174*lost
|
|
|
|
k=k+1
|
|
|
|
d8(k)=0
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
first=.false.
|
|
|
|
|
2007-06-28 16:03:52 -04:00
|
|
|
!###
|
|
|
|
! kbuf=kb
|
|
|
|
! kk=k
|
|
|
|
!###
|
|
|
|
|
2007-06-21 14:25:01 -04:00
|
|
|
nsec=msec/1000
|
|
|
|
if(mod(nsec,60).eq.1) nreset=1
|
|
|
|
if(mod(nsec,60).eq.0 .and. nreset.eq.1) then
|
|
|
|
! This is the start of a new minute, switch buffers
|
|
|
|
nreset=0
|
|
|
|
kb=3-kb
|
|
|
|
k=0
|
2007-06-23 14:12:39 -04:00
|
|
|
if(kb.eq.2) k=NSMAX
|
2007-06-21 14:59:43 -04:00
|
|
|
nlost=0
|
2007-06-21 14:25:01 -04:00
|
|
|
endif
|
|
|
|
|
2007-06-23 14:12:39 -04:00
|
|
|
if(kb.eq.1 .and. (k+174).gt.NSMAX) go to 20
|
|
|
|
if(kb.eq.2 .and. (k+174).gt.2*NSMAX) go to 20
|
|
|
|
|
2007-06-22 16:32:58 -04:00
|
|
|
if(transmitting.eq.0) then
|
2007-06-24 12:31:38 -04:00
|
|
|
sq=0.
|
2007-06-22 16:32:58 -04:00
|
|
|
do i=1,174
|
|
|
|
k=k+1
|
|
|
|
d8(k)=buf8(i)
|
2007-06-28 09:31:46 -04:00
|
|
|
sq=sq + float(id(1,k,1))**2 + float(id(1,k,1))**2 + &
|
|
|
|
float(id(1,k,1))**2 + float(id(1,k,1))**2
|
2007-06-22 16:32:58 -04:00
|
|
|
enddo
|
2007-06-24 12:31:38 -04:00
|
|
|
sqave=sqave + u*(sq-sqave)
|
2007-06-24 15:47:35 -04:00
|
|
|
rxnoise=10.0*log10(sqave) - 48.0
|
2007-06-26 10:20:11 -04:00
|
|
|
|
|
|
|
if(mode.eq.'Measur') then
|
|
|
|
npkt=npkt+1
|
|
|
|
if(npkt.ge.551) then
|
|
|
|
npkt=0
|
|
|
|
nw=nw+1
|
|
|
|
write(11,1000) nw,rxnoise
|
|
|
|
1000 format(i6,f8.2)
|
|
|
|
call flushqqq(11)
|
|
|
|
ndecdone=1
|
|
|
|
write(24,1000) nw,rxnoise
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
nw=0
|
|
|
|
endif
|
|
|
|
|
2007-06-22 16:32:58 -04:00
|
|
|
else
|
2007-06-26 10:20:11 -04:00
|
|
|
! We're transmitting, zero out this packet.
|
2007-06-22 16:32:58 -04:00
|
|
|
do i=1,174
|
|
|
|
k=k+1
|
|
|
|
d8(k)=0.d0
|
|
|
|
enddo
|
|
|
|
endif
|
2007-06-23 14:12:39 -04:00
|
|
|
if(k.lt.1 .or. k.gt.NSZ) then
|
|
|
|
print*,'Error in recvpkt: ',k,NSZ,NSMAX
|
|
|
|
stop
|
|
|
|
endif
|
2007-06-21 14:25:01 -04:00
|
|
|
|
2007-06-23 14:12:39 -04:00
|
|
|
20 if(nsec.ne.nsec0) then
|
2007-06-21 14:25:01 -04:00
|
|
|
mutch=nsec/3600
|
|
|
|
mutcm=mod(nsec/60,60)
|
|
|
|
mutc=100*mutch + mutcm
|
|
|
|
ns=mod(nsec,60)
|
2007-06-24 15:47:35 -04:00
|
|
|
! write(*,1010) mutc,ns,0.001*msec,k,rxnoise
|
2007-06-21 14:25:01 -04:00
|
|
|
!1010 format('UTC:',i5.4,' ns:',i3,' t:',f10.3,' k:',i8)
|
|
|
|
nsec0=nsec
|
2007-06-22 16:32:58 -04:00
|
|
|
ntx=ntx+transmitting
|
|
|
|
if(mod(nsec,60).eq.52) then
|
2007-06-28 16:03:52 -04:00
|
|
|
kk=k
|
2007-06-22 16:32:58 -04:00
|
|
|
kbuf=kb
|
|
|
|
nutc=mutc
|
|
|
|
klost=nlost
|
2007-06-28 16:03:52 -04:00
|
|
|
! if(ntx.lt.20) then
|
|
|
|
! newdat=1
|
|
|
|
! ndecoding=1
|
|
|
|
! endif
|
2007-06-22 16:32:58 -04:00
|
|
|
ntx=0
|
|
|
|
endif
|
2007-06-21 14:25:01 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
endif
|
|
|
|
go to 10
|
|
|
|
|
|
|
|
end subroutine recvpkt
|