2007-06-21 14:25:01 -04:00
|
|
|
subroutine recvpkt(iarg)
|
|
|
|
|
2008-07-12 14:11:36 -04:00
|
|
|
! Receive timf2 packets from Linrad and stuff data into array id().
|
|
|
|
! (This routine runs in a background thread and will never return.)
|
2007-06-21 14:25:01 -04:00
|
|
|
|
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
|
2007-06-30 10:28:31 -04:00
|
|
|
integer txnow
|
2007-06-21 14:25:01 -04:00
|
|
|
logical first
|
|
|
|
real*8 center_freq,buf8
|
|
|
|
common/plrscom/center_freq,msec,fqso,iptr,nblock,userx_no,iusb,buf8(174)
|
|
|
|
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)
|
2008-07-12 14:11:36 -04:00
|
|
|
data nblock0/0/,first/.true./,kb/1/,npkt/0/,nw/0/
|
2007-07-06 12:28:58 -04:00
|
|
|
data sqave/0.0/,u/0.001/,rxnoise/0.0/,kbuf/1/,lost_tot/0/
|
2007-11-05 14:19:46 -05:00
|
|
|
data multicast0/-99/
|
2007-06-21 14:25:01 -04:00
|
|
|
save
|
|
|
|
|
2007-11-05 14:19:46 -05:00
|
|
|
1 call setup_rsocket(multicast) !Open socket for multicast/unicast data
|
2007-06-21 14:25:01 -04:00
|
|
|
nreset=-1
|
|
|
|
k=0
|
|
|
|
nsec0=-999
|
2008-07-12 14:11:36 -04:00
|
|
|
fcenter=144.125 !Default (startup) frequency)
|
2007-11-05 14:19:46 -05:00
|
|
|
multicast0=multicast
|
2007-06-21 14:25:01 -04:00
|
|
|
|
2007-11-05 14:19:46 -05:00
|
|
|
10 if(multicast.ne.multicast0) go to 1
|
2007-06-26 10:20:11 -04:00
|
|
|
|
2007-11-05 14:19:46 -05:00
|
|
|
call recv_pkt(center_freq)
|
2008-07-12 14:11:36 -04:00
|
|
|
fcenter=center_freq
|
|
|
|
|
|
|
|
! Wait for an even minute to start accepting Rx data.
|
|
|
|
if(nsec0.eq.-999) then
|
|
|
|
if(mod(msec/1000,60).ne.0) go to 10
|
|
|
|
nsec0=-998
|
|
|
|
endif
|
|
|
|
|
2007-07-02 12:02:06 -04:00
|
|
|
isec=sec_midn()
|
2007-06-30 10:28:31 -04:00
|
|
|
imin=isec/60
|
|
|
|
if((monitoring.eq.0) .or. (lauto.eq.1 .and. mod(imin,2).eq.(1-TxFirst))) then
|
|
|
|
first=.true.
|
2008-07-12 14:11:36 -04:00
|
|
|
|
|
|
|
! If we're transmitting and were previously receiving in this minute,
|
|
|
|
! switch buffers to prepare for the next Rx minute.
|
2008-07-15 10:33:39 -04:00
|
|
|
if(lauto.eq.1 .and. mod(imin,2).eq.(1-TxFirst) .and. nreset.eq.1) then
|
2008-07-12 14:11:36 -04:00
|
|
|
nreset=0
|
|
|
|
kb=3-kb
|
|
|
|
k=0
|
|
|
|
if(kb.eq.2) k=NSMAX
|
|
|
|
lost_tot=0
|
|
|
|
ndone1=0
|
|
|
|
ndone2=0
|
|
|
|
endif
|
2007-06-30 10:28:31 -04:00
|
|
|
go to 10
|
|
|
|
endif
|
|
|
|
|
2008-07-12 14:11:36 -04:00
|
|
|
! If we get here, we're in Rx mode
|
2007-06-30 10:28:31 -04:00
|
|
|
lost=nblock-nblock0-1
|
|
|
|
if(lost.ne.0 .and. .not.first) then
|
2007-07-06 12:28:58 -04:00
|
|
|
nb=nblock
|
|
|
|
if(nb.lt.0) nb=nb+65536
|
|
|
|
nb0=nblock0
|
|
|
|
if(nb0.lt.0) nb0=nb0+65536
|
|
|
|
lost_tot=lost_tot + lost ! Insert zeros for the lost data.
|
2007-06-30 10:28:31 -04:00
|
|
|
do i=1,174*lost
|
|
|
|
k=k+1
|
|
|
|
d8(k)=0
|
|
|
|
enddo
|
|
|
|
endif
|
2008-07-12 14:11:36 -04:00
|
|
|
nblock0=nblock
|
2007-06-30 10:28:31 -04:00
|
|
|
|
|
|
|
nsec=msec/1000
|
|
|
|
if(mod(nsec,60).eq.1) nreset=1
|
2008-07-12 14:11:36 -04:00
|
|
|
|
|
|
|
! If this is the start of a new minute, switch buffers
|
2007-06-30 10:28:31 -04:00
|
|
|
if(mod(nsec,60).eq.0 .and. nreset.eq.1) then
|
|
|
|
nreset=0
|
|
|
|
kb=3-kb
|
|
|
|
k=0
|
|
|
|
if(kb.eq.2) k=NSMAX
|
2007-07-06 12:28:58 -04:00
|
|
|
lost_tot=0
|
2007-07-13 11:47:35 -04:00
|
|
|
ndone1=0
|
|
|
|
ndone2=0
|
2007-06-30 10:28:31 -04:00
|
|
|
endif
|
2007-06-21 14:25:01 -04:00
|
|
|
|
2007-06-30 10:28:31 -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
|
|
|
|
|
|
|
|
sq=0.
|
|
|
|
do i=1,174
|
|
|
|
k=k+1
|
|
|
|
d8(k)=buf8(i)
|
2007-11-19 11:42:21 -05:00
|
|
|
k2=k
|
|
|
|
n=1
|
|
|
|
if(k.gt.NSMAX) then
|
|
|
|
k2=k2-NSMAX
|
|
|
|
n=2
|
|
|
|
endif
|
|
|
|
sq=sq + float(int(id(1,k2,n)))**2 + float(int(id(1,k2,n)))**2 + &
|
|
|
|
float(int(id(1,k2,n)))**2 + float(int(id(1,k2,n)))**2
|
2007-06-30 10:28:31 -04:00
|
|
|
enddo
|
|
|
|
sqave=sqave + u*(sq-sqave)
|
|
|
|
rxnoise=10.0*log10(sqave) - 48.0
|
2007-07-09 20:15:11 -04:00
|
|
|
kxp=k
|
2007-06-21 14:25:01 -04:00
|
|
|
|
2008-07-12 14:11:36 -04:00
|
|
|
if(k.lt.1 .or. k.gt.NSZ) then
|
|
|
|
print*,'Error in recvpkt: ',k,NSZ,NSMAX
|
|
|
|
stop
|
|
|
|
endif
|
|
|
|
|
|
|
|
! The following may be a bad idea because it uses non-reentrant Fortran I/O ???
|
2007-06-30 10:28:31 -04:00
|
|
|
if(mode.eq.'Measur') then
|
|
|
|
npkt=npkt+1
|
|
|
|
if(npkt.ge.551) then
|
|
|
|
npkt=0
|
|
|
|
nw=nw+1
|
2007-07-06 12:28:58 -04:00
|
|
|
rewind 11
|
2007-06-30 10:28:31 -04:00
|
|
|
write(11,1000) nw,rxnoise
|
|
|
|
1000 format(i6,f8.2)
|
2007-07-06 12:28:58 -04:00
|
|
|
write(11,*) '$EOF'
|
2007-06-30 10:28:31 -04:00
|
|
|
call flushqqq(11)
|
|
|
|
ndecdone=1
|
|
|
|
write(24,1000) nw,rxnoise
|
2007-06-21 14:25:01 -04:00
|
|
|
endif
|
2007-06-30 10:28:31 -04:00
|
|
|
else
|
|
|
|
nw=0
|
|
|
|
endif
|
|
|
|
|
|
|
|
20 if(nsec.ne.nsec0) then
|
|
|
|
mutch=nsec/3600
|
|
|
|
mutcm=mod(nsec/60,60)
|
|
|
|
mutc=100*mutch + mutcm
|
|
|
|
ns=mod(nsec,60)
|
|
|
|
nsec0=nsec
|
2007-06-21 14:25:01 -04:00
|
|
|
|
2008-07-12 14:11:36 -04:00
|
|
|
! See if it's time to start FFTs
|
2007-07-13 11:47:35 -04:00
|
|
|
if(ns.ge.nt1 .and. ndone1.eq.0) then
|
2007-06-30 10:28:31 -04:00
|
|
|
nutc=mutc
|
2007-07-11 15:47:36 -04:00
|
|
|
fcenter=center_freq
|
2007-06-30 10:28:31 -04:00
|
|
|
kbuf=kb
|
|
|
|
kk=k
|
2007-06-30 13:08:27 -04:00
|
|
|
ndiskdat=0
|
2007-07-13 11:47:35 -04:00
|
|
|
ndone1=1
|
2007-06-30 10:28:31 -04:00
|
|
|
endif
|
2008-07-12 14:11:36 -04:00
|
|
|
|
|
|
|
! See if it's time to start second stage of processing
|
2007-07-13 11:47:35 -04:00
|
|
|
if(ns.ge.nt2 .and. ndone2.eq.0) then
|
2007-06-30 10:28:31 -04:00
|
|
|
kk=k
|
2007-07-13 11:47:35 -04:00
|
|
|
ndone2=1
|
2007-07-06 12:28:58 -04:00
|
|
|
nlost=lost_tot ! Save stats for printout
|
2007-06-30 10:28:31 -04:00
|
|
|
endif
|
2007-06-21 14:25:01 -04:00
|
|
|
endif
|
2007-07-06 12:28:58 -04:00
|
|
|
first=.false.
|
2007-06-21 14:25:01 -04:00
|
|
|
go to 10
|
|
|
|
|
|
|
|
end subroutine recvpkt
|