diff options
Diffstat (limited to 'lib/77bit/packjt77.f90')
| -rw-r--r-- | lib/77bit/packjt77.f90 | 193 |
1 files changed, 139 insertions, 54 deletions
diff --git a/lib/77bit/packjt77.f90 b/lib/77bit/packjt77.f90 index 2464ea80..83d848f1 100644 --- a/lib/77bit/packjt77.f90 +++ b/lib/77bit/packjt77.f90 @@ -2,8 +2,8 @@ module packjt77 ! These variables are accessible from outside via "use packjt77": parameter (MAXHASH=1000,MAXRECENT=10) - character (len=13), dimension(1:1024) :: calls10='' - character (len=13), dimension(1:4096) :: calls12='' + character (len=13), dimension(0:1023) :: calls10='' + character (len=13), dimension(0:4095) :: calls12='' character (len=13), dimension(1:MAXHASH) :: calls22='' character (len=13), dimension(1:MAXRECENT) :: recent_calls='' character (len=13) :: mycall13='' @@ -19,7 +19,7 @@ subroutine hash10(n10,c13) character*13 c13 c13='<...>' - if(n10.lt.1 .or. n10.gt.1024) return + if(n10.lt.0 .or. n10.gt.1023) return if(len(trim(calls10(n10))).gt.0) then c13=calls10(n10) c13='<'//trim(c13)//'>' @@ -33,7 +33,7 @@ subroutine hash12(n12,c13) character*13 c13 c13='<...>' - if(n12.lt.1 .or. n12.gt.4096) return + if(n12.lt.0 .or. n12.gt.4095) return if(len(trim(calls12(n12))).gt.0) then c13=calls12(n12) c13='<'//trim(c13)//'>' @@ -90,10 +90,10 @@ subroutine save_hash_call(c13,n10,n12,n22) if(len(trim(cw)) .lt. 3) return n10=ihashcall(cw,10) - if(n10.ge.1 .and. n10 .le. 1024 .and. cw.ne.mycall13) calls10(n10)=cw + if(n10.ge.0 .and. n10 .le. 1023 .and. cw.ne.mycall13) calls10(n10)=cw n12=ihashcall(cw,12) - if(n12.ge.1 .and. n12 .le. 4096 .and. cw.ne.mycall13) calls12(n12)=cw + if(n12.ge.0 .and. n12 .le. 4095 .and. cw.ne.mycall13) calls12(n12)=cw n22=ihashcall(cw,22) if(any(ihash22.eq.n22)) then ! If entry exists, make sure callsign is the most recently received one @@ -124,12 +124,14 @@ subroutine pack77(msg0,i3,n3,c77) integer ntel(3) msg=msg0 - if(i3.eq.0 .and. n3.eq.5) go to 5 + i3_hint=i3 + n3_hint=n3 + i3=-1 + n3=-1 + if(i3_hint.eq.0 .and. n3_hint.eq.5) go to 5 ! Convert msg to upper case; collapse multiple blanks; parse into words. call split77(msg,nwords,nw,w) - i3=-1 - n3=-1 if(msg(1:3).eq.'CQ ' .or. msg(1:3).eq.'DE ' .or. msg(1:4).eq.'QRZ ') go to 100 ! Check 0.1 (DXpedition mode) @@ -160,7 +162,7 @@ subroutine pack77(msg0,i3,n3,c77) go to 900 endif -100 call pack77_06(nwords,w,i3,n3,c77) +100 call pack77_06(nwords,w,i3,n3,c77,i3_hint,n3_hint) if(i3.ge.0) go to 900 ! Check Type 1 (Standard 77-bit message) or Type 2, with optional "/P" @@ -203,7 +205,7 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) integer ntel(3) character*77 c77 character*37 msg - character*13 call_1,call_2,call_3 + character*13 call_1,call_2,call_3,call_1a character*13 mycall13_0,dxcall13_0 character*11 c11 character*3 crpt,cntx,cpfx @@ -214,7 +216,7 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) character*38 c character*36 a2 integer hashmy10,hashmy12,hashmy22,hashdx10,hashdx12,hashdx22 - logical unpk28_success,unpk77_success + logical unpk28_success,unpk77_success,unpkg4_success logical dxcall13_set,mycall13_set data a2/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'/,nzzz/46656/ @@ -276,11 +278,16 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) read(c77(72:77),'(2b3)') n3,i3 msg=repeat(' ',37) + if(i3.eq.0 .and. n3.eq.0) then ! 0.0 Free text call unpacktext77(c77(1:71),msg(1:13)) msg(14:)=' ' msg=adjustl(msg) + if(msg(1:1).eq.' ') then + unpk77_success=.false. + return + endif else if(i3.eq.0 .and. n3.eq.1) then ! 0.1 K1ABC RR73; W9XYZ <KH1/KH7Z> -11 28 28 10 5 71 DXpedition Mode @@ -346,38 +353,32 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) msg=adjustl(msg) else if(i3.eq.0 .and. n3.eq.6) then - read(c77(50:50),'(b1)') j2a - j2b=0 - if(j2a.eq.0) read(c77(49:49),'(b1)') j2b - j2=2*j2a+j2b - if(j2.eq.0) then + read(c77(49:50),'(2b1)') j2a,j2b + itype=2 + if(j2b.eq.0 .and. j2a.eq.0) itype=1 + if(j2b.eq.0 .and. j2a.eq.1) itype=3 + if(itype.eq.1) then ! WSPR Type 1 read(c77,2010) n28,igrid4,idbm 2010 format(b28.28,b15.15,b5.5) idbm=nint(idbm*10.0/3.0) call unpack28(n28,call_1,unpk28_success) if(.not.unpk28_success) unpk77_success=.false. - call to_grid4(igrid4,grid4) + call to_grid4(igrid4,grid4,unpkg4_success) + if(.not.unpkg4_success) unpk77_success=.false. write(crpt,'(i3)') idbm msg=trim(call_1)//' '//grid4//' '//trim(adjustl(crpt)) + if (unpk77_success) call save_hash_call(call_1,n10,n12,n22) !### Is this OK here? ### - else if(j2.eq.1) then + else if(itype.eq.2) then ! WSPR Type 2 - read(c77,2030) n28,igrid6 -2030 format(b22.22,b25.25) - call unpack28(n28,call_1,unpk28_success) - if(.not.unpk28_success) unpk77_success=.false. - call to_grid6(igrid6,grid6) - msg=trim(call_1)//' '//grid6 - - else if(j2.eq.2) then -! WSPR Type 3 read(c77,2020) n28,npfx,idbm 2020 format(b28.28,b16.16,b5.5) idbm=nint(idbm*10.0/3.0) call unpack28(n28,call_1,unpk28_success) if(.not.unpk28_success) unpk77_success=.false. write(crpt,'(i3)') idbm + cpfx=' ' if(npfx.lt.nzzz) then ! Prefix do i=3,1,-1 @@ -387,10 +388,11 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) if(npfx.eq.0) exit enddo msg=trim(adjustl(cpfx))//'/'//trim(call_1)//' '//trim(adjustl(crpt)) + call_1a=trim(adjustl(cpfx))//'/'//trim(call_1) + call save_hash_call(call_1a,n10,n12,n22) !### Is this OK here? ### else ! Suffix npfx=npfx-nzzz - cpfx=' ' if(npfx.le.35) then cpfx(1:1)=a2(npfx+1:npfx+1) else if(npfx.gt.35 .and. npfx.le.1295) then @@ -405,10 +407,25 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) return endif msg=trim(call_1)//'/'//trim(adjustl(cpfx))//' '//trim(adjustl(crpt)) + call_1a=trim(call_1)//'/'//trim(adjustl(cpfx)) + call save_hash_call(call_1a,n10,n12,n22) !### Is this OK here? ### endif - + + else if(itype.eq.3) then +! WSPR Type 3 + read(c77,2030) n22,igrid6 +2030 format(b22.22,b25.25) + n28=n22+2063592 + call unpack28(n28,call_1,unpk28_success) + if(.not.unpk28_success) unpk77_success=.false. + call to_grid(igrid6,grid6,unpkg4_success) + if(.not.unpkg4_success) unpk77_success=.false. + msg=trim(call_1)//' '//grid6 endif - + + else if(i3.eq.0 .and. n3.gt.6) then + unpk77_success=.false. + else if(i3.eq.1 .or. i3.eq.2) then ! Type 1 (standard message) or Type 2 ("/P" form for EU VHF contest) read(c77,1000) n28a,ipa,n28b,ipb,ir,igrid4,i3 @@ -435,7 +452,8 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) if(i.ge.4) call add_call_to_recent_calls(call_2) endif if(igrid4.le.MAXGRID4) then - call to_grid4(igrid4,grid4) + call to_grid4(igrid4,grid4,unpkg4_success) + if(.not.unpkg4_success) unpk77_success=.false. if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//grid4 if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//grid4 if(msg(1:3).eq.'CQ ' .and. ir.eq.1) unpk77_success=.false. @@ -446,7 +464,9 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) if(irpt.eq.3) msg=trim(call_1)//' '//trim(call_2)//' RR73' if(irpt.eq.4) msg=trim(call_1)//' '//trim(call_2)//' 73' if(irpt.ge.5) then - write(crpt,'(i3.2)') irpt-35 + isnr=irpt-35 + if(isnr.gt.50) isnr=isnr-101 + write(crpt,'(i3.2)') isnr if(crpt(1:1).eq.' ') crpt(1:1)='+' if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//crpt if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R'//crpt @@ -550,7 +570,7 @@ subroutine unpack77(c77,nrx,msg,unpk77_success) nrs=52+irpt write(cexch,1022) nrs,iserial 1022 format(i2,i4.4) - call to_grid6(igrid6,grid6) + call to_grid6(igrid6,grid6,unpk77_success) if(ir.eq.0) msg=trim(call_1)//' '//trim(call_2)//' '//cexch//' '//grid6 if(ir.eq.1) msg=trim(call_1)//' '//trim(call_2)//' R '//cexch//' '//grid6 @@ -897,7 +917,7 @@ subroutine pack77_03(nwords,w,i3,n3,c77) ntx=-1 j=len(trim(w(nwords-1)))-1 - read(w(nwords-1)(1:j),*,err=1) ntx !Number of transmitters + read(w(nwords-1)(1:j),*,err=1,end=1) ntx !Number of transmitters 1 if(ntx.lt.1 .or. ntx.gt.32) return nclass=ichar(w(nwords-1)(j+1:j+1))-ichar('A') @@ -925,7 +945,7 @@ subroutine pack77_03(nwords,w,i3,n3,c77) end subroutine pack77_03 -subroutine pack77_06(nwords,w,i3,n3,c77) +subroutine pack77_06(nwords,w,i3,n3,c77,i3_hint,n3_hint) character*13 w(19) character*77 c77 @@ -942,13 +962,14 @@ subroutine pack77_06(nwords,w,i3,n3,c77) grid4(3:3).ge.'0' .and. grid4(3:3).le.'9' .and. & grid4(4:4).ge.'0' .and. grid4(4:4).le.'9' - is_grid6(grid6)=len(trim(grid6)).eq.6 .and. & + is_grid6(grid6)=(len(trim(grid6)).eq.6.or.len(trim(grid6)).eq.4).and. & grid6(1:1).ge.'A' .and. grid6(1:1).le.'R' .and. & grid6(2:2).ge.'A' .and. grid6(2:2).le.'R' .and. & grid6(3:3).ge.'0' .and. grid6(3:3).le.'9' .and. & grid6(4:4).ge.'0' .and. grid6(4:4).le.'9' .and. & - grid6(5:5).ge.'A' .and. grid6(5:5).le.'X' .and. & - grid6(6:6).ge.'A' .and. grid6(6:6).le.'X' + (len(trim(grid6)).eq.4.or. & + (grid6(5:5).ge.'A' .and. grid6(5:5).le.'X' .and. & + grid6(6:6).ge.'A' .and. grid6(6:6).le.'X')) is_digit(c)=c.ge.'0' .and. c.le.'9' @@ -1020,22 +1041,32 @@ subroutine pack77_06(nwords,w,i3,n3,c77) go to 900 endif - if(nwords.eq.2 .and. m1.ge.5 .and. m1.le.12 .and. m2.le.6) then + if(i3_hint.eq.0.and.n3_hint.eq.6.and.nwords.eq.2 .and. m1.ge.5 & + .and. m1.le.12 .and. m2.le.6) then ! WSPR Type 3 + + !n3_hint=6 and i3_hint=0 is a hint that the caller wanted a + !50-bit encoding rather than the possible alternative n3=4 77-bit + !encoding if(index(w(1),'<').lt.1 .or. index(w(1),'>').lt.1) go to 900 grid6=w(2)(1:6) if(.not.is_grid6(grid6)) go to 900 i3=0 n3=6 call pack28(w(1),n28) - k1=(ichar(grid6(1:1))-ichar('A'))*18*10*10*24*24 - k2=(ichar(grid6(2:2))-ichar('A'))*10*10*24*24 - k3=(ichar(grid6(3:3))-ichar('0'))*10*24*24 - k4=(ichar(grid6(4:4))-ichar('0'))*24*24 - k5=(ichar(grid6(5:5))-ichar('A'))*24 - k6=(ichar(grid6(6:6))-ichar('A')) - igrid6=k1+k2+k3+k4+k5+k6 - write(c77,1030) n28,igrid6,2,0,n3,i3 + n22=n28-2063592 + k1=(ichar(grid6(1:1))-ichar('A'))*18*10*10*25*25 + k2=(ichar(grid6(2:2))-ichar('A'))*10*10*25*25 + k3=(ichar(grid6(3:3))-ichar('0'))*10*25*25 + k4=(ichar(grid6(4:4))-ichar('0'))*25*25 + if (grid6(5:6).eq.' ') then + igrid6=k1+k2+k3+k4+24*25+24 + else + k5=(ichar(grid6(5:5))-ichar('A'))*25 + k6=(ichar(grid6(6:6))-ichar('A')) + igrid6=k1+k2+k3+k4+k5+k6 + endif + write(c77,1030) n22,igrid6,2,0,n3,i3 1030 format(b22.22,b25.25,b3.3,b21.21,2b3.3) endif @@ -1083,10 +1114,12 @@ subroutine pack77_1(nwords,w,i3,n3,c77) if(c1.eq.'+' .or. c1.eq.'-') then ir=0 read(w(nwords),*,err=900) irpt + if(irpt.ge.-50 .and. irpt.le.-31) irpt=irpt+101 irpt=irpt+35 else if(c2.eq.'R+' .or. c2.eq.'R-') then ir=1 read(w(nwords)(2:),*) irpt + if(irpt.ge.-50 .and. irpt.le.-31) irpt=irpt+101 irpt=irpt+35 else if(trim(w(nwords)).eq.'RRR') then ir=0 @@ -1467,44 +1500,96 @@ subroutine add_call_to_recent_calls(callsign) return end subroutine add_call_to_recent_calls -subroutine to_grid4(n,grid4) +subroutine to_grid4(n,grid4,ok) character*4 grid4 - + logical ok + + ok=.false. j1=n/(18*10*10) + if (j1.lt.0.or.j1.gt.17) goto 900 n=n-j1*18*10*10 j2=n/(10*10) + if (j2.lt.0.or.j2.gt.17) goto 900 n=n-j2*10*10 j3=n/10 + if (j3.lt.0.or.j3.gt.9) goto 900 j4=n-j3*10 + if (j4.lt.0.or.j4.gt.9) goto 900 grid4(1:1)=char(j1+ichar('A')) grid4(2:2)=char(j2+ichar('A')) grid4(3:3)=char(j3+ichar('0')) grid4(4:4)=char(j4+ichar('0')) - - return + ok=.true. + +900 return end subroutine to_grid4 -subroutine to_grid6(n,grid6) +subroutine to_grid6(n,grid6,ok) character*6 grid6 + logical ok + ok=.false. j1=n/(18*10*10*24*24) + if (j1.lt.0.or.j1.gt.17) goto 900 n=n-j1*18*10*10*24*24 j2=n/(10*10*24*24) + if (j2.lt.0.or.j2.gt.17) goto 900 n=n-j2*10*10*24*24 j3=n/(10*24*24) + if (j3.lt.0.or.j3.gt.9) goto 900 n=n-j3*10*24*24 j4=n/(24*24) + if (j4.lt.0.or.j4.gt.9) goto 900 n=n-j4*24*24 j5=n/24 + if (j5.lt.0.or.j5.gt.23) goto 900 j6=n-j5*24 + if (j6.lt.0.or.j6.gt.23) goto 900 grid6(1:1)=char(j1+ichar('A')) grid6(2:2)=char(j2+ichar('A')) grid6(3:3)=char(j3+ichar('0')) grid6(4:4)=char(j4+ichar('0')) grid6(5:5)=char(j5+ichar('A')) grid6(6:6)=char(j6+ichar('A')) + ok=.true. - return +900 return end subroutine to_grid6 +subroutine to_grid(n,grid6,ok) + ! 4-, or 6-character grid + character*6 grid6 + logical ok + + ok=.false. + j1=n/(18*10*10*25*25) + if (j1.lt.0.or.j1.gt.17) goto 900 + n=n-j1*18*10*10*25*25 + j2=n/(10*10*25*25) + if (j2.lt.0.or.j2.gt.17) goto 900 + n=n-j2*10*10*25*25 + j3=n/(10*25*25) + if (j3.lt.0.or.j3.gt.9) goto 900 + n=n-j3*10*25*25 + j4=n/(25*25) + if (j4.lt.0.or.j4.gt.9) goto 900 + n=n-j4*25*25 + j5=n/25 + if (j5.lt.0.or.j5.gt.24) goto 900 + j6=n-j5*25 + if (j6.lt.0.or.j6.gt.24) goto 900 + grid6='' + grid6(1:1)=char(j1+ichar('A')) + grid6(2:2)=char(j2+ichar('A')) + grid6(3:3)=char(j3+ichar('0')) + grid6(4:4)=char(j4+ichar('0')) + if (j5.ne.24.or.j6.ne.24) then + grid6(5:5)=char(j5+ichar('A')) + grid6(6:6)=char(j6+ichar('A')) + endif + ok=.true. + +900 return +end subroutine to_grid + end module packjt77 |
