summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIain R. Learmonth <irl@debian.org>2015-10-18 17:55:15 +0100
committerIain R. Learmonth <irl@debian.org>2015-10-18 17:55:15 +0100
commitc720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (patch)
treeecf89ef5fb2aa173119808e84e6d2e4cc15b962c /lib
Imported Upstream version 1.1.r3496upstream/1.1.r3496
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.MinGW117
-rw-r--r--lib/Makefile.linux104
-rw-r--r--lib/afc65b.f9059
-rw-r--r--lib/afc9.f9058
-rw-r--r--lib/analytic.f9025
-rw-r--r--lib/azdist.f90107
-rw-r--r--lib/bpskmetrics.dat256
-rw-r--r--lib/ccf2.f9045
-rw-r--r--lib/ccf65.f90117
-rw-r--r--lib/char.h57
-rw-r--r--lib/chkhist.f9021
-rw-r--r--lib/chkmsg.f9031
-rw-r--r--lib/chkss2.f9024
-rw-r--r--lib/constants.f905
-rw-r--r--lib/conv232.f9038
-rw-r--r--lib/cutil.c93
-rw-r--r--lib/db.f905
-rw-r--r--lib/decode65a.f9095
-rw-r--r--lib/decode65b.f9036
-rw-r--r--lib/decode9.f9085
-rw-r--r--lib/decode_rs.c263
-rw-r--r--lib/decoder.f90173
-rw-r--r--lib/deep24.f90182
-rw-r--r--lib/deg2grid.f9030
-rw-r--r--lib/demod64a.f9073
-rw-r--r--lib/downsam9.f9066
-rw-r--r--lib/encode232.f9033
-rw-r--r--lib/encode4.f9020
-rw-r--r--lib/encode_rs.c52
-rw-r--r--lib/entail.f9030
-rw-r--r--lib/extract.F90103
-rw-r--r--lib/extract4.f9061
-rw-r--r--lib/f77_wisdom.f9045
-rw-r--r--lib/fano232.f90140
-rw-r--r--lib/fchisq.f9041
-rw-r--r--lib/fchisq65.f9068
-rw-r--r--lib/fftw3.f9064
-rw-r--r--lib/fil3.f90159
-rw-r--r--lib/fil61.f9064
-rw-r--r--lib/fil6521.f9044
-rw-r--r--lib/filbig.f90127
-rw-r--r--lib/fillcom.f9025
-rw-r--r--lib/flat1.f9030
-rw-r--r--lib/flat2.f9018
-rw-r--r--lib/flat65.f9025
-rw-r--r--lib/four2a.f9090
-rw-r--r--lib/gen24.f9086
-rw-r--r--lib/gen65.f9065
-rw-r--r--lib/genjt9.f9058
-rw-r--r--lib/genmet.f9088
-rw-r--r--lib/geodist.f9096
-rw-r--r--lib/getlags.f9027
-rw-r--r--lib/getmet24.f9052
-rw-r--r--lib/getpfx1.f9097
-rw-r--r--lib/getpfx2.f9024
-rw-r--r--lib/gran.c28
-rw-r--r--lib/graycode.f909
-rw-r--r--lib/graycode65.f909
-rw-r--r--lib/grid2deg.f9038
-rw-r--r--lib/grid2k.f9012
-rw-r--r--lib/grid2n.f9010
-rw-r--r--lib/igray.c18
-rw-r--r--lib/indexx.f9019
-rw-r--r--lib/init_rs.c126
-rw-r--r--lib/int.h57
-rw-r--r--lib/interleave24.f9043
-rw-r--r--lib/interleave63.f9025
-rw-r--r--lib/interleave8.f9017
-rw-r--r--lib/interleave9.f9039
-rw-r--r--lib/ipcomm.cpp50
-rw-r--r--lib/jt65.f9068
-rw-r--r--lib/jt65a.f9085
-rw-r--r--lib/jt9.f90111
-rw-r--r--lib/jt9a.f9072
-rw-r--r--lib/jt9b.f9012
-rw-r--r--lib/jt9c.f9021
-rw-r--r--lib/jt9code.f9029
-rw-r--r--lib/jt9sim.f90166
-rw-r--r--lib/jt9sync.f9018
-rw-r--r--lib/k2grid.f9012
-rw-r--r--lib/libhamlib.dll.abin0 -> 177492 bytes
-rw-r--r--lib/met8.21256
-rw-r--r--lib/morse.f9086
-rw-r--r--lib/move.f907
-rw-r--r--lib/msgs.txt60
-rw-r--r--lib/n2grid.f9014
-rw-r--r--lib/nchar.f9023
-rw-r--r--lib/noisegen.f9013
-rw-r--r--lib/packbits.f9021
-rw-r--r--lib/packcall.f9079
-rw-r--r--lib/packdxcc.f9064
-rw-r--r--lib/packgrid.f9076
-rw-r--r--lib/packmsg.f90113
-rw-r--r--lib/packtext.f9047
-rw-r--r--lib/pctile.f9022
-rw-r--r--lib/peakdt9.f9054
-rw-r--r--lib/peakup.f908
-rw-r--r--lib/pfx.f9050
-rw-r--r--lib/pfxdump.f9013
-rw-r--r--lib/ps24.f9027
-rw-r--r--lib/ptt.c50
-rw-r--r--lib/rig_control.c99
-rw-r--r--lib/rs.h35
-rw-r--r--lib/s3avg.f9060
-rw-r--r--lib/sec_midn.f9011
-rw-r--r--lib/setup65.f9096
-rw-r--r--lib/sleep.h32
-rw-r--r--lib/sleep_msec.f904
-rw-r--r--lib/slope.f9040
-rw-r--r--lib/smo121.f9013
-rw-r--r--lib/softsym.f9050
-rw-r--r--lib/sort.f904
-rw-r--r--lib/ss.bat1
-rw-r--r--lib/ssort.f90264
-rw-r--r--lib/stdmsg.f9012
-rw-r--r--lib/symspec.f90113
-rw-r--r--lib/symspec2.f9088
-rw-r--r--lib/symspec65.f9047
-rw-r--r--lib/sync24.f90179
-rw-r--r--lib/sync9.f90101
-rw-r--r--lib/tab.c36
-rw-r--r--lib/timer.f90112
-rw-r--r--lib/timeval.h74
-rw-r--r--lib/tstrig.c26
-rw-r--r--lib/tstrig.h50
-rw-r--r--lib/twkfreq.f9028
-rw-r--r--lib/twkfreq65.f9025
-rw-r--r--lib/unpackbits.f9022
-rw-r--r--lib/unpackcall.f90142
-rw-r--r--lib/unpackgrid.f9045
-rw-r--r--lib/unpackmsg.f90107
-rw-r--r--lib/unpacktext.f9035
-rw-r--r--lib/vit216.c219
-rw-r--r--lib/wrapkarn.c70
-rw-r--r--lib/wsjt24.f90181
-rw-r--r--lib/wsjt24d.f9043
-rw-r--r--lib/xcor24.f9094
-rw-r--r--lib/zplot9.f9031
138 files changed, 8763 insertions, 0 deletions
diff --git a/lib/Makefile.MinGW b/lib/Makefile.MinGW
new file mode 100644
index 00000000..e09924b6
--- /dev/null
+++ b/lib/Makefile.MinGW
@@ -0,0 +1,117 @@
+# Makefile for MinGW on Windows
+# Windows re-direct:
+# C> make > junk1 2>&1
+
+CC = gcc
+FC = g95
+
+FFLAGS = -O2 -fbounds-check -Wall -Wno-precision-loss -fno-second-underscore
+CFLAGS = -I. -fbounds-check -mno-stack-arg-probe
+
+# Default rules
+%.o: %.c
+ ${CC} ${CFLAGS} -c $<
+%.o: %.f
+ ${FC} ${FFLAGS} -c $<
+%.o: %.F
+ ${FC} ${FFLAGS} -c $<
+%.o: %.f90
+ ${FC} ${FFLAGS} -c $<
+%.o: %.F90
+ ${FC} ${FFLAGS} -c $<
+
+all: libjt9.a jt9sim.exe jt9.exe jt9code.exe jt65.exe
+
+OBJS1 = pctile.o graycode.o sort.o ssort.o \
+ unpackmsg.o igray.o unpackcall.o unpackgrid.o \
+ grid2k.o unpacktext.o getpfx2.o packmsg.o deg2grid.o \
+ packtext.o getpfx1.o packcall.o k2grid.o packgrid.o \
+ nchar.o four2a.o grid2deg.o pfxdump.o f77_wisdom.o \
+ symspec.o analytic.o db.o genjt9.o \
+ packbits.o unpackbits.o encode232.o interleave9.o \
+ entail.o fano232.o gran.o sync9.o decode9.o \
+ fil3.o decoder.o grid2n.o n2grid.o timer.o \
+ softsym.o getlags.o afc9.o fchisq.o twkfreq.o downsam9.o \
+ peakdt9.o symspec2.o stdmsg.o morse.o azdist.o geodist.o \
+ fillcom.o chkss2.o zplot9.o flat2.o \
+ jt65a.o symspec65.o flat65.o ccf65.o decode65a.o \
+ filbig.o fil6521.o afc65b.o decode65b.o setup65.o \
+ extract.o fchisq65.o demod64a.o chkhist.o interleave63.o ccf2.o \
+ move.o indexx.o graycode65.o twkfreq65.o smo121.o \
+ wrapkarn.o init_rs.o encode_rs.o decode_rs.o gen65.o
+
+libjt9.a: $(OBJS1)
+ ar cr libjt9.a $(OBJS1)
+ ranlib libjt9.a
+
+OBJS2 = jt9.o jt9a.o jt9b.o jt9c.o ipcomm.o sec_midn.o cutil.o
+LIBS2 = -L'c:/QtSDK/Desktop/Qt/4.7.4/mingw/lib' -lQtCore4
+jt9.exe: $(OBJS2) libjt9.a
+ g++ -o jt9.exe $(OBJS2) $(LIBS2) libjt9.a ../libfftw3f_win.a \
+ c:/MinGW/lib/libf95.a
+ cp jt9.exe ../../wsjtx_install
+
+OBJS3 = jt9sim.o
+jt9sim.exe: $(OBJS3) libjt9.a
+ $(FC) -o jt9sim.exe $(OBJS3) libjt9.a
+
+OBJS4 = jt9code.o
+jt9code.exe: $(OBJS4) libjt9.a
+ $(FC) -o jt9code.exe $(OBJS4) libjt9.a
+
+OBJS5 = jt65.o
+jt65.exe: $(OBJS5) libjt9.a
+ $(FC) -o jt65.exe $(OBJS5) libjt9.a ../libfftw3f_win.a
+
+INCPATH = -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include/QtCore' \
+ -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include' \
+ -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include/ActiveQt' \
+ -I'release' -I'.' -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/mkspecs/win32-g++'
+
+sync9.o: sync9.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c sync9.f90
+
+spec9.o: spec9.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c spec9.f90
+
+peakdt9.o: peakdt9.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c peakdt9.f90
+
+jt9sim.o: jt9sim.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c jt9sim.f90
+
+genjt9.o: genjt9.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c genjt9.f90
+
+redsync.o: redsync.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c redsync.f90
+
+unpackmsg.o: unpackmsg.f90
+ $(FC) -c -O0 -fbounds-check -Wall -Wno-precision-loss unpackmsg.f90
+
+ipcomm.o: ipcomm.cpp
+ g++ -c $(INCPATH) ipcomm.cpp
+
+sec_midn.o: sec_midn.f90
+ $(FC) -c -fno-second-underscore sec_midn.f90
+
+#rig_control.o: rig_control.c
+# $(CC) -c -Wall -I..\..\..\hamlib-1.2.15.3\include rig_control.c
+
+tstrig.o: tstrig.c
+ $(CC) -c -Wall -I..\..\..\hamlib-1.2.15.3\include tstrig.c
+
+init_rs.o: init_rs.c
+ $(CC) -c -DBIGSYM=1 -o init_rs.o init_rs.c
+
+encode_rs.o: encode_rs.c
+ $(CC) -c -DBIGSYM=1 -o encode_rs.o encode_rs.c
+
+decode_rs.o: decode_rs.c
+ $(CC) -c -DBIGSYM=1 -o decode_rs.o decode_rs.c
+
+
+.PHONY : clean
+
+clean:
+ rm -f *.o libjt9.a wsjtx.exe jt9sim.exe jt9.exe jt65.exe
diff --git a/lib/Makefile.linux b/lib/Makefile.linux
new file mode 100644
index 00000000..19e6096e
--- /dev/null
+++ b/lib/Makefile.linux
@@ -0,0 +1,104 @@
+CC = gcc
+FC = gfortran
+
+FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion -fno-second-underscore
+CFLAGS = -I. -fbounds-check -mno-stack-arg-probe
+
+# Default rules
+%.o: %.c
+ ${CC} ${CFLAGS} -c $<
+%.o: %.f
+ ${FC} ${FFLAGS} -c $<
+%.o: %.F
+ ${FC} ${FFLAGS} -c $<
+%.o: %.f90
+ ${FC} ${FFLAGS} -c $<
+%.o: %.F90
+ ${FC} ${FFLAGS} -c $<
+
+all: libjt9.a jt9sim jt9 jt9code
+
+OBJS1 = pctile.o graycode.o sort.o ssort.o \
+ unpackmsg.o igray.o unpackcall.o unpackgrid.o \
+ grid2k.o unpacktext.o getpfx2.o packmsg.o deg2grid.o \
+ packtext.o getpfx1.o packcall.o k2grid.o packgrid.o \
+ nchar.o four2a.o grid2deg.o pfxdump.o f77_wisdom.o \
+ symspec.o analytic.o db.o genjt9.o \
+ packbits.o unpackbits.o encode232.o interleave9.o \
+ entail.o fano232.o gran.o sync9.o decode9.o \
+ fil3.o decoder.o grid2n.o n2grid.o timer.o \
+ softsym.o peakdt9.o getlags.o afc9.o fchisq.o \
+ twkfreq.o downsam9.o symspec2.o ipcomm.o sleep_msec.o \
+ stdmsg.o sec_midn.o cutil.o azdist.o geodist.o morse.o \
+ fillcom.o chkss2.o zplot9.o flat2.o \
+ jt65a.o symspec65.o flat65.o ccf65.o decode65a.o \
+ filbig.o fil6521.o afc65b.o decode65b.o setup65.o \
+ extract.o fchisq65.o demod64a.o chkhist.o interleave63.o ccf2.o \
+ move.o indexx.o graycode65.o twkfreq65.o smo121.o \
+ wrapkarn.o init_rs.o encode_rs.o decode_rs.o gen65.o
+
+libjt9.a: $(OBJS1)
+ ar cr libjt9.a $(OBJS1)
+ ranlib libjt9.a
+
+OBJS2 = jt9.o jt9a.o jt9b.o jt9c.o
+
+jt9: $(OBJS2) libjt9.a
+ g++ -o jt9 $(OBJS2) libjt9.a -lfftw3f -lgfortran -lQtCore
+ cp jt9 ../../wsjtx_install
+
+OBJS3 = jt9sim.o
+jt9sim: $(OBJS3) libjt9.a
+ $(FC) -o jt9sim $(OBJS3) libjt9.a
+
+OBJS4 = jt9code.o
+jt9code: $(OBJS4) libjt9.a
+ $(FC) -o jt9code $(OBJS4) libjt9.a
+
+#INCPATH = -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include/QtCore' \
+# -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include' \
+# -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include/ActiveQt' \
+# -I'release' -I'.' -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/mkspecs/win32-g++'
+
+INCPATH = -I'/usr/include/qt4' -I'/usr/include/qt4/QtCore'
+
+#jt9.o: jt9.f90
+# $(FC) -O0 -c jt9.f90
+
+sync9.o: sync9.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c sync9.f90
+
+peakdf9.o: peakdf9.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c peakdf9.f90
+
+peakdt9.o: peakdt9.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c peakdt9.f90
+
+jt9sim.o: jt9sim.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c jt9sim.f90
+
+genjt9.o: genjt9.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c genjt9.f90
+
+redsync.o: redsync.f90 jt9sync.f90
+ $(FC) $(FFLAGS) -c redsync.f90
+
+ipcomm.o: ipcomm.cpp
+ g++ -c $(INCPATH) ipcomm.cpp
+
+sec_midn.o: sec_midn.f90
+ $(FC) -c -fno-second-underscore sec_midn.f90
+
+init_rs.o: init_rs.c
+ $(CC) -c -DBIGSYM=1 -o init_rs.o init_rs.c
+
+encode_rs.o: encode_rs.c
+ $(CC) -c -DBIGSYM=1 -o encode_rs.o encode_rs.c
+
+decode_rs.o: decode_rs.c
+ $(CC) -c -DBIGSYM=1 -o decode_rs.o decode_rs.c
+
+.PHONY : clean
+
+clean:
+ rm -f *.o libjt9.a wsjtx jt9sim jt9 jt9code
diff --git a/lib/afc65b.f90 b/lib/afc65b.f90
new file mode 100644
index 00000000..f78f2752
--- /dev/null
+++ b/lib/afc65b.f90
@@ -0,0 +1,59 @@
+subroutine afc65b(cx,npts,fsample,nflip,a,ccfbest,dtbest)
+
+! Find delta f, f1, f2 ==> a(1:3)
+
+ complex cx(npts)
+ real a(5),deltaa(5)
+
+ a(1)=0.
+ a(2)=0.
+ a(3)=0.
+ a(4)=0.
+ deltaa(1)=2.0
+ deltaa(2)=2.0
+ deltaa(3)=2.0
+ deltaa(4)=0.05
+ nterms=3 !Maybe 2 is enough?
+
+! Start the iteration
+ chisqr=0.
+ chisqr0=1.e6
+ do iter=1,3 !One iteration is enough?
+ do j=1,nterms
+ chisq1=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax)
+ fn=0.
+ delta=deltaa(j)
+10 a(j)=a(j)+delta
+ chisq2=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax)
+ if(chisq2.eq.chisq1) go to 10
+ if(chisq2.gt.chisq1) then
+ delta=-delta !Reverse direction
+ a(j)=a(j)+delta
+ tmp=chisq1
+ chisq1=chisq2
+ chisq2=tmp
+ endif
+20 fn=fn+1.0
+ a(j)=a(j)+delta
+ chisq3=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax)
+ if(chisq3.lt.chisq2) then
+ chisq1=chisq2
+ chisq2=chisq3
+ go to 20
+ endif
+
+! Find minimum of parabola defined by last three points
+ delta=delta*(1./(1.+(chisq1-chisq2)/(chisq3-chisq2))+0.5)
+ a(j)=a(j)-delta
+ deltaa(j)=deltaa(j)*fn/3.
+ enddo
+ chisqr=fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax)
+ if(chisqr/chisqr0.gt.0.9999) go to 30
+ chisqr0=chisqr
+ enddo
+
+30 ccfbest=ccfmax * (1378.125/fsample)**2
+ dtbest=dtmax
+
+ return
+end subroutine afc65b
diff --git a/lib/afc9.f90 b/lib/afc9.f90
new file mode 100644
index 00000000..1fbcf2fa
--- /dev/null
+++ b/lib/afc9.f90
@@ -0,0 +1,58 @@
+subroutine afc9(c3,npts,fsample,a,syncpk)
+
+ complex c3(0:npts-1)
+ real a(3),deltaa(3)
+
+ a(1)=0. !f0
+ a(2)=0. !f1
+ a(3)=0. !f2
+ deltaa(1)=0.2
+ deltaa(2)=0.01
+ deltaa(3)=0.01
+ nterms=3
+
+! Start the iteration
+ chisqr=0.
+ chisqr0=1.e6
+ do iter=1,4 !One iteration is enough?
+ do j=1,nterms
+ chisq1=fchisq(c3,npts,fsample,a)
+ fn=0.
+ delta=deltaa(j)
+10 a(j)=a(j)+delta
+ chisq2=fchisq(c3,npts,fsample,a)
+ if(chisq2.eq.chisq1) go to 10
+ if(chisq2.gt.chisq1) then
+ delta=-delta !Reverse direction
+ a(j)=a(j)+delta
+ tmp=chisq1
+ chisq1=chisq2
+ chisq2=tmp
+ endif
+20 fn=fn+1.0
+ a(j)=a(j)+delta
+ chisq3=fchisq(c3,npts,fsample,a)
+ if(chisq3.lt.chisq2) then
+ chisq1=chisq2
+ chisq2=chisq3
+ go to 20
+ endif
+
+! Find minimum of parabola defined by last three points
+ delta=delta*(1./(1.+(chisq1-chisq2)/(chisq3-chisq2))+0.5)
+ a(j)=a(j)-delta
+ deltaa(j)=deltaa(j)*fn/3.
+! write(*,4000) iter,j,a,deltaa,-chisq2
+!4000 format(i1,i2,6f10.4,f9.3)
+ enddo
+ chisqr=fchisq(c3,npts,fsample,a)
+ if(chisqr/chisqr0.gt.0.9999) exit
+ chisqr0=chisqr
+ enddo
+
+ syncpk=-chisqr
+! write(*,4001) a,deltaa,-chisq2
+!4001 format(3x,6f10.4,f9.3)
+
+ return
+end subroutine afc9
diff --git a/lib/analytic.f90 b/lib/analytic.f90
new file mode 100644
index 00000000..33d5fc74
--- /dev/null
+++ b/lib/analytic.f90
@@ -0,0 +1,25 @@
+subroutine analytic(d,npts,nfft,s,c)
+
+! Convert real data to analytic signal
+
+ parameter (NFFTMAX=128*1024)
+ real d(npts)
+ real s(npts)
+ complex c(NFFTMAX)
+
+ nh=nfft/2
+ fac=2.0/nfft
+ c(1:npts)=fac*d(1:npts)
+ c(npts+1:nfft)=0.
+ call four2a(c,nfft,1,-1,1) !Forward c2c FFT
+
+ do i=1,nh
+ s(i)=real(c(i))**2 + aimag(c(i))**2
+ enddo
+
+ c(1)=0.5*c(1)
+ c(nh+2:nfft)=0.
+ call four2a(c,nfft,1,1,1) !Inverse c2c FFT
+
+ return
+end subroutine analytic
diff --git a/lib/azdist.f90 b/lib/azdist.f90
new file mode 100644
index 00000000..528801f4
--- /dev/null
+++ b/lib/azdist.f90
@@ -0,0 +1,107 @@
+subroutine azdist(MyGrid,HisGrid,utch,nAz,nEl,nDmiles,nDkm,nHotAz,nHotABetter)
+
+ character*6 MyGrid,HisGrid,mygrid0,hisgrid0
+ real*8 utch,utch0
+ logical HotABetter,IamEast
+ real eltab(22),daztab(22)
+ data eltab/18.,15.,13.,11.,9.,8.,7.,6.,5.3,4.7,4.,3.3,2.7, &
+ 2.,1.5,1.,0.8,0.6,0.4,0.2,0.0,0.0/
+ data daztab/21.,18.,16.,15.,14.,13.,12.,11.,10.7,10.3,10., &
+ 10.,10.,10.,10.,10.,10.,9.,9.,9.,8.,8./
+ data mygrid0/" "/,hisgrid0/" "/,utch0/-999.d0/
+ save
+
+ if(MyGrid.eq.HisGrid) then
+ naz=0
+ nel=0
+ ndmiles=0
+ ndkm=0
+ nhotaz=0
+ nhotabetter=1
+ go to 999
+ endif
+
+ if(mygrid.eq.mygrid0 .and. hisgrid.eq.hisgrid0 .and. &
+ abs(utch-utch0).lt.0.1666667d0) go to 900
+ utch0=utch
+ mygrid0=mygrid
+ hisgrid0=hisgrid
+ utchours=utch
+
+ if(MyGrid(5:5).eq.' ') MyGrid(5:5)='m'
+ if(MyGrid(6:6).eq.' ') MyGrid(6:6)='m'
+ if(HisGrid(5:5).eq.' ') HisGrid(5:5)='m'
+ if(HisGrid(6:6).eq.' ') HisGrid(6:6)='m'
+
+ if(MyGrid.eq.HisGrid) then
+ Az=0.
+ Dmiles=0.
+ Dkm=0.0
+ El=0.
+ HotA=0.
+ HotB=0.
+ HotABetter=.true.
+ go to 900
+ endif
+
+ call grid2deg(MyGrid,dlong1,dlat1)
+ call grid2deg(HisGrid,dlong2,dlat2)
+ call geodist(dlat1,dlong1,dlat2,dlong2,Az,Baz,Dkm)
+
+ ndkm=Dkm/100
+ j=ndkm-4
+ if(j.lt.1) j=1
+ if(j.gt.21)j=21
+ if(Dkm.lt.500.0) then
+ El=18.0
+ else
+ u=(Dkm-100.0*ndkm)/100.0
+ El=(1.0-u)*eltab(j) + u*eltab(j+1)
+ endif
+
+ daz=daztab(j) + u * (daztab(j+1)-daztab(j))
+ Dmiles=Dkm/1.609344
+
+ tmid=mod(UTChours-0.5*(dlong1+dlong2)/15.0+48.0,24.0)
+ IamEast=.false.
+ if(dlong1.lt.dlong2) IamEast=.true.
+ if(dlong1.eq.dlong2 .and. dlat1.gt.dlat2) IamEast=.false.
+ azEast=baz
+ if(IamEast) azEast=az
+ if((azEast.ge.45.0 .and. azEast.lt.135.0) .or. &
+ (azEast.ge.225.0 .and. azEast.lt.315.0)) then
+! The path will be taken as "east-west".
+ HotABetter=.true.
+ if(abs(tmid-6.0).lt.6.0) HotABetter=.false.
+ if((dlat1+dlat2)/2.0 .lt. 0.0) HotABetter=.not.HotABetter
+ else
+! The path will be taken as "north-south".
+ HotABetter=.false.
+ if(abs(tmid-12.0).lt.6.0) HotABetter=.true.
+ endif
+ if(IamEast) then
+ HotA = Az - daz
+ HotB = Az + daz
+ else
+ HotA = Az + daz
+ HotB = Az - daz
+ endif
+ if(HotA.lt.0.0) HotA=HotA+360.0
+ if(HotA.gt.360.0) HotA=HotA-360.0
+ if(HotB.lt.0.0) HotB=HotB+360.0
+ if(HotB.gt.360.0) HotB=HotB-360.0
+
+900 continue
+ naz=nint(Az)
+ nel=nint(el)
+ nDmiles=nint(Dmiles)
+ nDkm=nint(Dkm)
+ nHotAz=nint(HotB)
+ nHotABetter=0
+ if(HotABetter) then
+ nHotAz=nint(HotA)
+ nHotABetter=1
+ endif
+
+999 return
+end subroutine azdist
diff --git a/lib/bpskmetrics.dat b/lib/bpskmetrics.dat
new file mode 100644
index 00000000..4073e578
--- /dev/null
+++ b/lib/bpskmetrics.dat
@@ -0,0 +1,256 @@
+ -12.8 1.000 -9.966 1.000000 0.000000
+ -12.7 1.000 -9.966 1.000000 0.000000
+ -12.6 1.000 -9.966 1.000000 0.000000
+ -12.5 1.000 -9.966 1.000000 0.000000
+ -12.4 1.000 -9.966 1.000000 0.000000
+ -12.3 1.000 -9.966 1.000000 0.000000
+ -12.2 1.000 -9.966 1.000000 0.000000
+ -12.1 1.000 -9.966 1.000000 0.000000
+ -12.0 1.000 -9.966 1.000000 0.000000
+ -11.9 1.000 -9.966 1.000000 0.000000
+ -11.8 1.000 -9.966 1.000000 0.000000
+ -11.7 1.000 -9.966 1.000000 0.000000
+ -11.6 1.000 -9.966 1.000000 0.000000
+ -11.5 1.000 -9.966 1.000000 0.000000
+ -11.4 1.000 -9.966 1.000000 0.000000
+ -11.3 1.000 -9.966 1.000000 0.000000
+ -11.2 1.000 -9.966 1.000000 0.000000
+ -11.1 1.000 -9.966 1.000000 0.000000
+ -11.0 1.000 -9.966 1.000000 0.000000
+ -10.9 1.000 -9.966 1.000000 0.000000
+ -10.8 1.000 -9.966 1.000000 0.000000
+ -10.7 1.000 -9.966 1.000000 0.000000
+ -10.6 1.000 -9.966 1.000000 0.000000
+ -10.5 1.000 -9.966 1.000000 0.000000
+ -10.4 1.000 -9.966 1.000000 0.000000
+ -10.3 1.000 -9.966 1.000000 0.000000
+ -10.2 1.000 -9.966 1.000000 0.000000
+ -10.1 1.000 -9.966 1.000000 0.000000
+ -10.0 1.000 -9.966 1.000000 0.000000
+ -9.9 1.000 -9.966 1.000000 0.000000
+ -9.8 1.000 -9.966 1.000000 0.000000
+ -9.7 1.000 -9.966 1.000000 0.000000
+ -9.6 1.000 -9.966 1.000000 0.000000
+ -9.5 1.000 -9.966 1.000000 0.000000
+ -9.4 1.000 -9.966 1.000000 0.000000
+ -9.3 1.000 -9.966 1.000000 0.000000
+ -9.2 1.000 -9.966 1.000000 0.000000
+ -9.1 1.000 -9.966 1.000000 0.000000
+ -9.0 1.000 -9.966 1.000000 0.000000
+ -8.9 1.000 -9.966 1.000000 0.000000
+ -8.8 1.000 -9.966 1.000000 0.000000
+ -8.7 1.000 -9.966 1.000000 0.000000
+ -8.6 1.000 -9.966 1.000000 0.000000
+ -8.5 1.000 -9.966 1.000000 0.000000
+ -8.4 1.000 -9.966 1.000000 0.000000
+ -8.3 1.000 -9.966 1.000000 0.000000
+ -8.2 1.000 -9.966 1.000000 0.000000
+ -8.1 1.000 -9.966 1.000000 0.000000
+ -8.0 1.000 -9.966 1.000000 0.000000
+ -7.9 1.000 -9.966 1.000000 0.000000
+ -7.8 1.000 -9.966 1.000000 0.000000
+ -7.7 1.000 -9.966 1.000000 0.000000
+ -7.6 1.000 -9.966 1.000000 0.000000
+ -7.5 1.000 -9.966 1.000000 0.000000
+ -7.4 1.000 -9.966 1.000000 0.000000
+ -7.3 1.000 -9.966 1.000000 0.000000
+ -7.2 1.000 -9.966 1.000000 0.000000
+ -7.1 1.000 -9.966 1.000000 0.000000
+ -7.0 1.000 -9.966 1.000000 0.000000
+ -6.9 1.000 -9.966 1.000000 0.000000
+ -6.8 1.000 -9.966 1.000000 0.000000
+ -6.7 1.000 -9.966 1.000000 0.000000
+ -6.6 1.000 -9.966 1.000000 0.000000
+ -6.5 1.000 -9.966 1.000000 0.000000
+ -6.4 1.000 -9.966 1.000000 0.000000
+ -6.3 1.000 -9.966 1.000000 0.000000
+ -6.2 1.000 -9.966 1.000000 0.000000
+ -6.1 1.000 -9.966 1.000000 0.000000
+ -6.0 1.000 -9.966 1.000000 0.000000
+ -5.9 1.000 -9.966 1.000000 0.000000
+ -5.8 1.000 -9.966 1.000000 0.000000
+ -5.7 1.000 -9.966 1.000000 0.000000
+ -5.6 1.000 -9.966 1.000000 0.000000
+ -5.5 1.000 -9.966 1.000000 0.000000
+ -5.4 1.000 -9.966 1.000000 0.000000
+ -5.3 1.000 -9.966 1.000000 0.000000
+ -5.2 1.000 -9.966 1.000000 0.000000
+ -5.1 1.000 -9.966 1.000000 0.000000
+ -5.0 1.000 -9.966 1.000000 0.000000
+ -4.9 1.000 -9.966 1.000000 0.000000
+ -4.8 1.000 -9.966 1.000000 0.000000
+ -4.7 1.000 -9.966 1.000000 0.000000
+ -4.6 1.000 -9.966 1.000000 0.000000
+ -4.5 1.000 -9.966 1.000000 0.000000
+ -4.4 1.000 -9.966 1.000000 0.000000
+ -4.3 1.000 -9.966 1.000000 0.000000
+ -4.2 1.000 -9.966 1.000000 0.000000
+ -4.1 1.000 -9.966 1.000000 0.000000
+ -4.0 1.000 -9.966 1.000000 0.000000
+ -3.9 1.000 -9.966 1.000000 0.000000
+ -3.8 1.000 -9.966 1.000000 0.000000
+ -3.7 1.000 -9.966 1.000000 0.000000
+ -3.6 1.000 -9.966 1.000000 0.000000
+ -3.5 1.000 -9.966 1.000000 0.000000
+ -3.4 1.000 -9.966 1.000000 0.000000
+ -3.3 1.000 -9.966 1.000000 0.000000
+ -3.2 1.000 -9.966 1.000000 0.000000
+ -3.1 1.000 -9.966 1.000000 0.000000
+ -3.0 1.000 -9.966 1.000000 0.000000
+ -2.9 1.000 -9.966 1.000000 0.000000
+ -2.8 1.000 -9.966 0.999955 0.000045
+ -2.7 1.000 -9.966 0.999968 0.000032
+ -2.6 1.000 -9.966 0.999909 0.000091
+ -2.5 1.000 -9.966 0.999983 0.000017
+ -2.4 1.000 -9.966 0.999937 0.000063
+ -2.3 1.000 -9.966 0.999914 0.000086
+ -2.2 1.000 -9.966 0.999813 0.000187
+ -2.1 1.000 -9.966 0.999775 0.000225
+ -2.0 1.000 -9.966 0.999671 0.000329
+ -1.9 0.999 -9.966 0.999531 0.000469
+ -1.8 0.999 -9.308 0.999211 0.000789
+ -1.7 0.998 -8.893 0.998948 0.001052
+ -1.6 0.998 -8.191 0.998290 0.001710
+ -1.5 0.996 -7.655 0.997519 0.002481
+ -1.4 0.994 -7.037 0.996192 0.003808
+ -1.3 0.992 -6.513 0.994525 0.005475
+ -1.2 0.988 -5.931 0.991804 0.008196
+ -1.1 0.982 -5.359 0.987816 0.012184
+ -1.0 0.974 -4.789 0.981916 0.018084
+ -0.9 0.961 -4.217 0.973110 0.026890
+ -0.8 0.942 -3.672 0.960785 0.039215
+ -0.7 0.915 -3.123 0.942613 0.057387
+ -0.6 0.874 -2.582 0.916477 0.083523
+ -0.5 0.816 -2.062 0.880296 0.119704
+ -0.4 0.734 -1.573 0.831905 0.168095
+ -0.3 0.619 -1.109 0.768168 0.231832
+ -0.2 0.465 -0.690 0.690103 0.309897
+ -0.1 0.260 -0.317 0.598759 0.401241
+ 0.0 0.000 0.000 0.500000 0.500000
+ 0.1 -0.317 0.260 0.401241 0.598759
+ 0.2 -0.690 0.465 0.309897 0.690103
+ 0.3 -1.109 0.619 0.231832 0.768168
+ 0.4 -1.573 0.734 0.168095 0.831905
+ 0.5 -2.062 0.816 0.119704 0.880296
+ 0.6 -2.582 0.874 0.083523 0.916477
+ 0.7 -3.123 0.915 0.057387 0.942613
+ 0.8 -3.672 0.942 0.039215 0.960785
+ 0.9 -4.217 0.961 0.026890 0.973110
+ 1.0 -4.789 0.974 0.018084 0.981916
+ 1.1 -5.359 0.982 0.012184 0.987816
+ 1.2 -5.931 0.988 0.008196 0.991804
+ 1.3 -6.513 0.992 0.005475 0.994525
+ 1.4 -7.037 0.994 0.003808 0.996192
+ 1.5 -7.655 0.996 0.002481 0.997519
+ 1.6 -8.191 0.998 0.001710 0.998290
+ 1.7 -8.893 0.998 0.001052 0.998948
+ 1.8 -9.308 0.999 0.000789 0.999211
+ 1.9 -9.966 0.999 0.000469 0.999531
+ 2.0 -9.966 1.000 0.000329 0.999671
+ 2.1 -9.966 1.000 0.000225 0.999775
+ 2.2 -9.966 1.000 0.000187 0.999813
+ 2.3 -9.966 1.000 0.000086 0.999914
+ 2.4 -9.966 1.000 0.000063 0.999937
+ 2.5 -9.966 1.000 0.000017 0.999983
+ 2.6 -9.966 1.000 0.000091 0.999909
+ 2.7 -9.966 1.000 0.000032 0.999968
+ 2.8 -9.966 1.000 0.000045 0.999955
+ 2.9 -9.966 1.000 0.000000 1.000000
+ 3.0 -9.966 1.000 0.000000 1.000000
+ 3.1 -9.966 1.000 0.000000 1.000000
+ 3.2 -9.966 1.000 0.000000 1.000000
+ 3.3 -9.966 1.000 0.000000 1.000000
+ 3.4 -9.966 1.000 0.000000 1.000000
+ 3.5 -9.966 1.000 0.000000 1.000000
+ 3.6 -9.966 1.000 0.000000 1.000000
+ 3.7 -9.966 1.000 0.000000 1.000000
+ 3.8 -9.966 1.000 0.000000 1.000000
+ 3.9 -9.966 1.000 0.000000 1.000000
+ 4.0 -9.966 1.000 0.000000 1.000000
+ 4.1 -9.966 1.000 0.000000 1.000000
+ 4.2 -9.966 1.000 0.000000 1.000000
+ 4.3 -9.966 1.000 0.000000 1.000000
+ 4.4 -9.966 1.000 0.000000 1.000000
+ 4.5 -9.966 1.000 0.000000 1.000000
+ 4.6 -9.966 1.000 0.000000 1.000000
+ 4.7 -9.966 1.000 0.000000 1.000000
+ 4.8 -9.966 1.000 0.000000 1.000000
+ 4.9 -9.966 1.000 0.000000 1.000000
+ 5.0 -9.966 1.000 0.000000 1.000000
+ 5.1 -9.966 1.000 0.000000 1.000000
+ 5.2 -9.966 1.000 0.000000 1.000000
+ 5.3 -9.966 1.000 0.000000 1.000000
+ 5.4 -9.966 1.000 0.000000 1.000000
+ 5.5 -9.966 1.000 0.000000 1.000000
+ 5.6 -9.966 1.000 0.000000 1.000000
+ 5.7 -9.966 1.000 0.000000 1.000000
+ 5.8 -9.966 1.000 0.000000 1.000000
+ 5.9 -9.966 1.000 0.000000 1.000000
+ 6.0 -9.966 1.000 0.000000 1.000000
+ 6.1 -9.966 1.000 0.000000 1.000000
+ 6.2 -9.966 1.000 0.000000 1.000000
+ 6.3 -9.966 1.000 0.000000 1.000000
+ 6.4 -9.966 1.000 0.000000 1.000000
+ 6.5 -9.966 1.000 0.000000 1.000000
+ 6.6 -9.966 1.000 0.000000 1.000000
+ 6.7 -9.966 1.000 0.000000 1.000000
+ 6.8 -9.966 1.000 0.000000 1.000000
+ 6.9 -9.966 1.000 0.000000 1.000000
+ 7.0 -9.966 1.000 0.000000 1.000000
+ 7.1 -9.966 1.000 0.000000 1.000000
+ 7.2 -9.966 1.000 0.000000 1.000000
+ 7.3 -9.966 1.000 0.000000 1.000000
+ 7.4 -9.966 1.000 0.000000 1.000000
+ 7.5 -9.966 1.000 0.000000 1.000000
+ 7.6 -9.966 1.000 0.000000 1.000000
+ 7.7 -9.966 1.000 0.000000 1.000000
+ 7.8 -9.966 1.000 0.000000 1.000000
+ 7.9 -9.966 1.000 0.000000 1.000000
+ 8.0 -9.966 1.000 0.000000 1.000000
+ 8.1 -9.966 1.000 0.000000 1.000000
+ 8.2 -9.966 1.000 0.000000 1.000000
+ 8.3 -9.966 1.000 0.000000 1.000000
+ 8.4 -9.966 1.000 0.000000 1.000000
+ 8.5 -9.966 1.000 0.000000 1.000000
+ 8.6 -9.966 1.000 0.000000 1.000000
+ 8.7 -9.966 1.000 0.000000 1.000000
+ 8.8 -9.966 1.000 0.000000 1.000000
+ 8.9 -9.966 1.000 0.000000 1.000000
+ 9.0 -9.966 1.000 0.000000 1.000000
+ 9.1 -9.966 1.000 0.000000 1.000000
+ 9.2 -9.966 1.000 0.000000 1.000000
+ 9.3 -9.966 1.000 0.000000 1.000000
+ 9.4 -9.966 1.000 0.000000 1.000000
+ 9.5 -9.966 1.000 0.000000 1.000000
+ 9.6 -9.966 1.000 0.000000 1.000000
+ 9.7 -9.966 1.000 0.000000 1.000000
+ 9.8 -9.966 1.000 0.000000 1.000000
+ 9.9 -9.966 1.000 0.000000 1.000000
+ 10.0 -9.966 1.000 0.000000 1.000000
+ 10.1 -9.966 1.000 0.000000 1.000000
+ 10.2 -9.966 1.000 0.000000 1.000000
+ 10.3 -9.966 1.000 0.000000 1.000000
+ 10.4 -9.966 1.000 0.000000 1.000000
+ 10.5 -9.966 1.000 0.000000 1.000000
+ 10.6 -9.966 1.000 0.000000 1.000000
+ 10.7 -9.966 1.000 0.000000 1.000000
+ 10.8 -9.966 1.000 0.000000 1.000000
+ 10.9 -9.966 1.000 0.000000 1.000000
+ 11.0 -9.966 1.000 0.000000 1.000000
+ 11.1 -9.966 1.000 0.000000 1.000000
+ 11.2 -9.966 1.000 0.000000 1.000000
+ 11.3 -9.966 1.000 0.000000 1.000000
+ 11.4 -9.966 1.000 0.000000 1.000000
+ 11.5 -9.966 1.000 0.000000 1.000000
+ 11.6 -9.966 1.000 0.000000 1.000000
+ 11.7 -9.966 1.000 0.000000 1.000000
+ 11.8 -9.966 1.000 0.000000 1.000000
+ 11.9 -9.966 1.000 0.000000 1.000000
+ 12.0 -9.966 1.000 0.000000 1.000000
+ 12.1 -9.966 1.000 0.000000 1.000000
+ 12.2 -9.966 1.000 0.000000 1.000000
+ 12.3 -9.966 1.000 0.000000 1.000000
+ 12.4 -9.966 1.000 0.000000 1.000000
+ 12.5 -9.966 1.000 0.000000 1.000000
+ 12.6 -9.966 1.000 0.000000 1.000000
+ 12.7 -9.966 1.000 0.000000 1.000000
diff --git a/lib/ccf2.f90 b/lib/ccf2.f90
new file mode 100644
index 00000000..4e74a52e
--- /dev/null
+++ b/lib/ccf2.f90
@@ -0,0 +1,45 @@
+subroutine ccf2(ss,nz,nflip,ccfbest,lagpk)
+
+ parameter (LAGMAX=60)
+! parameter (LAGMAX=200)
+ real ss(nz)
+ real ccf(-LAGMAX:LAGMAX)
+ integer npr(126)
+
+! The JT65 pseudo-random sync pattern:
+ data npr/ &
+ 1,0,0,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0, &
+ 0,1,0,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,1,1, &
+ 0,1,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1, &
+ 0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,1, &
+ 1,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1, &
+ 0,1,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1, &
+ 1,1,1,1,1,1/
+ save
+
+ ccfbest=0.
+ lag1=-LAGMAX
+ lag2=LAGMAX
+ do lag=lag1,lag2
+ s0=0.
+ s1=0.
+ do i=1,126
+ j=2*(8*i + 43) + lag
+ if(j.ge.1 .and. j.le.nz-8) then
+ x=ss(j)+ss(j+8) !Add two half-symbol contributions
+ if(npr(i).eq.0) then
+ s0=s0 + x
+ else
+ s1=s1 + x
+ endif
+ endif
+ enddo
+ ccf(lag)=nflip*(s1-s0)
+ if(ccf(lag).gt.ccfbest) then
+ ccfbest=ccf(lag)
+ lagpk=lag
+ endif
+ enddo
+
+ return
+end subroutine ccf2
diff --git a/lib/ccf65.f90 b/lib/ccf65.f90
new file mode 100644
index 00000000..9e667df8
--- /dev/null
+++ b/lib/ccf65.f90
@@ -0,0 +1,117 @@
+subroutine ccf65(ss,nhsym,ssmax,sync1,dt1,flipk,syncshort,snr2,dt2)
+
+ parameter (NFFT=512,NH=NFFT/2)
+ real ss(322) !Input: half-symbol normalized powers
+ real s(NFFT) !CCF = ss*pr
+ complex cs(0:NH) !Complex FT of s
+ real s2(NFFT) !CCF = ss*pr2
+ complex cs2(0:NH) !Complex FT of s2
+ real pr(NFFT) !JT65 pseudo-random sync pattern
+ complex cpr(0:NH) !Complex FT of pr
+ real pr2(NFFT) !JT65 shorthand pattern
+ complex cpr2(0:NH) !Complex FT of pr2
+ real tmp1(322)
+ real ccf(-11:54)
+ logical first
+ integer npr(126)
+ data first/.true./
+ equivalence (s,cs),(pr,cpr),(s2,cs2),(pr2,cpr2)
+ save
+
+! The JT65 pseudo-random sync pattern:
+ data npr/ &
+ 1,0,0,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0, &
+ 0,1,0,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,1,1, &
+ 0,1,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1, &
+ 0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,1, &
+ 1,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1, &
+ 0,1,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1, &
+ 1,1,1,1,1,1/
+
+ if(first) then
+! Initialize pr, pr2; compute cpr, cpr2.
+ fac=1.0/NFFT
+ do i=1,NFFT
+ pr(i)=0.
+ pr2(i)=0.
+ k=2*mod((i-1)/8,2)-1
+ if(i.le.NH) pr2(i)=fac*k
+ enddo
+ do i=1,126
+ j=2*i
+ pr(j)=fac*(2*npr(i)-1)
+! Not sure why, but it works significantly better without the following line:
+! pr(j-1)=pr(j)
+ enddo
+ call four2a(cpr,NFFT,1,-1,0)
+ call four2a(cpr2,NFFT,1,-1,0)
+ first=.false.
+ endif
+
+! Look for JT65 sync pattern and shorthand square-wave pattern.
+ ccfbest=0.
+ ccfbest2=0.
+ do i=1,nhsym-1
+ s(i)=min(ssmax,ss(i)+ss(i+1))
+! s(i)=ss(i)+ss(i+1)
+ enddo
+
+ call pctile(s,nhsym-1,50,base)
+ s(1:nhsym-1)=s(1:nhsym-1)-base
+ s(nhsym:NFFT)=0.
+ call four2a(cs,NFFT,1,-1,0) !Real-to-complex FFT
+ do i=0,NH
+! cs2(i)=cs(i)*conjg(cpr2(i)) !Mult by complex FFT of pr2
+ cs(i)=cs(i)*conjg(cpr(i)) !Mult by complex FFT of pr
+ enddo
+ call four2a(cs,NFFT,1,1,-1) !Complex-to-real inv-FFT
+! call four2a(cs2,NFFT,1,1,-1) !Complex-to-real inv-FFT
+
+ do lag=-11,54 !Check for best JT65 sync
+ j=lag
+ if(j.lt.1) j=j+NFFT
+ ccf(lag)=s(j)
+! if(abs(ccf(lag)).gt.ccfbest) then
+ if(ccf(lag).gt.ccfbest) then !No inverted sync for use at HF
+! ccfbest=abs(ccf(lag))
+ ccfbest=ccf(lag)
+ lagpk=lag
+ flipk=1.0
+! if(ccf(lag).lt.0.0) flipk=-1.0
+ endif
+ enddo
+
+! do lag=-11,54 !Check for best shorthand
+! ccf2=s2(lag+28)
+! if(ccf2.gt.ccfbest2) then
+! ccfbest2=ccf2
+! lagpk2=lag
+! endif
+! enddo
+
+! Find rms level on baseline of "ccfblue", for normalization.
+ sum=0.
+ do lag=-11,54
+ if(abs(lag-lagpk).gt.1) sum=sum + ccf(lag)
+ enddo
+ base=sum/50.0
+ sq=0.
+ do lag=-11,54
+ if(abs(lag-lagpk).gt.1) sq=sq + (ccf(lag)-base)**2
+ enddo
+ rms=sqrt(sq/49.0)
+ sync1=ccfbest/rms - 4.0
+ dt1=lagpk*(2048.0/11025.0) - 2.5
+
+! Find base level for normalizing snr2.
+ do i=1,nhsym
+ tmp1(i)=ss(i)
+ enddo
+ call pctile(tmp1,nhsym,40,base)
+ snr2=0.398107*ccfbest2/base !### empirical
+ syncshort=0.5*ccfbest2/rms - 4.0 !### better normalizer than rms?
+! dt2=(2.5 + lagpk2*(2048.0/11025.0))
+ dt2=0.
+
+ return
+end subroutine ccf65
diff --git a/lib/char.h b/lib/char.h
new file mode 100644
index 00000000..cc477ec7
--- /dev/null
+++ b/lib/char.h
@@ -0,0 +1,57 @@
+/* Include file to configure the RS codec for character symbols
+ *
+ * Copyright 2002, Phil Karn, KA9Q
+ * May be used under the terms of the GNU General Public License (GPL)
+ */
+#define DTYPE unsigned char
+
+/* Reed-Solomon codec control block */
+struct rs {
+ int mm; /* Bits per symbol */
+ int nn; /* Symbols per block (= (1<<mm)-1) */
+ DTYPE *alpha_to; /* log lookup table */
+ DTYPE *index_of; /* Antilog lookup table */
+ DTYPE *genpoly; /* Generator polynomial */
+ int nroots; /* Number of generator roots = number of parity symbols */
+ int fcr; /* First consecutive root, index form */
+ int prim; /* Primitive element, index form */
+ int iprim; /* prim-th root of 1, index form */
+ int pad; /* Padding bytes in shortened block */
+};
+
+static inline int modnn(struct rs *rs,int x){
+ while (x >= rs->nn) {
+ x -= rs->nn;
+ x = (x >> rs->mm) + (x & rs->nn);
+ }
+ return x;
+}
+#define MODNN(x) modnn(rs,x)
+
+#define MM (rs->mm)
+#define NN (rs->nn)
+#define ALPHA_TO (rs->alpha_to)
+#define INDEX_OF (rs->index_of)
+#define GENPOLY (rs->genpoly)
+#define NROOTS (rs->nroots)
+#define FCR (rs->fcr)
+#define PRIM (rs->prim)
+#define IPRIM (rs->iprim)
+#define PAD (rs->pad)
+#define A0 (NN)
+
+#define ENCODE_RS encode_rs_char
+#define DECODE_RS decode_rs_char
+#define INIT_RS init_rs_char
+#define FREE_RS free_rs_char
+
+void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity);
+int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras);
+void *INIT_RS(int symsize,int gfpoly,int fcr,
+ int prim,int nroots,int pad);
+void FREE_RS(void *p);
+
+
+
+
+
diff --git a/lib/chkhist.f90 b/lib/chkhist.f90
new file mode 100644
index 00000000..6aa4a807
--- /dev/null
+++ b/lib/chkhist.f90
@@ -0,0 +1,21 @@
+subroutine chkhist(mrsym,nmax,ipk)
+
+ integer mrsym(63)
+ integer hist(0:63)
+
+ hist=0
+ do j=1,63
+ i=mrsym(j)
+ hist(i)=hist(i)+1
+ enddo
+
+ nmax=0
+ do i=0,63
+ if(hist(i).gt.nmax) then
+ nmax=hist(i)
+ ipk=i+1
+ endif
+ enddo
+
+ return
+end subroutine chkhist
diff --git a/lib/chkmsg.f90 b/lib/chkmsg.f90
new file mode 100644
index 00000000..ade13bc5
--- /dev/null
+++ b/lib/chkmsg.f90
@@ -0,0 +1,31 @@
+subroutine chkmsg(message,cok,nspecial,flip)
+
+ character message*22,cok*3
+
+ nspecial=0
+ flip=1.0
+ cok=" "
+
+ do i=22,1,-1
+ if(message(i:i).ne.' ') go to 10
+ enddo
+ i=22
+
+10 if(i.ge.11) then
+ if((message(i-3:i).eq.' OOO') .or. (message(20:22).eq.' OO')) then
+ cok='OOO'
+ flip=-1.0
+ if(message(20:22).eq.' OO') then
+ message=message(1:19)
+ else
+ message=message(1:i-4)
+ endif
+ endif
+ endif
+
+ if(message(1:2).eq.'RO') nspecial=2
+ if(message(1:3).eq.'RRR') nspecial=3
+ if(message(1:2).eq.'73') nspecial=4
+
+ return
+end subroutine chkmsg
diff --git a/lib/chkss2.f90 b/lib/chkss2.f90
new file mode 100644
index 00000000..12b2a2e2
--- /dev/null
+++ b/lib/chkss2.f90
@@ -0,0 +1,24 @@
+subroutine chkss2(ss2,freq,drift,schk)
+
+ real ss2(0:8,85)
+ real s(0:8,85)
+ real s1(0:5)
+ include 'jt9sync.f90'
+
+ ave=sum(ss2)/(9*85)
+ if(freq+drift.eq.-999999.0) ave=0. !To silence compiler warning
+ s=ss2/ave-1.0
+
+! call zplot9(s,freq,drift)
+ s1=0.
+ do lag=0,5
+ do i=1,16
+ j=ii(i)+lag
+ if(j.le.85) s1(lag)=s1(lag) + s(0,j)
+ enddo
+ enddo
+ schk=s1(0)/16.0
+
+ return
+end subroutine chkss2
+
diff --git a/lib/constants.f90 b/lib/constants.f90
new file mode 100644
index 00000000..2acf6bbd
--- /dev/null
+++ b/lib/constants.f90
@@ -0,0 +1,5 @@
+ parameter (NTMAX=120)
+ parameter (NMAX=NTMAX*12000) !Total sample intervals per 30 minutes
+ parameter (NDMAX=NTMAX*1500) !Sample intervals at 1500 Hz rate
+ parameter (NSMAX=6827) !Max length of saved spectra
+ parameter (MAXFFT3=16384)
diff --git a/lib/conv232.f90 b/lib/conv232.f90
new file mode 100644
index 00000000..3a347e1d
--- /dev/null
+++ b/lib/conv232.f90
@@ -0,0 +1,38 @@
+! Layland-Lushbaugh polynomials for a K=32, r=1/2 convolutional code,
+! and 8-bit parity lookup table.
+
+ data npoly1/-221228207/,npoly2/-463389625/
+ integer*1 partab(0:255)
+ data partab/ &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 0, 1, 1, 0, 1, 0, 0, 1, &
+ 1, 0, 0, 1, 0, 1, 1, 0/
diff --git a/lib/cutil.c b/lib/cutil.c
new file mode 100644
index 00000000..69a526b0
--- /dev/null
+++ b/lib/cutil.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+// #include <sys/times.h>
+// #include <time.h>
+// #include <sys/time.h>
+#include "sleep.h"
+#include "timeval.h"
+
+/* FORTRAN: fd = close(filedes) */
+int close_(int *filedes)
+{
+return(close(*filedes));
+}
+/* FORTRAN: fd = open(filnam,mode) */
+int open_(char filnam[], int *mode)
+{
+ return(open(filnam,*mode));
+}
+/* FORTRAN: fd = creat(filnam,mode) */
+int creat_(char filnam[],int *mode)
+{
+ return(creat(filnam,*mode));
+}
+/* FORTRAN: nread = read(fd,buf,n) */
+int read_(int *fd, char buf[], int *n)
+{
+ return(read(*fd,buf,*n));
+}
+/* FORTRAN: nwrt = write(fd,buf,n) */
+int write_(int *fd, char buf[], int *n)
+{
+ return(write(*fd,buf,*n));
+}
+/* FORTRAN: ns = lseek(fd,offset,origin) */
+int lseek_(int *fd,int *offset, int *origin)
+{
+ return(lseek(*fd,*offset,*origin));
+}
+/* times(2) */
+//int times_(struct tms *buf)
+//{
+// return (times(buf));
+//}
+/* ioperm(2) */
+//ioperm_(from,num,turn_on)
+//unsigned long *from,*num,*turn_on;
+//{
+// return (ioperm(*from,*num,*turn_on));
+// return (i386_get_ioperm(*from,*num,*turn_on));
+//}
+
+/* usleep(3) */
+void usleep_(unsigned long *microsec)
+{
+ usleep(*microsec);
+}
+
+/* returns random numbers between 0 and 32767 to FORTRAN program */
+int iran_(int *arg)
+{
+ return (rand());
+}
+
+int exit_(int *n)
+{
+ printf("\n\n");
+ exit(*n);
+}
+
+/*
+struct tm *
+gmtime_r_(const time_t *clock, struct tm *result)
+{
+ gmtime_r(clock, result);
+}
+*/
+
+time_t time_(void)
+{
+ return time(0);
+}
+
+/* hrtime() */
+double hrtime_(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return(tv.tv_sec+1.e-6*tv.tv_usec);
+}
diff --git a/lib/db.f90 b/lib/db.f90
new file mode 100644
index 00000000..aa58f43f
--- /dev/null
+++ b/lib/db.f90
@@ -0,0 +1,5 @@
+real function db(x)
+ db=-99.0
+ if(x.gt.1.259e-10) db=10.0*log10(x)
+ return
+end function db
diff --git a/lib/decode65a.f90 b/lib/decode65a.f90
new file mode 100644
index 00000000..ea61d359
--- /dev/null
+++ b/lib/decode65a.f90
@@ -0,0 +1,95 @@
+subroutine decode65a(dd,npts,newdat,f0,nflip,mode65,sync2,a,dt, &
+ nbmkv,nhist,decoded)
+
+! Apply AFC corrections to a candidate JT65 signal, then decode it.
+
+ parameter (NMAX=60*12000) !Samples per 60 s
+ real*4 dd(NMAX) !92 MB: raw data from Linrad timf2
+ complex cx(NMAX/8) !Data at 1378.125 samples/s
+ complex c5x(NMAX/32) !Data at 344.53125 Hz
+ complex c5a(512)
+ real s2(66,126)
+ real a(5)
+ logical first
+ character decoded*22
+ data first/.true./,jjjmin/1000/,jjjmax/-1000/
+ data nhz0/-9999999/
+ save
+
+! Mix sync tone to baseband, low-pass filter, downsample to 1378.125 Hz
+ dt00=dt
+ call timer('filbig ',0)
+ call filbig(dd,npts,f0,newdat,cx,n5,sq0)
+ call timer('filbig ',1)
+
+! NB: cx has sample rate 12000*77125/672000 = 1378.125 Hz
+
+! Find best DF, f1, f2, and DT. Start by downsampling to 344.53125 Hz
+ call timer('fil6521 ',0)
+! Add some zeros at start of c5 arrays -- empirical fix for negative DT's
+ nadd=1089
+ c5x(:nadd)=0.
+ call fil6521(cx,n5,c5x(nadd+1),n6)
+ n6=n6+nadd
+ call timer('fil6521 ',1)
+
+ fsample=1378.125/4.
+ a(5)=dt00
+ i0=nint((a(5)+0.5)*fsample) - 2 + nadd
+ if(i0.lt.1) then
+! write(23,*) 'i0 too small in decode1a:',i0,f0,a(5),fsample,nadd
+! flush(23)
+ i0=1
+ endif
+ nz=n6+1-i0
+
+! We're looking only at sync tone here... so why not downsample by another
+! factor of 1/8, say? Should be a significant execution speed-up.
+ call timer('afc65b ',0)
+! Best fit for DF, f1, and f2
+ call afc65b(c5x(i0),nz,fsample,nflip,a,ccfbest,dtbest)
+ call timer('afc65b ',1)
+
+ sync2=3.7e-4*ccfbest/sq0 !Constant is empirical
+
+! Apply AFC corrections to the time-domain signal
+! Now we are back to using the 1378.125 Hz sample rate, enough to
+! accommodate the full JT65C bandwidth.
+
+ call timer('twkfreq ',0)
+ call twkfreq65(cx,n5,a)
+ call timer('twkfreq ',1)
+
+! Compute spectrum for each half symbol.
+! Adding or subtracting a small number (e.g., 5) to j may make it decode.\
+! NB: might want to try computing full-symbol spectra (nfft=512, even for
+! submodes B and C).
+
+ nsym=126
+ nfft=512
+ j=(dt00+dtbest+2.685)*1378.125
+ if(j.lt.0) j=0
+
+ call timer('sh_ffts ',0)
+ do k=1,nsym
+ do i=1,nfft
+ j=j+1
+ c5a(i)=cx(j)
+ enddo
+ call four2a(c5a,nfft,1,1,1)
+ do i=1,66
+ jj=i
+ if(mode65.eq.2) jj=2*i-1
+ if(mode65.eq.4) jj=4*i-3
+ s2(i,k)=real(c5a(jj))**2 + aimag(c5a(jj))**2
+ enddo
+ enddo
+ call timer('sh_ffts ',1)
+
+ call timer('dec65b ',0)
+ call decode65b(s2,nflip,mode65,nbmkv,nhist,decoded)
+ dt=dt00 + dtbest + 1.7
+ call timer('dec65b ',1)
+
+ return
+end subroutine decode65a
diff --git a/lib/decode65b.f90 b/lib/decode65b.f90
new file mode 100644
index 00000000..729a218e
--- /dev/null
+++ b/lib/decode65b.f90
@@ -0,0 +1,36 @@
+subroutine decode65b(s2,nflip,mode65,nbmkv,nhist,decoded)
+
+ real s2(66,126)
+ real s3(64,63)
+ logical first,ltext
+ character decoded*22
+ common/prcom/pr(126),mdat(126),mref(126,2),mdat2(126),mref2(126,2)
+ data first/.true./
+ save
+
+ if(first) call setup65
+ first=.false.
+
+ do j=1,63
+ k=mdat(j) !Points to data symbol
+ if(nflip.lt.0) k=mdat2(j)
+ do i=1,64
+ s3(i,j)=s2(i+2,k)
+ enddo
+ k=mdat2(j) !Points to data symbol
+ if(nflip.lt.0) k=mdat(j)
+ enddo
+
+ nadd=mode65
+ call extract(s3,nadd,ncount,nhist,decoded,ltext,nbmkv) !Extract the message
+! Suppress "birdie messages" and other garbage decodes:
+ if(decoded(1:7).eq.'000AAA ') ncount=-1
+ if(decoded(1:7).eq.'0L6MWK ') ncount=-1
+ if(nflip.lt.0 .and. ltext) ncount=-1
+ if(ncount.lt.0) then
+ nbmkv=0
+ decoded=' '
+ endif
+
+ return
+end subroutine decode65b
diff --git a/lib/decode9.f90 b/lib/decode9.f90
new file mode 100644
index 00000000..06809eb7
--- /dev/null
+++ b/lib/decode9.f90
@@ -0,0 +1,85 @@
+subroutine decode9(i1SoftSymbols,limit,nlim,msg)
+
+! Decoder for JT9
+! Input: i1SoftSymbols(207) - Single-bit soft symbols
+! Output: msg - decoded message (blank if erasure)
+
+ character*22 msg
+ integer*4 i4DecodedBytes(9)
+ integer*4 i4Decoded6BitWords(12)
+ integer*1 i1DecodedBytes(13) !72 bits and zero tail as 8-bit bytes
+ integer*1 i1SoftSymbols(207)
+ integer*1 i1DecodedBits(72)
+
+ real*4 xx0(0:255)
+
+ logical first
+ integer*4 mettab(0:255,0:1)
+ data first/.true./
+ data xx0/ & !Metric table
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 0.988, 1.000, 0.991, 0.993, 1.000, 0.995, 1.000, 0.991, &
+ 1.000, 0.991, 0.992, 0.991, 0.990, 0.990, 0.992, 0.996, &
+ 0.990, 0.994, 0.993, 0.991, 0.992, 0.989, 0.991, 0.987, &
+ 0.985, 0.989, 0.984, 0.983, 0.979, 0.977, 0.971, 0.975, &
+ 0.974, 0.970, 0.970, 0.970, 0.967, 0.962, 0.960, 0.957, &
+ 0.956, 0.953, 0.942, 0.946, 0.937, 0.933, 0.929, 0.920, &
+ 0.917, 0.911, 0.903, 0.895, 0.884, 0.877, 0.869, 0.858, &
+ 0.846, 0.834, 0.821, 0.806, 0.790, 0.775, 0.755, 0.737, &
+ 0.713, 0.691, 0.667, 0.640, 0.612, 0.581, 0.548, 0.510, &
+ 0.472, 0.425, 0.378, 0.328, 0.274, 0.212, 0.146, 0.075, &
+ 0.000,-0.079,-0.163,-0.249,-0.338,-0.425,-0.514,-0.606, &
+ -0.706,-0.796,-0.895,-0.987,-1.084,-1.181,-1.280,-1.376, &
+ -1.473,-1.587,-1.678,-1.790,-1.882,-1.992,-2.096,-2.201, &
+ -2.301,-2.411,-2.531,-2.608,-2.690,-2.829,-2.939,-3.058, &
+ -3.164,-3.212,-3.377,-3.463,-3.550,-3.768,-3.677,-3.975, &
+ -4.062,-4.098,-4.186,-4.261,-4.472,-4.621,-4.623,-4.608, &
+ -4.822,-4.870,-4.652,-4.954,-5.108,-5.377,-5.544,-5.995, &
+ -5.632,-5.826,-6.304,-6.002,-6.559,-6.369,-6.658,-7.016, &
+ -6.184,-7.332,-6.534,-6.152,-6.113,-6.288,-6.426,-6.313, &
+ -9.966,-6.371,-9.966,-7.055,-9.966,-6.629,-6.313,-9.966, &
+ -5.858,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966/
+ save
+
+ if(first) then
+! Get the metric table
+ bias=0.5
+ scale=10
+ do i=0,255
+ mettab(i,0)=nint(scale*(xx0(i)-bias))
+ if(i.ge.1) mettab(256-i,1)=mettab(i,0)
+ enddo
+ first=.false.
+ endif
+
+ msg=' '
+ nbits=72
+ ndelta=17
+ call fano232(i1SoftSymbols,nbits+31,mettab,ndelta,limit,i1DecodedBytes, &
+ ncycles,metric,ierr)
+
+ nlim=ncycles/(nbits+31)
+ if(ncycles.lt.(nbits*limit)) then
+ nbytes=(nbits+7)/8
+ do i=1,nbytes
+ n=i1DecodedBytes(i)
+ i4DecodedBytes(i)=iand(n,255)
+ enddo
+ call unpackbits(i4DecodedBytes,nbytes,8,i1DecodedBits)
+ call packbits(i1DecodedBits,12,6,i4Decoded6BitWords)
+ call unpackmsg(i4Decoded6BitWords,msg) !Unpack decoded msg
+ if(index(msg,'000AAA ').gt.0) msg=' '
+ endif
+
+ return
+end subroutine decode9
diff --git a/lib/decode_rs.c b/lib/decode_rs.c
new file mode 100644
index 00000000..ac85eddd
--- /dev/null
+++ b/lib/decode_rs.c
@@ -0,0 +1,263 @@
+/* Reed-Solomon decoder
+ * Copyright 2002 Phil Karn, KA9Q
+ * May be used under the terms of the GNU General Public License (GPL)
+ */
+
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
+#include <string.h>
+
+//#define NULL ((void *)0)
+#define min(a,b) ((a) < (b) ? (a) : (b))
+
+#ifdef FIXED
+#include "fixed.h"
+#elif defined(BIGSYM)
+#include "int.h"
+#else
+#include "char.h"
+#endif
+
+int DECODE_RS(
+#ifdef FIXED
+DTYPE *data, int *eras_pos, int no_eras,int pad){
+#else
+void *p,DTYPE *data, int *eras_pos, int no_eras){
+ struct rs *rs = (struct rs *)p;
+#endif
+ int deg_lambda, el, deg_omega;
+ int i, j, r,k;
+ DTYPE u,q,tmp,num1,num2,den,discr_r;
+ DTYPE lambda[NROOTS+1], s[NROOTS]; /* Err+Eras Locator poly
+ * and syndrome poly */
+ DTYPE b[NROOTS+1], t[NROOTS+1], omega[NROOTS+1];
+ DTYPE root[NROOTS], reg[NROOTS+1], loc[NROOTS];
+ int syn_error, count;
+
+#ifdef FIXED
+ /* Check pad parameter for validity */
+ if(pad < 0 || pad >= NN)
+ return -1;
+#endif
+
+ /* form the syndromes; i.e., evaluate data(x) at roots of g(x) */
+ for(i=0;i<NROOTS;i++)
+ s[i] = data[0];
+
+ for(j=1;j<NN-PAD;j++){
+ for(i=0;i<NROOTS;i++){
+ if(s[i] == 0){
+ s[i] = data[j];
+ } else {
+ s[i] = data[j] ^ ALPHA_TO[MODNN(INDEX_OF[s[i]] + (FCR+i)*PRIM)];
+ }
+ }
+ }
+
+ /* Convert syndromes to index form, checking for nonzero condition */
+ syn_error = 0;
+ for(i=0;i<NROOTS;i++){
+ syn_error |= s[i];
+ s[i] = INDEX_OF[s[i]];
+ }
+
+ if (!syn_error) {
+ /* if syndrome is zero, data[] is a codeword and there are no
+ * errors to correct. So return data[] unmodified
+ */
+ count = 0;
+ goto finish;
+ }
+ memset(&lambda[1],0,NROOTS*sizeof(lambda[0]));
+ lambda[0] = 1;
+
+ if (no_eras > 0) {
+ /* Init lambda to be the erasure locator polynomial */
+ lambda[1] = ALPHA_TO[MODNN(PRIM*(NN-1-eras_pos[0]))];
+ for (i = 1; i < no_eras; i++) {
+ u = MODNN(PRIM*(NN-1-eras_pos[i]));
+ for (j = i+1; j > 0; j--) {
+ tmp = INDEX_OF[lambda[j - 1]];
+ if(tmp != A0)
+ lambda[j] ^= ALPHA_TO[MODNN(u + tmp)];
+ }
+ }
+
+#if DEBUG >= 1
+ /* Test code that verifies the erasure locator polynomial just constructed
+ Needed only for decoder debugging. */
+
+ /* find roots of the erasure location polynomial */
+ for(i=1;i<=no_eras;i++)
+ reg[i] = INDEX_OF[lambda[i]];
+
+ count = 0;
+ for (i = 1,k=IPRIM-1; i <= NN; i++,k = MODNN(k+IPRIM)) {
+ q = 1;
+ for (j = 1; j <= no_eras; j++)
+ if (reg[j] != A0) {
+ reg[j] = MODNN(reg[j] + j);
+ q ^= ALPHA_TO[reg[j]];
+ }
+ if (q != 0)
+ continue;
+ /* store root and error location number indices */
+ root[count] = i;
+ loc[count] = k;
+ count++;
+ }
+ if (count != no_eras) {
+ printf("count = %d no_eras = %d\n lambda(x) is WRONG\n",count,no_eras);
+ count = -1;
+ goto finish;
+ }
+#if DEBUG >= 2
+ printf("\n Erasure positions as determined by roots of Eras Loc Poly:\n");
+ for (i = 0; i < count; i++)
+ printf("%d ", loc[i]);
+ printf("\n");
+#endif
+#endif
+ }
+ for(i=0;i<NROOTS+1;i++)
+ // printf("%d %d %d\n",i,lambda[i],INDEX_OF[lambda[i]]);
+ b[i] = INDEX_OF[lambda[i]];
+
+ /*
+ * Begin Berlekamp-Massey algorithm to determine error+erasure
+ * locator polynomial
+ */
+ r = no_eras;
+ el = no_eras;
+ while (++r <= NROOTS) { /* r is the step number */
+ /* Compute discrepancy at the r-th step in poly-form */
+ discr_r = 0;
+ for (i = 0; i < r; i++){
+ if ((lambda[i] != 0) && (s[r-i-1] != A0)) {
+ discr_r ^= ALPHA_TO[MODNN(INDEX_OF[lambda[i]] + s[r-i-1])];
+ }
+ }
+ discr_r = INDEX_OF[discr_r]; /* Index form */
+ if (discr_r == A0) {
+ /* 2 lines below: B(x) <-- x*B(x) */
+ memmove(&b[1],b,NROOTS*sizeof(b[0]));
+ b[0] = A0;
+ } else {
+ /* 7 lines below: T(x) <-- lambda(x) - discr_r*x*b(x) */
+ t[0] = lambda[0];
+ for (i = 0 ; i < NROOTS; i++) {
+ if(b[i] != A0)
+ t[i+1] = lambda[i+1] ^ ALPHA_TO[MODNN(discr_r + b[i])];
+ else
+ t[i+1] = lambda[i+1];
+ }
+ if (2 * el <= r + no_eras - 1) {
+ el = r + no_eras - el;
+ /*
+ * 2 lines below: B(x) <-- inv(discr_r) *
+ * lambda(x)
+ */
+ for (i = 0; i <= NROOTS; i++)
+ b[i] = (lambda[i] == 0) ? A0 : MODNN(INDEX_OF[lambda[i]] - discr_r + NN);
+ } else {
+ /* 2 lines below: B(x) <-- x*B(x) */
+ memmove(&b[1],b,NROOTS*sizeof(b[0]));
+ b[0] = A0;
+ }
+ memcpy(lambda,t,(NROOTS+1)*sizeof(t[0]));
+ }
+ }
+
+ /* Convert lambda to index form and compute deg(lambda(x)) */
+ deg_lambda = 0;
+ for(i=0;i<NROOTS+1;i++){
+ lambda[i] = INDEX_OF[lambda[i]];
+ if(lambda[i] != A0)
+ deg_lambda = i;
+ }
+ /* Find roots of the error+erasure locator polynomial by Chien search */
+ memcpy(&reg[1],&lambda[1],NROOTS*sizeof(reg[0]));
+ count = 0; /* Number of roots of lambda(x) */
+ for (i = 1,k=IPRIM-1; i <= NN; i++,k = MODNN(k+IPRIM)) {
+ q = 1; /* lambda[0] is always 0 */
+ for (j = deg_lambda; j > 0; j--){
+ if (reg[j] != A0) {
+ reg[j] = MODNN(reg[j] + j);
+ q ^= ALPHA_TO[reg[j]];
+ }
+ }
+ if (q != 0)
+ continue; /* Not a root */
+ /* store root (index-form) and error location number */
+#if DEBUG>=2
+ printf("count %d root %d loc %d\n",count,i,k);
+#endif
+ root[count] = i;
+ loc[count] = k;
+ /* If we've already found max possible roots,
+ * abort the search to save time
+ */
+ if(++count == deg_lambda)
+ break;
+ }
+ if (deg_lambda != count) {
+ /*
+ * deg(lambda) unequal to number of roots => uncorrectable
+ * error detected
+ */
+ count = -1;
+ goto finish;
+ }
+ /*
+ * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo
+ * x**NROOTS). in index form. Also find deg(omega).
+ */
+ deg_omega = deg_lambda-1;
+ for (i = 0; i <= deg_omega;i++){
+ tmp = 0;
+ for(j=i;j >= 0; j--){
+ if ((s[i - j] != A0) && (lambda[j] != A0))
+ tmp ^= ALPHA_TO[MODNN(s[i - j] + lambda[j])];
+ }
+ omega[i] = INDEX_OF[tmp];
+ }
+
+ /*
+ * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 =
+ * inv(X(l))**(FCR-1) and den = lambda_pr(inv(X(l))) all in poly-form
+ */
+ for (j = count-1; j >=0; j--) {
+ num1 = 0;
+ for (i = deg_omega; i >= 0; i--) {
+ if (omega[i] != A0)
+ num1 ^= ALPHA_TO[MODNN(omega[i] + i * root[j])];
+ }
+ num2 = ALPHA_TO[MODNN(root[j] * (FCR - 1) + NN)];
+ den = 0;
+
+ /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
+ for (i = min(deg_lambda,NROOTS-1) & ~1; i >= 0; i -=2) {
+ if(lambda[i+1] != A0)
+ den ^= ALPHA_TO[MODNN(lambda[i+1] + i * root[j])];
+ }
+#if DEBUG >= 1
+ if (den == 0) {
+ printf("\n ERROR: denominator = 0\n");
+ count = -1;
+ goto finish;
+ }
+#endif
+ /* Apply error to data */
+ if (num1 != 0 && loc[j] >= PAD) {
+ data[loc[j]-PAD] ^= ALPHA_TO[MODNN(INDEX_OF[num1] + INDEX_OF[num2] + NN - INDEX_OF[den])];
+ }
+ }
+ finish:
+ if(eras_pos != NULL){
+ for(i=0;i<count;i++)
+ eras_pos[i] = loc[i];
+ }
+ return count;
+}
diff --git a/lib/decoder.f90 b/lib/decoder.f90
new file mode 100644
index 00000000..83e63a20
--- /dev/null
+++ b/lib/decoder.f90
@@ -0,0 +1,173 @@
+subroutine decoder(ss,id2)
+
+! Decoder for JT9.
+
+ include 'constants.f90'
+ real ss(184,NSMAX)
+ character*22 msg
+ character*20 datetime
+ real*4 ccfred(NSMAX)
+ real*4 red2(NSMAX)
+ logical ccfok(NSMAX)
+ logical done(NSMAX)
+ logical done65
+ integer*2 id2(NTMAX*12000)
+ real*4 dd(NTMAX*12000)
+ integer*1 i1SoftSymbols(207)
+ common/npar/nutc,ndiskdat,ntrperiod,nfqso,newdat,npts8,nfa,nfb,ntol, &
+ kin,nzhsym,nsave,nagain,ndepth,ntxmode,nmode,datetime
+ common/tracer/limtrace,lu
+ save
+
+ call system_clock(iclock0,iclock_rate,iclock_max) !###
+ nfreqs0=0
+ nfreqs1=0
+ ndecodes0=0
+ ndecodes1=0
+
+ open(13,file='decoded.txt',status='unknown')
+ open(22,file='kvasd.dat',access='direct',recl=1024,status='unknown')
+
+ npts65=52*12000
+ ntol65=20
+ done65=.false.
+ if(nmode.ge.65 .and. ntxmode.eq.65) then
+ if(newdat.ne.0) dd(1:npts65)=id2(1:npts65)
+ call jt65a(dd,npts65,newdat,nutc,nfa,nfqso,ntol65,nagain,ndecoded)
+ done65=.true.
+ endif
+
+ if(nmode.eq.65) go to 800
+
+ nsynced=0
+ ndecoded=0
+ nsps=0
+
+ nsps=6912 !Params for JT9-1
+ df3=1500.0/2048.0
+
+ tstep=0.5*nsps/12000.0 !Half-symbol step (seconds)
+ done=.false.
+
+ nf0=0
+ ia=max(1,nint((nfa-nf0)/df3))
+ ib=min(NSMAX,nint((nfb-nf0)/df3))
+ lag1=-(2.5/tstep + 0.9999)
+ lag2=5.0/tstep + 0.9999
+ if(newdat.ne.0) then
+ call timer('sync9 ',0)
+ call sync9(ss,nzhsym,lag1,lag2,ia,ib,ccfred,red2,ipk)
+ call timer('sync9 ',1)
+ endif
+
+ nsps8=nsps/8
+ df8=1500.0/nsps8
+ dblim=db(864.0/nsps8) - 26.2
+
+ do nqd=1,0,-1
+ limit=1000
+ ccflim=4.0
+ red2lim=1.6
+ schklim=2.2
+ if(ndepth.eq.2) then
+ limit=10000
+ ccflim=3.5
+ endif
+ if(ndepth.ge.3 .or. nqd.eq.1) then
+ limit=100000
+ ccflim=2.5
+ endif
+ ccfok=.false.
+
+ if(nqd.eq.1) then
+ nfa1=nfqso-ntol
+ nfb1=nfqso+ntol
+ ia=max(1,nint((nfa1-nf0)/df3))
+ ib=min(NSMAX,nint((nfb1-nf0)/df3))
+ ccfok(ia:ib)=(ccfred(ia:ib).gt.(ccflim-2.0)) .and. &
+ (red2(ia:ib).gt.(red2lim-1.0))
+ ia1=ia
+ ib1=ib
+ else
+ nfa1=nfa
+ nfb1=nfb
+ ia=max(1,nint((nfa1-nf0)/df3))
+ ib=min(NSMAX,nint((nfb1-nf0)/df3))
+ do i=ia,ib
+ ccfok(i)=ccfred(i).gt.ccflim .and. red2(i).gt.red2lim
+ enddo
+ ccfok(ia1:ib1)=.false.
+ endif
+
+ fgood=0.
+ do i=ia,ib
+ if(done(i) .or. (.not.ccfok(i))) cycle
+ f=(i-1)*df3
+ if(nqd.eq.1 .or. &
+ (ccfred(i).ge.ccflim .and. abs(f-fgood).gt.10.0*df8)) then
+
+ if(nqd.eq.0) nfreqs0=nfreqs0+1
+ if(nqd.eq.1) nfreqs1=nfreqs1+1
+
+ call timer('softsym ',0)
+ fpk=nf0 + df3*(i-1)
+
+ call softsym(id2,npts8,nsps8,newdat,fpk,syncpk,snrdb,xdt, &
+ freq,drift,schk,i1SoftSymbols)
+ call timer('softsym ',1)
+
+! write(71,3001) nqd,i,f,fpk,ccfred(i),red2(i),schk
+!3001 format(2i6,2f8.1,3f6.1)
+! call flush(71)
+
+ if(schk.lt.schklim) cycle
+
+ call timer('decode9 ',0)
+ call decode9(i1SoftSymbols,limit,nlim,msg)
+ call timer('decode9 ',1)
+
+ sync=(syncpk+1)/4.0
+ if(sync.lt.0.0 .or. snrdb.lt.dblim-2.0) sync=0.0
+ nsync=sync
+ if(nsync.gt.10) nsync=10
+ nsnr=nint(snrdb)
+ ndrift=nint(drift/df3)
+
+ if(msg.ne.' ') then
+ if(nqd.eq.0) ndecodes0=ndecodes0+1
+ if(nqd.eq.1) ndecodes1=ndecodes1+1
+
+ write(*,1000) nutc,nsnr,xdt,nint(freq),msg
+1000 format(i4.4,i4,f5.1,i5,1x,'@',1x,a22)
+ write(13,1002) nutc,nsync,nsnr,xdt,freq,ndrift,msg
+1002 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a22,' JT9')
+
+ iaa=max(1,i-1)
+ ibb=min(NSMAX,i+22)
+ fgood=f
+ nsynced=1
+ ndecoded=1
+ ccfok(iaa:ibb)=.false.
+ done(iaa:ibb)=.true.
+ call flush(6)
+ endif
+ endif
+ enddo
+ call flush(6)
+ if(nagain.ne.0) exit
+ enddo
+
+ if(nmode.ge.65 .and. (.not.done65)) then
+ if(newdat.ne.0) dd(1:npts65)=id2(1:npts65)
+ call jt65a(dd,npts65,newdat,nutc,nfa,nfqso,ntol65,nagain,ndecoded)
+ endif
+
+!### JT65 is not yet producing info for nsynced, ndecoded.
+800 write(*,1010) nsynced,ndecoded
+1010 format('<DecodeFinished>',2i4)
+ call flush(6)
+ close(13)
+ close(22)
+
+ return
+end subroutine decoder
diff --git a/lib/deep24.f90 b/lib/deep24.f90
new file mode 100644
index 00000000..70a69ae7
--- /dev/null
+++ b/lib/deep24.f90
@@ -0,0 +1,182 @@
+subroutine deep24(sym,neme,flip,mycall,hiscall,hisgrid,decoded,qual)
+
+! Have barely begun converting this from JT65 to JT4
+
+ parameter (MAXCALLS=7000,MAXRPT=63)
+ real*4 sym(206)
+ character callsign*12,grid*4,message*22,hisgrid*6,c*1,ceme*3
+ character*12 mycall,hiscall
+ character mycall0*12,hiscall0*12,hisgrid0*6
+ character*22 decoded
+ character*22 testmsg(2*MAXCALLS + 2 + MAXRPT)
+ character*15 callgrid(MAXCALLS)
+ character*180 line
+ character*4 rpt(MAXRPT)
+ integer ncode(206)
+ real*4 code(206,2*MAXCALLS + 2 + MAXRPT)
+ real pp(2*MAXCALLS + 2 + MAXRPT)
+! common/c3com/ mcall3a
+
+ data neme0/-99/
+ data rpt/'-01','-02','-03','-04','-05', &
+ '-06','-07','-08','-09','-10', &
+ '-11','-12','-13','-14','-15', &
+ '-16','-17','-18','-19','-20', &
+ '-21','-22','-23','-24','-25', &
+ '-26','-27','-28','-29','-30', &
+ 'R-01','R-02','R-03','R-04','R-05', &
+ 'R-06','R-07','R-08','R-09','R-10', &
+ 'R-11','R-12','R-13','R-14','R-15', &
+ 'R-16','R-17','R-18','R-19','R-20', &
+ 'R-21','R-22','R-23','R-24','R-25', &
+ 'R-26','R-27','R-28','R-29','R-30', &
+ 'RO','RRR','73'/
+ save
+
+ if(mycall.eq.mycall0 .and. hiscall.eq.hiscall0 .and. &
+ hisgrid.eq.hisgrid0 .and. mcall3a.eq.0 .and. neme.eq.neme0) go to 30
+
+ mcall3a=0
+ rewind 23
+ k=0
+ icall=0
+ do n=1,MAXCALLS
+ if(n.eq.1) then
+ callsign=hiscall
+ do i=4,12
+ if(ichar(callsign(i:i)).eq.0) callsign(i:i)=' '
+ enddo
+ grid=hisgrid(1:4)
+ if(ichar(grid(3:3)).eq.0) grid(3:3)=' '
+ if(ichar(grid(4:4)).eq.0) grid(4:4)=' '
+ else
+ read(23,1002,end=20) line
+1002 format (A80)
+ if(line(1:4).eq.'ZZZZ') go to 20
+ if(line(1:2).eq.'//') go to 10
+ i1=index(line,',')
+ if(i1.lt.4) go to 10
+ i2=index(line(i1+1:),',')
+ if(i2.lt.5) go to 10
+ i2=i2+i1
+ i3=index(line(i2+1:),',')
+ if(i3.lt.1) i3=index(line(i2+1:),' ')
+ i3=i2+i3
+ callsign=line(1:i1-1)
+ grid=line(i1+1:i2-1)
+ ceme=line(i2+1:i3-1)
+ if(neme.eq.1 .and. ceme.ne.'EME') go to 10
+ endif
+
+ icall=icall+1
+ j1=index(mycall,' ') - 1
+ if(j1.le.-1) j1=12
+ if(j1.lt.3) j1=6
+ j2=index(callsign,' ') - 1
+ if(j2.le.-1) j2=12
+ if(j2.lt.3) j2=6
+ j3=index(mycall,'/') ! j3>0 means compound mycall
+ j4=index(callsign,'/') ! j4>0 means compound hiscall
+ callgrid(icall)=callsign(1:j2)
+
+ mz=1
+! Allow MyCall + HisCall + rpt (?)
+ if(n.eq.1 .and. j3.lt.1 .and. j4.lt.1 .and. &
+ flip.gt.0.0 .and. callsign(1:6).ne.' ') mz=MAXRPT+1
+ do m=1,mz
+ if(m.gt.1) grid=rpt(m-1)
+ if(j3.lt.1 .and.j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid
+ message=mycall(1:j1)//' '//callgrid(icall)
+ k=k+1
+ testmsg(k)=message
+ call encode4(message,ncode)
+ code(1:206,k)=2*ncode(1:206)-1
+ if(n.ge.2) then
+! Insert CQ message
+ if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid
+ message='CQ '//callgrid(icall)
+ k=k+1
+ testmsg(k)=message
+ call encode4(message,ncode)
+ code(1:206,k)=2*ncode(1:206)-1
+ endif
+ enddo
+10 continue
+ enddo
+
+20 continue
+ ntot=k
+ neme0=neme
+
+30 mycall0=mycall
+ hiscall0=hiscall
+ hisgrid0=hisgrid
+
+ sq=0.
+ do j=1,206
+ sq=sq + sym(j)**2
+ enddo
+ rms=sqrt(sq/206.0)
+ sym=sym/rms
+
+ p1=-1.e30
+ p2=-1.e30
+ do k=1,ntot
+ pp(k)=0.
+! Test all messages if flip=+1; skip the CQ messages if flip=-1.
+ if(flip.gt.0.0 .or. testmsg(k)(1:3).ne.'CQ ') then
+ p=0.
+ do j=1,206
+ i=code(j,k)+1
+ p=p + code(j,k)*sym(j)
+ enddo
+ pp(k)=p
+ if(p.gt.p1) then
+ p1=p
+ ip1=k
+ endif
+ endif
+ enddo
+
+ do i=1,ntot
+ if(pp(i).gt.p2 .and. pp(i).ne.p1) p2=pp(i)
+ enddo
+
+! ### DO NOT REMOVE ###
+! rewind 77
+! write(77,*) p1,p2
+! ### Works OK without it (in both Windows and Linux) if compiled
+! ### without optimization. However, in Windows this is a colossal
+! ### pain because of the way F2PY wants to run the compile step.
+
+
+ bias=1.1*p2
+! if(mode65.eq.1) bias=max(1.12*p2,0.335)
+! if(mode65.eq.2) bias=max(1.08*p2,0.405)
+! if(mode65.ge.4) bias=max(1.04*p2,0.505)
+
+ if(p2.eq.p1 .and. p1.ne.-1.e30) stop 'Error in deep24'
+ qual=10.0*(p1-bias)
+
+ decoded=' '
+ c=' '
+
+ if(qual.gt.1.0) then
+ if(qual.lt.6.0) c='?'
+ decoded=testmsg(ip1)
+ else
+ qual=0.
+ endif
+ decoded(22:22)=c
+
+! Make sure everything is upper case.
+ do i=1,22
+ if(decoded(i:i).ge.'a' .and. decoded(i:i).le.'z') &
+ decoded(i:i)=char(ichar(decoded(i:i))-32)
+ enddo
+
+! write(*,3010) p1,p2,p1-p2,p1/p2,qual,decoded
+!3010 format('DS:',5f9.1,2x,a22)
+
+ return
+end subroutine deep24
diff --git a/lib/deg2grid.f90 b/lib/deg2grid.f90
new file mode 100644
index 00000000..4fdc2af3
--- /dev/null
+++ b/lib/deg2grid.f90
@@ -0,0 +1,30 @@
+subroutine deg2grid(dlong0,dlat,grid)
+
+ real dlong !West longitude (deg)
+ real dlat !Latitude (deg)
+ character grid*6
+
+ dlong=dlong0
+ if(dlong.lt.-180.0) dlong=dlong+360.0
+ if(dlong.gt.180.0) dlong=dlong-360.0
+
+! Convert to units of 5 min of longitude, working east from 180 deg.
+ nlong=int(60.0*(180.0-dlong)/5.0)
+ n1=nlong/240 !20-degree field
+ n2=(nlong-240*n1)/24 !2 degree square
+ n3=nlong-240*n1-24*n2 !5 minute subsquare
+ grid(1:1)=char(ichar('A')+n1)
+ grid(3:3)=char(ichar('0')+n2)
+ grid(5:5)=char(ichar('a')+n3)
+
+! Convert to units of 2.5 min of latitude, working north from -90 deg.
+ nlat=int(60.0*(dlat+90)/2.5)
+ n1=nlat/240 !10-degree field
+ n2=(nlat-240*n1)/24 !1 degree square
+ n3=nlat-240*n1-24*n2 !2.5 minuts subsquare
+ grid(2:2)=char(ichar('A')+n1)
+ grid(4:4)=char(ichar('0')+n2)
+ grid(6:6)=char(ichar('a')+n3)
+
+ return
+end subroutine deg2grid
diff --git a/lib/demod64a.f90 b/lib/demod64a.f90
new file mode 100644
index 00000000..9d1a3794
--- /dev/null
+++ b/lib/demod64a.f90
@@ -0,0 +1,73 @@
+subroutine demod64a(s3,nadd,mrsym,mrprob,mr2sym,mr2prob,ntest,nlow)
+
+! Demodulate the 64-bin spectra for each of 63 symbols in a frame.
+
+! Parameters
+! nadd number of spectra already summed
+! mrsym most reliable symbol value
+! mr2sym second most likely symbol value
+! mrprob probability that mrsym was the transmitted value
+! mr2prob probability that mr2sym was the transmitted value
+
+ implicit real*8 (a-h,o-z)
+ real*4 s3(64,63)
+ real*8 fs(64)
+ integer mrsym(63),mrprob(63),mr2sym(63),mr2prob(63)
+! common/mrscom/ mrs(63),mrs2(63)
+
+ if(nadd.eq.-999) return
+ afac=1.1 * float(nadd)**0.64
+ scale=255.999
+
+! Compute average spectral value
+ sum=0.
+ do j=1,63
+ do i=1,64
+ sum=sum+s3(i,j)
+ enddo
+ enddo
+ ave=sum/(64.*63.)
+ i1=1 !Silence warning
+ i2=1
+
+! Compute probabilities for most reliable symbol values
+ do j=1,63
+ s1=-1.e30
+ fsum=0.
+ do i=1,64
+ x=min(afac*s3(i,j)/ave,50.d0)
+ fs(i)=exp(x)
+ fsum=fsum+fs(i)
+ if(s3(i,j).gt.s1) then
+ s1=s3(i,j)
+ i1=i !Most reliable
+ endif
+ enddo
+
+ s2=-1.e30
+ do i=1,64
+ if(i.ne.i1 .and. s3(i,j).gt.s2) then
+ s2=s3(i,j)
+ i2=i !Second most reliable
+ endif
+ enddo
+ p1=fs(i1)/fsum !Normalized probabilities
+ p2=fs(i2)/fsum
+ mrsym(j)=i1-1
+ mr2sym(j)=i2-1
+ mrprob(j)=scale*p1
+ mr2prob(j)=scale*p2
+! mrs(j)=i1
+! mrs2(j)=i2
+ enddo
+
+ sum=0.
+ nlow=0
+ do j=1,63
+ sum=sum+mrprob(j)
+ if(mrprob(j).le.5) nlow=nlow+1
+ enddo
+ ntest=sum/63
+
+ return
+end subroutine demod64a
diff --git a/lib/downsam9.f90 b/lib/downsam9.f90
new file mode 100644
index 00000000..851d497c
--- /dev/null
+++ b/lib/downsam9.f90
@@ -0,0 +1,66 @@
+subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2,nz2)
+
+!Downsample from id2() into C2() so as to yield nspsd samples per symbol,
+!mixing from fpk down to zero frequency.
+
+ include 'constants.f90'
+ parameter (NMAX1=1024*1920)
+ integer*2 id2(0:8*npts8-1)
+ real*4 x1(0:NMAX1-1)
+ complex c1(0:NMAX1/2)
+ complex c2(0:4096-1)
+ real s(5000)
+ equivalence (c1,x1)
+ save
+
+ nfft1=1024*nsps8 !Forward FFT length
+ df1=12000.0/nfft1
+ npts=8*npts8
+
+ if(newdat.eq.1) then
+ fac=6.963e-6 !Why this weird constant?
+ do i=0,npts-1
+ x1(i)=fac*id2(i)
+ enddo
+ x1(npts:nfft1-1)=0. !Zero the rest of x1
+ call timer('fft_forw',0)
+ call four2a(c1,nfft1,1,-1,0) !Forward FFT, r2c
+ call timer('fft_forw',1)
+
+ nadd=1.0/df1
+ s=0.
+ do i=1,5000
+ j=(i-1)/df1
+ do n=1,nadd
+ j=j+1
+ s(i)=s(i)+real(c1(j))**2 + aimag(c1(j))**2
+ enddo
+ enddo
+ endif
+
+ ndown=8*nsps8/nspsd !Downsample factor
+ nfft2=nfft1/ndown !Backward FFT length
+ nh2=nfft2/2
+ nf=nint(fpk)
+ i0=fpk/df1
+
+ nw=100
+ ia=max(1,nf-nw)
+ ib=min(5000,nf+nw)
+ call timer('pctile_1',0)
+ call pctile(s(ia),ib-ia+1,40,avenoise)
+ call timer('pctile_1',1)
+
+ fac=sqrt(1.0/avenoise)
+ do i=0,nfft2-1
+ j=i0+i
+ if(i.gt.nh2) j=j-nfft2
+ c2(i)=fac*c1(j)
+ enddo
+ call timer('fft_back',0)
+ call four2a(c2,nfft2,1,1,1) !FFT back to time domain
+ call timer('fft_back',1)
+ nz2=8*npts8/ndown
+
+ return
+end subroutine downsam9
diff --git a/lib/encode232.f90 b/lib/encode232.f90
new file mode 100644
index 00000000..bc904b48
--- /dev/null
+++ b/lib/encode232.f90
@@ -0,0 +1,33 @@
+subroutine encode232(dat,nsym,symbol)
+
+! Convolutional encoder for a K=32, r=1/2 code.
+
+ integer*1 dat(13) !User data, packed 8 bits per byte
+ integer*1 symbol(500) !Channel symbols, one bit per byte
+ integer*1 i1
+ include 'conv232.f90'
+
+ nstate=0
+ k=0
+ do j=1,nsym
+ do i=7,0,-1
+ i1=dat(j)
+ i4=i1
+ if (i4.lt.0) i4=i4+256
+ nstate=ior(ishft(nstate,1),iand(ishft(i4,-i),1))
+ n=iand(nstate,npoly1)
+ n=ieor(n,ishft(n,-16))
+ k=k+1
+ symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255))
+ n=iand(nstate,npoly2)
+ n=ieor(n,ishft(n,-16))
+ k=k+1
+ symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255))
+ if(k.ge.nsym) go to 100
+ enddo
+ enddo
+
+100 continue
+
+ return
+end subroutine encode232
diff --git a/lib/encode4.f90 b/lib/encode4.f90
new file mode 100644
index 00000000..64b9dfcd
--- /dev/null
+++ b/lib/encode4.f90
@@ -0,0 +1,20 @@
+subroutine encode4(message,ncode)
+
+ parameter (MAXCALLS=7000,MAXRPT=63)
+ integer ncode(206)
+ character*22 message !Message to be generated
+ character*3 cok !' ' or 'OOO'
+ integer dgen(13)
+ integer*1 data0(13),symbol(216)
+ logical text
+
+ call chkmsg(message,cok,nspecial,flip)
+ call packmsg(message,dgen,text) !Pack 72-bit message into 12 six-bit symbols
+ call entail(dgen,data0)
+ call encode232(data0,206,symbol) !Convolutional encoding
+ call interleave24(symbol,1) !Apply JT4 interleaving
+ do i=1,206
+ ncode(i)=symbol(i)
+ enddo
+
+end subroutine encode4
diff --git a/lib/encode_rs.c b/lib/encode_rs.c
new file mode 100644
index 00000000..911bc36d
--- /dev/null
+++ b/lib/encode_rs.c
@@ -0,0 +1,52 @@
+/* Reed-Solomon encoder
+ * Copyright 2002, Phil Karn, KA9Q
+ * May be used under the terms of the GNU General Public License (GPL)
+ */
+#include <string.h>
+
+#ifdef FIXED
+#include "fixed.h"
+#elif defined(BIGSYM)
+#include "int.h"
+#else
+#include "char.h"
+#endif
+
+void ENCODE_RS(
+#ifdef FIXED
+DTYPE *data, DTYPE *bb,int pad){
+#else
+void *p,DTYPE *data, DTYPE *bb){
+ struct rs *rs = (struct rs *)p;
+#endif
+ int i, j;
+ DTYPE feedback;
+
+#ifdef FIXED
+ /* Check pad parameter for validity */
+ if(pad < 0 || pad >= NN)
+ return;
+#endif
+
+ memset(bb,0,NROOTS*sizeof(DTYPE));
+
+ for(i=0;i<NN-NROOTS-PAD;i++){
+ feedback = INDEX_OF[data[i] ^ bb[0]];
+ if(feedback != A0){ /* feedback term is non-zero */
+#ifdef UNNORMALIZED
+ /* This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
+ * always be for the polynomials constructed by init_rs()
+ */
+ feedback = MODNN(NN - GENPOLY[NROOTS] + feedback);
+#endif
+ for(j=1;j<NROOTS;j++)
+ bb[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS-j])];
+ }
+ /* Shift */
+ memmove(&bb[0],&bb[1],sizeof(DTYPE)*(NROOTS-1));
+ if(feedback != A0)
+ bb[NROOTS-1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
+ else
+ bb[NROOTS-1] = 0;
+ }
+}
diff --git a/lib/entail.f90 b/lib/entail.f90
new file mode 100644
index 00000000..1228a75c
--- /dev/null
+++ b/lib/entail.f90
@@ -0,0 +1,30 @@
+subroutine entail(dgen,data0)
+
+! Move 72-bit packed data from 6-bit to 8-bit symbols and add a zero tail.
+ integer dgen(13)
+ integer*1 data0(13)
+
+ i4=0
+ k=0
+ m=0
+ do i=1,12
+ n=dgen(i)
+ do j=1,6
+ k=k+1
+ i4=i4+i4+iand(1,ishft(n,j-6))
+ i4=iand(i4,255)
+ if(k.eq.8) then
+ m=m+1
+ if(i4.gt.127) i4=i4-256
+ data0(m)=i4
+ k=0
+ endif
+ enddo
+ enddo
+ do m=10,13
+ data0(m)=0
+ enddo
+
+ return
+end subroutine entail
+
diff --git a/lib/extract.F90 b/lib/extract.F90
new file mode 100644
index 00000000..2b580f63
--- /dev/null
+++ b/lib/extract.F90
@@ -0,0 +1,103 @@
+subroutine extract(s3,nadd,ncount,nhist,decoded,ltext,nbmkv)
+
+ real s3(64,63)
+ character decoded*22
+ integer era(51),dat4(12),indx(64)
+ integer mrsym(63),mr2sym(63),mrprob(63),mr2prob(63)
+ logical nokv,ltext
+ data nokv/.false./,nsec1/0/
+ save
+
+ nbmkv=0
+ nfail=0
+1 continue
+ call demod64a(s3,nadd,mrsym,mrprob,mr2sym,mr2prob,ntest,nlow)
+ if(ntest.lt.50 .or. nlow.gt.20) then
+ ncount=-999 !Flag bad data
+ go to 900
+ endif
+ call chkhist(mrsym,nhist,ipk)
+
+ if(nhist.ge.20) then
+ nfail=nfail+1
+ call pctile(s3,4032,50,base) ! ### or, use ave from demod64a
+ do j=1,63
+ s3(ipk,j)=base
+ enddo
+ if(nfail.gt.30) then
+ decoded=' '
+ ncount=-1
+ go to 900
+ endif
+ go to 1
+ endif
+
+ call graycode65(mrsym,63,-1)
+ call interleave63(mrsym,-1)
+ call interleave63(mrprob,-1)
+
+! Decode using Berlekamp-Massey algorithm
+ nemax=30 !Max BM erasures
+ call indexx(63,mrprob,indx)
+ do i=1,nemax
+ j=indx(i)
+ if(mrprob(j).gt.120) then
+ ne2=i-1
+ go to 2
+ endif
+ era(i)=j-1
+ enddo
+ ne2=nemax
+2 decoded=' '
+ do nerase=0,ne2,2
+ call rs_decode(mrsym,era,nerase,dat4,ncount)
+ if(ncount.ge.0) then
+ call unpackmsg(dat4,decoded)
+ if(iand(dat4(10),8).ne.0) ltext=.true.
+ nbmkv=1
+ go to 900
+ endif
+ enddo
+
+! Berlekamp-Massey algorithm failed, try Koetter-Vardy
+
+ if(nokv) go to 900
+
+ maxe=8 !Max KV errors in 12 most reliable symbols
+! xlambda=12.0
+ xlambda=7.99
+ call graycode65(mr2sym,63,-1)
+ call interleave63(mr2sym,-1)
+ call interleave63(mr2prob,-1)
+
+ nsec1=nsec1+1
+ write(22,rec=1) nsec1,xlambda,maxe,200,mrsym,mrprob,mr2sym,mr2prob
+ call flush(22)
+ call timer('kvasd ',0)
+#ifdef UNIX
+ iret=system('./kvasd -q > dev_null')
+#else
+ iret=system('kvasd -q > dev_null')
+#endif
+ call timer('kvasd ',1)
+ if(iret.ne.0) then
+ if(.not.nokv) write(*,1000)
+1000 format('Error in KV decoder, or no KV decoder present.')
+ nokv=.true.
+ go to 900
+ endif
+
+ read(22,rec=2,err=900) nsec2,ncount,dat4
+ j=nsec2 !Silence compiler warning
+ decoded=' '
+ ltext=.false.
+ if(ncount.ge.0) then
+ call unpackmsg(dat4,decoded) !Unpack the user message
+ if(iand(dat4(10),8).ne.0) ltext=.true.
+ nbmkv=2
+ endif
+
+900 continue
+
+ return
+end subroutine extract
diff --git a/lib/extract4.f90 b/lib/extract4.f90
new file mode 100644
index 00000000..06229460
--- /dev/null
+++ b/lib/extract4.f90
@@ -0,0 +1,61 @@
+subroutine extract4(sym,nadd,ncount,decoded)
+
+ real sym(207)
+ character decoded*22, submode*1
+ character*72 c72
+ integer*1 symbol(207)
+ integer*1 data1(13) !Decoded data (8-bit bytes)
+ integer data4a(9) !Decoded data (8-bit bytes)
+ integer data4(12) !Decoded data (6-bit bytes)
+ integer mettab(0:255,0:1) !Metric table
+ logical first
+ data first/.true./
+ save first,mettab
+
+ if(first) then
+ call getmet24(mode,mettab)
+ first=.false.
+ endif
+
+ do j=1,207
+ r=sym(j) + 128.
+ if(r.gt.255.0) r=255.0
+ if(r.lt.0.0) r=0.0
+ i4=nint(r)
+ if(i4.gt.127) i4=i4-256
+ symbol(j)=i4
+ enddo
+
+ nbits=72+31
+ ndelta=50
+ limit=100000
+ ncycles=0
+ ncount=-1
+ decoded=' '
+ submode=' '
+
+ call interleave24(symbol(2),-1) !Remove the interleaving
+ call fano232(symbol(2),nbits,mettab,ndelta,limit,data1,ncycles,metric,ncount)
+ nlim=ncycles/nbits
+
+ if(ncount.ge.0) then
+ do i=1,9
+ i4=data1(i)
+ if(i4.lt.0) i4=i4+256
+ data4a(i)=i4
+ enddo
+ write(c72,1100) (data4a(i),i=1,9)
+1100 format(9b8.8)
+ read(c72,1102) data4
+1102 format(12b6)
+
+ call unpackmsg(data4,decoded)
+ submode=char(ichar('A')+ich-1)
+ if(decoded(1:6).eq.'000AAA') then
+ decoded='***WRONG MODE?***'
+ ncount=-1
+ endif
+ endif
+
+ return
+end subroutine extract4
diff --git a/lib/f77_wisdom.f90 b/lib/f77_wisdom.f90
new file mode 100644
index 00000000..39bdff8e
--- /dev/null
+++ b/lib/f77_wisdom.f90
@@ -0,0 +1,45 @@
+subroutine write_char(c, iunit)
+ character c
+ integer iunit
+ write(iunit,1000) c
+1000 format(a,$)
+end subroutine write_char
+
+subroutine export_wisdom_to_file(iunit)
+ integer iunit
+ external write_char
+! call dfftw_export_wisdom(write_char, iunit)
+ call sfftw_export_wisdom(write_char, iunit)
+end subroutine export_wisdom_to_file
+
+subroutine read_char(ic, iunit)
+ integer ic
+ integer iunit
+ character*256 buf
+ save buf
+ integer ibuf
+ data ibuf/257/
+ save ibuf
+ if (ibuf .lt. 257) then
+ ic = ichar(buf(ibuf:ibuf))
+ ibuf = ibuf + 1
+ return
+ endif
+ read(iunit,1000,end=10) buf
+1000 format(a256)
+ ic = ichar(buf(1:1))
+ ibuf = 2
+ return
+10 ic = -1
+ ibuf = 257
+ rewind iunit
+ return
+end subroutine read_char
+
+subroutine import_wisdom_from_file(isuccess, iunit)
+ integer isuccess
+ integer iunit
+ external read_char
+! call dfftw_import_wisdom(isuccess, read_char, iunit)
+ call sfftw_import_wisdom(isuccess, read_char, iunit)
+end subroutine import_wisdom_from_file
diff --git a/lib/fano232.f90 b/lib/fano232.f90
new file mode 100644
index 00000000..1e129507
--- /dev/null
+++ b/lib/fano232.f90
@@ -0,0 +1,140 @@
+subroutine fano232(symbol,nbits,mettab,ndelta,maxcycles,dat, &
+ ncycles,metric,ierr)
+
+! Sequential decoder for K=32, r=1/2 convolutional code using
+! the Fano algorithm. Translated from C routine for same purpose
+! written by Phil Karn, KA9Q.
+
+ parameter (MAXBITS=103)
+ parameter (MAXBYTES=(MAXBITS+7)/8)
+ integer*1 symbol(0:2*MAXBITS-1) !Soft symbols (as unsigned i*1)
+ integer*1 dat(MAXBYTES) !Decoded user data, 8 bits per byte
+ integer mettab(0:255,0:1) !Metric table
+
+! These were the "node" structure in Karn's C code:
+ integer nstate(0:MAXBITS-1) !Encoder state of next node
+ integer gamma(0:MAXBITS-1) !Cumulative metric to this node
+ integer metrics(0:3,0:MAXBITS-1) !Metrics indexed by all possible Tx syms
+ integer tm(0:1,0:MAXBITS-1) !Sorted metrics for current hypotheses
+ integer ii(0:MAXBITS-1) !Current branch being tested
+
+ logical noback
+ include 'conv232.f90' !Polynomials defined here
+
+ ntail=nbits-31
+
+! Compute all possible branch metrics for each symbol pair.
+! This is the only place we actually look at the raw input symbols
+ i4a=0
+ i4b=0
+ do np=0,nbits-1
+ j=2*np
+ i4a=symbol(j)
+ i4b=symbol(j+1)
+ if (i4a.lt.0) i4a=i4a+256
+ if (i4b.lt.0) i4b=i4b+256
+ metrics(0,np) = mettab(i4a,0) + mettab(i4b,0)
+ metrics(1,np) = mettab(i4a,0) + mettab(i4b,1)
+ metrics(2,np) = mettab(i4a,1) + mettab(i4b,0)
+ metrics(3,np) = mettab(i4a,1) + mettab(i4b,1)
+ enddo
+
+ np=0
+ nstate(np)=0
+
+ n=iand(nstate(np),npoly1) !Compute and sort branch metrics
+ n=ieor(n,ishft(n,-16)) !from the root node
+ lsym=partab(iand(ieor(n,ishft(n,-8)),255))
+ n=iand(nstate(np),npoly2)
+ n=ieor(n,ishft(n,-16))
+ lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255))
+ m0=metrics(lsym,np)
+ m1=metrics(ieor(3,lsym),np)
+ if(m0.gt.m1) then
+ tm(0,np)=m0 !0-branch has better metric
+ tm(1,np)=m1
+ else
+ tm(0,np)=m1 !1-branch is better
+ tm(1,np)=m0
+ nstate(np)=nstate(np) + 1 !Set low bit
+ endif
+
+ ii(np)=0 !Start with best branch
+ gamma(np)=0
+ nt=0
+
+ do i=1,nbits*maxcycles !Start the Fano decoder
+ ngamma=gamma(np) + tm(ii(np),np) !Look forward
+ if(ngamma.ge.nt) then
+! Node is acceptable. If first time visiting this node, tighten threshold:
+ if(gamma(np).lt.(nt+ndelta)) nt=nt + ndelta * ((ngamma-nt)/ndelta)
+ gamma(np+1)=ngamma !Move forward
+ nstate(np+1)=ishft(nstate(np),1)
+ np=np+1
+ if(np.eq.nbits-1) go to 100 !We're done!
+
+ n=iand(nstate(np),npoly1)
+ n=ieor(n,ishft(n,-16))
+ lsym=partab(iand(ieor(n,ishft(n,-8)),255))
+ n=iand(nstate(np),npoly2)
+ n=ieor(n,ishft(n,-16))
+ lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255))
+
+ if(np.ge.ntail) then
+ tm(0,np)=metrics(lsym,np) !We're in the tail, now all zeros
+ else
+ m0=metrics(lsym,np)
+ m1=metrics(ieor(3,lsym),np)
+ if(m0.gt.m1) then
+ tm(0,np)=m0 !0-branch has better metric
+ tm(1,np)=m1
+ else
+ tm(0,np)=m1 !1-branch is better
+ tm(1,np)=m0
+ nstate(np)=nstate(np) + 1 !Set low bit
+ endif
+ endif
+ ii(np)=0 !Start with best branch
+ else
+ do while(.true.)
+ noback=.false. !Threshold violated, can't go forward
+ if(np.eq.0) noback=.true.
+ if(np.gt.0) then
+ if(gamma(np-1).lt.nt) noback=.true.
+ endif
+
+ if(noback) then !Can't back up, either
+ nt=nt-ndelta !Relax threshold and look forward again
+ if(ii(np).ne.0) then
+ ii(np)=0
+ nstate(np)=ieor(nstate(np),1)
+ endif
+ exit
+ endif
+
+ np=np-1 !Back up
+ if(np.lt.ntail .and. ii(np).ne.1) then
+ ii(np)=ii(np)+1 !Search the next best branch
+ nstate(np)=ieor(nstate(np),1)
+ exit
+ endif
+ enddo
+ endif
+ enddo
+ i=nbits*maxcycles
+
+100 metric=gamma(np) !Final path metric
+ nbytes=(nbits+7)/8 !Copy decoded data to user's buffer
+ np=7
+ do j=1,nbytes-1
+ i4a=nstate(np)
+ dat(j)=i4a
+ np=np+8
+ enddo
+ dat(nbytes)=0
+ ncycles=i+1
+ ierr=0
+ if(i.ge.maxcycles*nbits) ierr=-1
+
+ return
+end subroutine fano232
diff --git a/lib/fchisq.f90 b/lib/fchisq.f90
new file mode 100644
index 00000000..1dece102
--- /dev/null
+++ b/lib/fchisq.f90
@@ -0,0 +1,41 @@
+real function fchisq(c3,npts,fsample,a)
+
+ parameter (NMAX=85*16)
+ complex c3(npts)
+ complex c4(NMAX)
+ real a(3)
+ complex z
+ data a1,a2,a3/99.,99.,99./
+ include 'jt9sync.f90'
+ save
+
+ if(a(1).ne.a1 .or. a(2).ne.a2 .or. a(3).ne.a3) then
+ a1=a(1)
+ a2=a(2)
+ a3=a(3)
+ call twkfreq(c3,c4,npts,fsample,a)
+ endif
+
+! Get sync power.
+ nspsd=16
+ sum1=0.
+ sum0=0.
+ k=-1
+ do i=1,85
+ z=0.
+ do j=1,nspsd
+ k=k+1
+ z=z+c4(k+1)
+ enddo
+ pp=real(z)**2 + aimag(z)**2
+ if(isync(i).eq.1) then
+ sum1=sum1+pp
+ else
+ sum0=sum0+pp
+ endif
+ enddo
+ sync=(sum1/16.0)/(sum0/69.0) - 1.0
+ fchisq=-sync
+
+ return
+end function fchisq
diff --git a/lib/fchisq65.f90 b/lib/fchisq65.f90
new file mode 100644
index 00000000..b91444e5
--- /dev/null
+++ b/lib/fchisq65.f90
@@ -0,0 +1,68 @@
+real function fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax)
+
+ parameter (NMAX=60*12000) !Samples per 60 s
+ complex cx(npts)
+ real a(5)
+ complex w,wstep,z
+ real ss(3000)
+ complex csx(0:NMAX/8)
+ data twopi/6.283185307/a1,a2,a3/99.,99.,99./
+ save
+
+ call timer('fchisq65',0)
+ baud=11025.0/4096.0
+ nsps=nint(fsample/baud) !Samples per symbol
+ nsph=nsps/2 !Samples per half-symbol
+ ndiv=16 !Output ss() steps per symbol
+ nout=ndiv*npts/nsps
+ dtstep=1.0/(ndiv*baud) !Time per output step
+
+ if(a(1).ne.a1 .or. a(2).ne.a2 .or. a(3).ne.a3) then
+ a1=a(1)
+ a2=a(2)
+ a3=a(3)
+
+! Mix and integrate the complex signal
+ csx(0)=0.
+ w=1.0
+ x0=0.5*(npts+1)
+ s=2.0/npts
+ do i=1,npts
+ x=s*(i-x0)
+ if(mod(i,100).eq.1) then
+ p2=1.5*x*x - 0.5
+ dphi=(a(1) + x*a(2) + p2*a(3)) * (twopi/fsample)
+ wstep=cmplx(cos(dphi),sin(dphi))
+ endif
+ w=w*wstep
+ csx(i)=csx(i-1) + w*cx(i)
+ enddo
+ endif
+
+! Compute 1/2-symbol powers at 1/16-symbol steps.
+ fac=1.e-4
+
+ do i=1,nout
+ j=i*nsps/ndiv
+ k=j-nsph
+ ss(i)=0.
+ if(k.ge.1) then
+ z=csx(j)-csx(k)
+ ss(i)=fac*(real(z)**2 + aimag(z)**2)
+ endif
+ enddo
+
+ ccfmax=0.
+ call timer('ccf2 ',0)
+ call ccf2(ss,nout,nflip,ccf,lagpk)
+ call timer('ccf2 ',1)
+ if(ccf.gt.ccfmax) then
+ ccfmax=ccf
+ dtmax=lagpk*dtstep
+ endif
+ fchisq65=-ccfmax
+
+ call timer('fchisq65',1)
+
+ return
+end function fchisq65
diff --git a/lib/fftw3.f90 b/lib/fftw3.f90
new file mode 100644
index 00000000..440ccc28
--- /dev/null
+++ b/lib/fftw3.f90
@@ -0,0 +1,64 @@
+ INTEGER FFTW_R2HC
+ PARAMETER (FFTW_R2HC=0)
+ INTEGER FFTW_HC2R
+ PARAMETER (FFTW_HC2R=1)
+ INTEGER FFTW_DHT
+ PARAMETER (FFTW_DHT=2)
+ INTEGER FFTW_REDFT00
+ PARAMETER (FFTW_REDFT00=3)
+ INTEGER FFTW_REDFT01
+ PARAMETER (FFTW_REDFT01=4)
+ INTEGER FFTW_REDFT10
+ PARAMETER (FFTW_REDFT10=5)
+ INTEGER FFTW_REDFT11
+ PARAMETER (FFTW_REDFT11=6)
+ INTEGER FFTW_RODFT00
+ PARAMETER (FFTW_RODFT00=7)
+ INTEGER FFTW_RODFT01
+ PARAMETER (FFTW_RODFT01=8)
+ INTEGER FFTW_RODFT10
+ PARAMETER (FFTW_RODFT10=9)
+ INTEGER FFTW_RODFT11
+ PARAMETER (FFTW_RODFT11=10)
+ INTEGER FFTW_FORWARD
+ PARAMETER (FFTW_FORWARD=-1)
+ INTEGER FFTW_BACKWARD
+ PARAMETER (FFTW_BACKWARD=+1)
+ INTEGER FFTW_MEASURE
+ PARAMETER (FFTW_MEASURE=0)
+ INTEGER FFTW_DESTROY_INPUT
+ PARAMETER (FFTW_DESTROY_INPUT=1)
+ INTEGER FFTW_UNALIGNED
+ PARAMETER (FFTW_UNALIGNED=2)
+ INTEGER FFTW_CONSERVE_MEMORY
+ PARAMETER (FFTW_CONSERVE_MEMORY=4)
+ INTEGER FFTW_EXHAUSTIVE
+ PARAMETER (FFTW_EXHAUSTIVE=8)
+ INTEGER FFTW_PRESERVE_INPUT
+ PARAMETER (FFTW_PRESERVE_INPUT=16)
+ INTEGER FFTW_PATIENT
+ PARAMETER (FFTW_PATIENT=32)
+ INTEGER FFTW_ESTIMATE
+ PARAMETER (FFTW_ESTIMATE=64)
+ INTEGER FFTW_ESTIMATE_PATIENT
+ PARAMETER (FFTW_ESTIMATE_PATIENT=128)
+ INTEGER FFTW_BELIEVE_PCOST
+ PARAMETER (FFTW_BELIEVE_PCOST=256)
+ INTEGER FFTW_DFT_R2HC_ICKY
+ PARAMETER (FFTW_DFT_R2HC_ICKY=512)
+ INTEGER FFTW_NONTHREADED_ICKY
+ PARAMETER (FFTW_NONTHREADED_ICKY=1024)
+ INTEGER FFTW_NO_BUFFERING
+ PARAMETER (FFTW_NO_BUFFERING=2048)
+ INTEGER FFTW_NO_INDIRECT_OP
+ PARAMETER (FFTW_NO_INDIRECT_OP=4096)
+ INTEGER FFTW_ALLOW_LARGE_GENERIC
+ PARAMETER (FFTW_ALLOW_LARGE_GENERIC=8192)
+ INTEGER FFTW_NO_RANK_SPLITS
+ PARAMETER (FFTW_NO_RANK_SPLITS=16384)
+ INTEGER FFTW_NO_VRANK_SPLITS
+ PARAMETER (FFTW_NO_VRANK_SPLITS=32768)
+ INTEGER FFTW_NO_VRECURSE
+ PARAMETER (FFTW_NO_VRECURSE=65536)
+ INTEGER FFTW_NO_SIMD
+ PARAMETER (FFTW_NO_SIMD=131072)
diff --git a/lib/fil3.f90 b/lib/fil3.f90
new file mode 100644
index 00000000..0d660610
--- /dev/null
+++ b/lib/fil3.f90
@@ -0,0 +1,159 @@
+subroutine fil3(x1,n1,c2,n2)
+
+! FIR real-to-complex filter designed using ScopeFIR
+!
+!-----------------------------------------------
+! fsample (Hz) 12000 Input sample rate
+! Ntaps 113 Number of filter taps
+! fc (Hz) 500 Cutoff frequency
+! fstop (Hz) 750 Lower limit of stopband
+! Ripple (dB) 0.2 Ripple in passband
+! Stop Atten (dB) 50 Stopband attenuation
+! fmix (HZ) 1500 Mixing frequency
+! fout (Hz) 1500 Output sample rate
+
+! Resulting passband is 1000 - 2000 Hz
+
+! Suggest calling with n1 = 8*n2 + 105, where n2 is the desired number
+! of 1500 Hz output samples.
+
+ parameter (NTAPS=113)
+ parameter (NH=NTAPS/2)
+ parameter (NDOWN=8) !Downsample ratio = 1/8
+ real x1(n1)
+ complex z
+ complex c2(n1/NDOWN)
+
+! Filter coefficients:
+ complex ca(-NH:NH)
+ data ca/ &
+ (-0.001818142144, 0.000000000000), &
+ (-0.000664066641,-0.000664066640), &
+ (-0.000000000000,-0.001044063550), &
+ ( 0.000737290018,-0.000737290010), &
+ ( 0.000908957610,-0.000000000000), &
+ ( 0.000444156615, 0.000444156610), &
+ (-0.000000000000, 0.000202701460), &
+ ( 0.000244876473,-0.000244876470), &
+ ( 0.000978154552, 0.000000000000), &
+ ( 0.001155650277, 0.001155650270), &
+ ( 0.000000000000, 0.002243121590), &
+ (-0.001927618608, 0.001927618600), &
+ (-0.003006201675, 0.000000000000), &
+ (-0.002134087852,-0.002134087850), &
+ ( 0.000000000000,-0.002717699570), &
+ ( 0.001478946738,-0.001478946730), &
+ ( 0.001162489032, 0.000000000000), &
+ (-0.000005589545,-0.000005589540), &
+ (-0.000000000000,-0.001321554800), &
+ ( 0.001873767954,-0.001873767950), &
+ ( 0.003843608784,-0.000000000000), &
+ ( 0.003356874940, 0.003356874940), &
+ (-0.000000000000, 0.005218967040), &
+ (-0.003640348011, 0.003640348010), &
+ (-0.004470167307, 0.000000000000), &
+ (-0.002247131477,-0.002247131470), &
+ (-0.000000000000,-0.001335998900), &
+ (-0.000647656208, 0.000647656200), &
+ (-0.003386100636, 0.000000000000), &
+ (-0.004114456189,-0.004114456180), &
+ ( 0.000000000000,-0.007939147960), &
+ ( 0.006692816134,-0.006692816130), &
+ ( 0.010145641899, 0.000000000000), &
+ ( 0.006920770724, 0.006920770720), &
+ ( 0.000000000000, 0.008285915750), &
+ (-0.003992321524, 0.003992321520), &
+ (-0.001995842303, 0.000000000000), &
+ ( 0.001704388774, 0.001704388770), &
+ (-0.000000000000, 0.007202515550), &
+ (-0.008426458377, 0.008426458370), &
+ (-0.016028350845, 0.000000000000), &
+ (-0.013430355885,-0.013430355880), &
+ (-0.000000000000,-0.020297455950), &
+ ( 0.013791263729,-0.013791263720), &
+ ( 0.016298136197,-0.000000000000), &
+ ( 0.007443596155, 0.007443596150), &
+ (-0.000000000000, 0.002223837360), &
+ ( 0.005924356866,-0.005924356860), &
+ ( 0.020854478160, 0.000000000000), &
+ ( 0.024471928130, 0.024471928130), &
+ ( 0.000000000000, 0.048909701460), &
+ (-0.044508219241, 0.044508219240), &
+ (-0.075874892030, 0.000000000000), &
+ (-0.061450241075,-0.061450241070), &
+ ( 0.000000000000,-0.095332017640), &
+ ( 0.071148679982,-0.071148679980), &
+ ( 0.102420526192, 0.000000000000), &
+ ( 0.071148679982, 0.071148679980), &
+ ( 0.000000000000, 0.095332017640), &
+ (-0.061450241075, 0.061450241070), &
+ (-0.075874892030, 0.000000000000), &
+ (-0.044508219241,-0.044508219240), &
+ ( 0.000000000000,-0.048909701460), &
+ ( 0.024471928130,-0.024471928130), &
+ ( 0.020854478160, 0.000000000000), &
+ ( 0.005924356866, 0.005924356860), &
+ (-0.000000000000,-0.002223837360), &
+ ( 0.007443596155,-0.007443596150), &
+ ( 0.016298136197,-0.000000000000), &
+ ( 0.013791263729, 0.013791263720), &
+ (-0.000000000000, 0.020297455950), &
+ (-0.013430355885, 0.013430355880), &
+ (-0.016028350845, 0.000000000000), &
+ (-0.008426458377,-0.008426458370), &
+ (-0.000000000000,-0.007202515550), &
+ ( 0.001704388774,-0.001704388770), &
+ (-0.001995842303, 0.000000000000), &
+ (-0.003992321524,-0.003992321520), &
+ ( 0.000000000000,-0.008285915750), &
+ ( 0.006920770724,-0.006920770720), &
+ ( 0.010145641899, 0.000000000000), &
+ ( 0.006692816134, 0.006692816130), &
+ ( 0.000000000000, 0.007939147960), &
+ (-0.004114456189, 0.004114456180), &
+ (-0.003386100636, 0.000000000000), &
+ (-0.000647656208,-0.000647656200), &
+ (-0.000000000000, 0.001335998900), &
+ (-0.002247131477, 0.002247131470), &
+ (-0.004470167307, 0.000000000000), &
+ (-0.003640348011,-0.003640348010), &
+ (-0.000000000000,-0.005218967040), &
+ ( 0.003356874940,-0.003356874940), &
+ ( 0.003843608784,-0.000000000000), &
+ ( 0.001873767954, 0.001873767950), &
+ (-0.000000000000, 0.001321554800), &
+ (-0.000005589545, 0.000005589540), &
+ ( 0.001162489032, 0.000000000000), &
+ ( 0.001478946738, 0.001478946730), &
+ ( 0.000000000000, 0.002717699570), &
+ (-0.002134087852, 0.002134087850), &
+ (-0.003006201675, 0.000000000000), &
+ (-0.001927618608,-0.001927618600), &
+ ( 0.000000000000,-0.002243121590), &
+ ( 0.001155650277,-0.001155650270), &
+ ( 0.000978154552, 0.000000000000), &
+ ( 0.000244876473, 0.000244876470), &
+ (-0.000000000000,-0.000202701460), &
+ ( 0.000444156615,-0.000444156610), &
+ ( 0.000908957610,-0.000000000000), &
+ ( 0.000737290018, 0.000737290010), &
+ (-0.000000000000, 0.001044063550), &
+ (-0.000664066641, 0.000664066640), &
+ (-0.001818142144, 0.000000000000)/
+ save ca
+
+ n2=(n1-NTAPS+NDOWN)/NDOWN
+ k0=NH-NDOWN+1
+
+! Loop over all output samples
+ do i=1,n2
+ z=0.
+ k=k0 + NDOWN*i
+ do j=-NH,NH
+ z=z + x1(j+k)*ca(j)
+ enddo
+ c2(i)=z
+ enddo
+
+ return
+end subroutine fil3
diff --git a/lib/fil61.f90 b/lib/fil61.f90
new file mode 100644
index 00000000..faf62a3f
--- /dev/null
+++ b/lib/fil61.f90
@@ -0,0 +1,64 @@
+12000 61 250 750 0.2 50, mix at 1500
+
+
+-0.000000000000 0.001944450121
+-0.000668730681 0.000668730681
+-0.000974850191 -0.000000000000
+-0.000581679123 -0.000581679123
+ 0.000000000000 -0.000439648787
+-0.000148911451 0.000148911451
+-0.001140891736 -0.000000000000
+-0.001653102965 -0.001653102965
+ 0.000000000000 -0.003749915818
+ 0.003740834397 -0.003740834397
+ 0.006834087490 0.000000000000
+ 0.005812808655 0.005812808655
+-0.000000000000 0.009262713933
+-0.006900370427 0.006900370427
+-0.009503248519 -0.000000000000
+-0.005874581677 -0.005874581677
+ 0.000000000000 -0.006017530719
+ 0.001785268072 -0.001785268072
+-0.002214736448 -0.000000000000
+-0.005777038427 -0.005777038427
+ 0.000000000000 -0.015228682747
+ 0.016402831440 -0.016402831440
+ 0.031806920774 0.000000000000
+ 0.028800401613 0.028800401613
+-0.000000000000 0.049589395998
+-0.041000303659 0.041000303659
+-0.065514139214 -0.000000000000
+-0.050781544715 -0.050781544715
+ 0.000000000000 -0.076562341482
+ 0.056225821996 -0.056225821996
+ 0.080516569816 0.000000000000
+ 0.056225821996 0.056225821996
+-0.000000000000 0.076562341482
+-0.050781544715 0.050781544715
+-0.065514139214 -0.000000000000
+-0.041000303659 -0.041000303659
+ 0.000000000000 -0.049589395998
+ 0.028800401613 -0.028800401613
+ 0.031806920774 0.000000000000
+ 0.016402831440 0.016402831440
+-0.000000000000 0.015228682747
+-0.005777038427 0.005777038427
+-0.002214736448 -0.000000000000
+ 0.001785268072 0.001785268072
+-0.000000000000 0.006017530719
+-0.005874581677 0.005874581677
+-0.009503248519 -0.000000000000
+-0.006900370427 -0.006900370427
+ 0.000000000000 -0.009262713933
+ 0.005812808655 -0.005812808655
+ 0.006834087490 0.000000000000
+ 0.003740834397 0.003740834397
+-0.000000000000 0.003749915818
+-0.001653102965 0.001653102965
+-0.001140891736 -0.000000000000
+-0.000148911451 -0.000148911451
+-0.000000000000 0.000439648787
+-0.000581679123 0.000581679123
+-0.000974850191 -0.000000000000
+-0.000668730681 -0.000668730681
+ 0.000000000000 -0.001944450121
diff --git a/lib/fil6521.f90 b/lib/fil6521.f90
new file mode 100644
index 00000000..6e78e63a
--- /dev/null
+++ b/lib/fil6521.f90
@@ -0,0 +1,44 @@
+subroutine fil6521(c1,n1,c2,n2)
+
+! FIR lowpass filter designed using ScopeFIR
+
+! Pass #1 Pass #2
+! -----------------------------------------------
+! fsample (Hz) 1378.125 Input sample rate
+! Ntaps 21 Number of filter taps
+! fc (Hz) 40 Cutoff frequency
+! fstop (Hz) 172.266 Lower limit of stopband
+! Ripple (dB) 0.1 Ripple in passband
+! Stop Atten (dB) 38 Stopband attenuation
+! fout (Hz) 344.531 Output sample rate
+
+ parameter (NTAPS=21)
+ parameter (NH=NTAPS/2)
+ parameter (NDOWN=4) !Downsample ratio = 1/4
+ complex c1(n1)
+ complex c2(n1/NDOWN)
+
+! Filter coefficients:
+ real a(-NH:NH)
+ data a/ &
+ -0.011958606980,-0.013888627387,-0.015601306443,-0.010602249570, &
+ 0.003804023436, 0.028320058273, 0.060903935217, 0.096841904411, &
+ 0.129639871228, 0.152644580853, 0.160917511283, 0.152644580853, &
+ 0.129639871228, 0.096841904411, 0.060903935217, 0.028320058273, &
+ 0.003804023436,-0.010602249570,-0.015601306443,-0.013888627387, &
+ -0.011958606980/
+
+ n2=(n1-NTAPS+NDOWN)/NDOWN
+ k0=NH-NDOWN+1
+
+! Loop over all output samples
+ do i=1,n2
+ c2(i)=0.
+ k=k0 + NDOWN*i
+ do j=-NH,NH
+ c2(i)=c2(i) + c1(j+k)*a(j)
+ enddo
+ enddo
+
+ return
+end subroutine fil6521
diff --git a/lib/filbig.f90 b/lib/filbig.f90
new file mode 100644
index 00000000..cb59b2f1
--- /dev/null
+++ b/lib/filbig.f90
@@ -0,0 +1,127 @@
+subroutine filbig(dd,npts,f0,newdat,c4a,n4,sq0)
+
+! Filter and downsample the real data in array dd(npts), sampled at 12000 Hz.
+! Output is complex, sampled at 1378.125 Hz.
+
+ parameter (NSZ=3413)
+ parameter (NFFT1=672000,NFFT2=77175)
+ parameter (NZ2=1000)
+ real*4 dd(npts) !Input data
+ complex ca(NFFT1) !FFT of input
+ complex c4a(NFFT2) !Output data
+ real*4 s(NZ2)
+ real*8 df
+ real halfpulse(8) !Impulse response of filter (one sided)
+ complex cfilt(NFFT2) !Filter (complex; imag = 0)
+ real rfilt(NFFT2) !Filter (real)
+ integer*8 plan1,plan2,plan3
+ logical first
+ include 'fftw3.f90'
+ equivalence (rfilt,cfilt)
+ data first/.true./,npatience/0/
+ data halfpulse/114.97547150,36.57879257,-20.93789101, &
+ 5.89886379,1.59355187,-2.49138308,0.60910773,-0.04248129/
+ common/refspec/dfref,ref(NSZ)
+ save
+
+ if(npts.lt.0) go to 900 !Clean up at end of program
+
+ if(first) then
+ nflags=FFTW_ESTIMATE
+ if(npatience.eq.1) nflags=FFTW_ESTIMATE_PATIENT
+ if(npatience.eq.2) nflags=FFTW_MEASURE
+ if(npatience.eq.3) nflags=FFTW_PATIENT
+ if(npatience.eq.4) nflags=FFTW_EXHAUSTIVE
+! Plan the FFTs just once
+ call timer('FFTplans ',0)
+ call sfftw_plan_dft_1d(plan1,nfft1,ca,ca,FFTW_BACKWARD,nflags)
+ call sfftw_plan_dft_1d(plan2,nfft2,c4a,c4a,FFTW_FORWARD,nflags)
+ call sfftw_plan_dft_1d(plan3,nfft2,cfilt,cfilt,FFTW_BACKWARD,nflags)
+ call timer('FFTplans ',1)
+
+! Convert impulse response to filter function
+ do i=1,nfft2
+ cfilt(i)=0.
+ enddo
+ fac=0.00625/nfft1
+ cfilt(1)=fac*halfpulse(1)
+ do i=2,8
+ cfilt(i)=fac*halfpulse(i)
+ cfilt(nfft2+2-i)=fac*halfpulse(i)
+ enddo
+ call timer('FFTfilt ',0)
+ call sfftw_execute(plan3)
+ call timer('FFTfilt ',1)
+
+ base=cfilt(nfft2/2+1)
+ do i=1,nfft2
+ rfilt(i)=real(cfilt(i))-base
+ enddo
+
+ df=12000.d0/nfft1
+ first=.false.
+ endif
+
+! When new data comes along, we need to compute a new "big FFT"
+! If we just have a new f0, continue with the existing data in ca.
+
+ if(newdat.ne.0) then
+ nz=min(npts,nfft1)
+ ca(1:nz)=dd(1:nz)
+ ca(nz+1:)=0. !### Should change this to r2c FFT ###
+ call timer('FFTbig ',0)
+ call sfftw_execute(plan1)
+ call timer('FFTbig ',1)
+
+ do i=1,NFFT1/2 !Flatten the spectrum
+ j=nint(i*df/dfref)
+ if(j.lt.1) j=1
+ if(j.gt.NSZ) j=NSZ
+ fac=sqrt(min(30.0,1.0/ref(j)))
+ ca(i)=fac * ca(i)
+ enddo
+ endif
+
+! NB: f0 is the frequency at which we want our filter centered.
+! i0 is the bin number in ca closest to f0.
+
+ i0=nint(f0/df) + 1
+ nh=nfft2/2
+ do i=1,nh !Copy data into c4a and apply
+ j=i0+i-1 !the filter function
+ if(j.ge.1 .and. j.le.nfft1) then
+ c4a(i)=rfilt(i)*ca(j)
+ else
+ c4a(i)=0.
+ endif
+ enddo
+ do i=nh+1,nfft2
+ j=i0+i-1-nfft2
+ if(j.lt.1) j=j+nfft1 !nfft1 was nfft2
+ c4a(i)=rfilt(i)*ca(j)
+ enddo
+
+ nadd=nfft2/NZ2
+ i=0
+ do j=1,NZ2
+ s(j)=0.
+ do n=1,nadd
+ i=i+1
+ s(j)=s(j) + real(c4a(i))**2 + aimag(c4a(i))**2
+ enddo
+ enddo
+ call pctile(s,NZ2,30,sq0)
+
+! Do the short reverse transform, to go back to time domain.
+ call timer('FFTsmall',0)
+ call sfftw_execute(plan2)
+ call timer('FFTsmall',1)
+ n4=min(npts/8,nfft2)
+ return
+
+900 call sfftw_destroy_plan(plan1)
+ call sfftw_destroy_plan(plan2)
+ call sfftw_destroy_plan(plan3)
+
+ return
+end subroutine filbig
diff --git a/lib/fillcom.f90 b/lib/fillcom.f90
new file mode 100644
index 00000000..03fbb2c1
--- /dev/null
+++ b/lib/fillcom.f90
@@ -0,0 +1,25 @@
+subroutine fillcom(nutc0,ndepth0,nrxfreq)
+ character*20 datetime
+ common/npar/nutc,ndiskdat,ntrperiod,nfqso,newdat,npts8,nfa,nfb,ntol, &
+ kin,nzhsym,nsave,nagain,ndepth,ntxmode,nmode,datetime
+ save
+
+ nutc=nutc0
+ ndiskdat=1
+ ntrperiod=60
+ nfqso=nrxfreq
+ newdat=1
+ npts8=74736
+ nfa=2700
+ nfb=4007
+ ntol=3
+ kin=1024
+ nzhsym=173
+ nsave=0
+ ndepth=ndepth0
+ ntxmode=9
+ nmode=9+65
+ datetime="2013-Apr-16 15:13"
+
+ return
+end subroutine fillcom
diff --git a/lib/flat1.f90 b/lib/flat1.f90
new file mode 100644
index 00000000..526ab9bd
--- /dev/null
+++ b/lib/flat1.f90
@@ -0,0 +1,30 @@
+subroutine flat1(psavg,s2,nh,nsteps,nhmax,nsmax)
+
+ real psavg(nh)
+ real s2(nhmax,nsmax)
+ real x(8192),tmp(33)
+
+ nsmo=33
+ ia=nsmo/2 + 1
+ ib=nh - nsmo/2 - 1
+ do i=ia,ib
+ call pctile(psavg(i-nsmo/2),nsmo,50,x(i))
+ enddo
+ do i=1,ia-1
+ x(i)=x(ia)
+ enddo
+ do i=ib+1,nh
+ x(i)=x(ib)
+ enddo
+
+ do i=1,nh
+ psavg(i)=psavg(i)/x(i)
+ do j=1,nsteps
+ s2(i,j)=s2(i,j)/x(i)
+ enddo
+ enddo
+
+ return
+end subroutine flat1
+
+
diff --git a/lib/flat2.f90 b/lib/flat2.f90
new file mode 100644
index 00000000..cebd989f
--- /dev/null
+++ b/lib/flat2.f90
@@ -0,0 +1,18 @@
+subroutine flat2(s,nz,ref)
+
+ parameter (NSMAX=6827)
+ real s(NSMAX)
+ real ref(NSMAX)
+
+ nsmo=10
+ ia=nsmo+1
+ ib=nz-nsmo-1
+ do i=ia,ib
+ call pctile(s(i-nsmo),2*nsmo+1,5,ref(i))
+ enddo
+
+ ref(:ia-1)=ref(ia)
+ ref(ib+1:)=ref(ib)
+
+ return
+end subroutine flat2
diff --git a/lib/flat65.f90 b/lib/flat65.f90
new file mode 100644
index 00000000..7aa106c4
--- /dev/null
+++ b/lib/flat65.f90
@@ -0,0 +1,25 @@
+subroutine flat65(ss,nhsym,maxhsym,nsz,ref)
+
+ real stmp(nsz)
+ real ss(maxhsym,nsz)
+ real ref(nsz)
+
+ npct=28 !Somewhat arbitrary
+ do i=1,nsz
+ call pctile(ss(1,i),nhsym,npct,stmp(i))
+ enddo
+
+ nsmo=33
+ ia=nsmo/2 + 1
+ ib=nsz - nsmo/2 - 1
+ do i=ia,ib
+ call pctile(stmp(i-nsmo/2),nsmo,npct,ref(i))
+ enddo
+ ref(:ia-1)=ref(ia)
+ ref(ib+1:)=ref(ib)
+ ref=4.0*ref
+
+ return
+end subroutine flat65
+
+
diff --git a/lib/four2a.f90 b/lib/four2a.f90
new file mode 100644
index 00000000..c095629b
--- /dev/null
+++ b/lib/four2a.f90
@@ -0,0 +1,90 @@
+subroutine four2a(a,nfft,ndim,isign,iform)
+
+! IFORM = 1, 0 or -1, as data is
+! complex, real, or the first half of a complex array. Transform
+! values are returned in array DATA. They are complex, real, or
+! the first half of a complex array, as IFORM = 1, -1 or 0.
+
+! The transform of a real array (IFORM = 0) dimensioned N(1) by N(2)
+! by ... will be returned in the same array, now considered to
+! be complex of dimensions N(1)/2+1 by N(2) by .... Note that if
+! IFORM = 0 or -1, N(1) must be even, and enough room must be
+! reserved. The missing values may be obtained by complex conjugation.
+
+! The reverse transformation of a half complex array dimensioned
+! N(1)/2+1 by N(2) by ..., is accomplished by setting IFORM
+! to -1. In the N array, N(1) must be the true N(1), not N(1)/2+1.
+! The transform will be real and returned to the input array.
+
+ parameter (NPMAX=100)
+ parameter (NSMALL=16384)
+ complex a(nfft)
+ complex aa(NSMALL)
+ integer nn(NPMAX),ns(NPMAX),nf(NPMAX)
+ integer*8 plan(NPMAX),nl(NPMAX),nloc
+ data nplan/0/,npatience/1/
+! data nplan/0/,npatience/0/
+ include 'fftw3.f90'
+ save plan,nplan,nn,ns,nf,nl
+
+ if(nfft.lt.0) go to 999
+
+ nloc=loc(a)
+ do i=1,nplan
+ if(nfft.eq.nn(i) .and. isign.eq.ns(i) .and. &
+ iform.eq.nf(i) .and. nloc.eq.nl(i)) go to 10
+ enddo
+ if(nplan.ge.NPMAX) stop 'Too many FFTW plans requested.'
+ nplan=nplan+1
+ i=nplan
+ nn(i)=nfft
+ ns(i)=isign
+ nf(i)=iform
+ nl(i)=nloc
+
+! Planning: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT, FFTW_MEASURE,
+! FFTW_PATIENT, FFTW_EXHAUSTIVE
+ nflags=FFTW_ESTIMATE
+ if(npatience.eq.1) nflags=FFTW_ESTIMATE_PATIENT
+ if(npatience.eq.2) nflags=FFTW_MEASURE
+ if(npatience.eq.3) nflags=FFTW_PATIENT
+ if(npatience.eq.4) nflags=FFTW_EXHAUSTIVE
+
+ if(nfft.le.NSMALL) then
+ jz=nfft
+ if(iform.eq.0) jz=nfft/2
+ do j=1,jz
+ aa(j)=a(j)
+ enddo
+ endif
+ if(isign.eq.-1 .and. iform.eq.1) then
+ call sfftw_plan_dft_1d(plan(i),nfft,a,a,FFTW_FORWARD,nflags)
+ else if(isign.eq.1 .and. iform.eq.1) then
+ call sfftw_plan_dft_1d(plan(i),nfft,a,a,FFTW_BACKWARD,nflags)
+ else if(isign.eq.-1 .and. iform.eq.0) then
+ call sfftw_plan_dft_r2c_1d(plan(i),nfft,a,a,nflags)
+ else if(isign.eq.1 .and. iform.eq.-1) then
+ call sfftw_plan_dft_c2r_1d(plan(i),nfft,a,a,nflags)
+ else
+ stop 'Unsupported request in four2a'
+ endif
+ i=nplan
+ if(nfft.le.NSMALL) then
+ jz=nfft
+ if(iform.eq.0) jz=nfft/2
+ do j=1,jz
+ a(j)=aa(j)
+ enddo
+ endif
+
+10 continue
+ call sfftw_execute(plan(i))
+ return
+
+999 do i=1,nplan
+! The test is only to silence a compiler warning:
+ if(ndim.ne.-999) call sfftw_destroy_plan(plan(i))
+ enddo
+
+ return
+end subroutine four2a
diff --git a/lib/gen24.f90 b/lib/gen24.f90
new file mode 100644
index 00000000..e2aaa77a
--- /dev/null
+++ b/lib/gen24.f90
@@ -0,0 +1,86 @@
+subroutine gen24(message,mode4,samfac,ntxdf,iwave,nwave,sendingsh,msgsent,nmsg)
+
+! Encode a JT4 message into a wavefile.
+
+ parameter (NMAX=60*11025) !Max length of wave file
+ character*22 message !Message to be generated
+ character*22 msgsent !Message as it will be received
+ character*3 cok !' ' or 'OOO'
+ real*8 t,dt,phi,f,f0,dfgen,dphi,pi,twopi,samfac,tsymbol
+ integer*2 iwave(NMAX) !Generated wave file
+ integer sendingsh
+ integer dgen(13)
+ integer*1 data0(13),symbol(216)
+ logical first
+ include 'prcom2.f'
+ data first/.true./
+ save
+
+ nsym=207 !Symbols per transmission
+ if(first) then
+ do i=1,nsym
+ pr2(i)=2*npr2(i)-1
+ enddo
+ pi=4.d0*atan(1.d0)
+ twopi=2.d0*pi
+ first=.false.
+ endif
+
+ call chkmsg(message,cok,nspecial,flip)
+ call packmsg(message,dgen) !Pack 72-bit message into 12 six-bit symbols
+ call entail(dgen,data0)
+ call unpackmsg(dgen,msgsent)
+
+ nbytes=(72+31+7)/8
+ call encode(data0,nbytes,symbol(2)) !Convolutional encoding
+ symbol(1)=0 !Reference phase
+ sendingsh=0
+ if(iand(dgen(10),8).ne.0) sendingsh=-1 !Plain text flag
+ call interleave24(symbol(2),1) !Apply JT4 interleaving
+
+! Set up necessary constants
+ tsymbol=2520.d0/11025.d0
+ dt=1.d0/(samfac*11025.d0)
+ f0=118*11025.d0/1024 + ntxdf
+ dfgen=11025.d0/2520 !4.375 Hz
+ t=0.d0
+ phi=0.d0
+ j0=0
+ ndata=(nsym*11025.d0*samfac*tsymbol)/2
+ ndata=2*ndata
+ do i=1,ndata
+ t=t+dt
+ j=int(t/tsymbol) + 1 !Symbol number, 1-207
+ if(j.ne.j0) then
+ f=f0 + (npr2(j)+2*symbol(j)-1.5) * dfgen * mode4
+ if(flip.lt.0.0) f=f0+((1-npr2(j))+2*symbol(j)-1.5)*dfgen*mode4
+ dphi=twopi*dt*f
+ j0=j
+ endif
+ phi=phi+dphi
+ iwave(i)=32767.0*sin(phi)
+ enddo
+
+ do j=1,5512 !Put another 0.5 sec of silence at end
+ i=i+1
+ iwave(i)=0
+ enddo
+ nwave=i
+
+ if(flip.lt.0.0) then
+ do i=22,1,-1
+ if(msgsent(i:i).ne.' ') goto 10
+ enddo
+10 msgsent=msgsent(1:i)//' OOO'
+ endif
+ do i=22,1,-1
+ if(msgsent(i:i).ne.' ') goto 20
+ enddo
+20 nmsg=i
+
+! write(*,3002) (symbol(i),i=1,207)
+! 3002 format(70i1)
+
+ return
+end subroutine gen24
+
diff --git a/lib/gen65.f90 b/lib/gen65.f90
new file mode 100644
index 00000000..85802384
--- /dev/null
+++ b/lib/gen65.f90
@@ -0,0 +1,65 @@
+subroutine gen65(msg0,ichk,msgsent,itone,itext)
+
+! Encodes a JT65 message to yieild itone(1:126)
+! Temporarily, does not implement EME shorthands
+
+ character*22 msg0
+ character*22 message !Message to be generated
+ character*22 msgsent !Message as it will be received
+ integer itone(126)
+! character*3 cok !' ' or 'OOO'
+ integer dgen(13)
+ integer sent(63)
+ logical text
+ integer nprc(126)
+ data nprc/1,0,0,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0, &
+ 0,1,0,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,1,1, &
+ 0,1,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1, &
+ 0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,1, &
+ 1,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1, &
+ 0,1,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1, &
+ 1,1,1,1,1,1/
+ save
+
+ message=msg0
+ do i=1,22
+ if(ichar(message(i:i)).eq.0) then
+ message(i:)=' '
+ exit
+ endif
+ enddo
+
+ do i=1,22 !Strip leading blanks
+ if(message(1:1).ne.' ') exit
+ message=message(i+1:)
+ enddo
+
+ nspecial=0
+! call chkmsg(message,cok,nspecial,flip)
+ if(nspecial.eq.0) then
+ call packmsg(message,dgen,text) !Pack message into 72 bits
+ itext=0
+ if(text) itext=1
+ call unpackmsg(dgen,msgsent) !Unpack to get message sent
+ if(ichk.ne.0) go to 999 !Return if checking only
+
+ call rs_encode(dgen,sent) !Apply Reed-Solomon code
+ call interleave63(sent,1) !Apply interleaving
+ call graycode65(sent,63,1) !Apply Gray code
+ nsym=126 !Symbols per transmission
+ else
+ nsym=32
+ endif
+
+ k=0
+ do j=1,nsym
+ if(nprc(j).eq.0) then
+ k=k+1
+ itone(j)=sent(k)+2
+ else
+ itone(j)=0
+ endif
+ enddo
+
+999 return
+end subroutine gen65
diff --git a/lib/genjt9.f90 b/lib/genjt9.f90
new file mode 100644
index 00000000..90427e1c
--- /dev/null
+++ b/lib/genjt9.f90
@@ -0,0 +1,58 @@
+subroutine genjt9(msg0,ichk,msgsent,i4tone,itext)
+
+! Encodes a JT9 message and returns msgsent, the message as it will
+! be decoded, and an integer array i4tone(85) of 9-FSK tone values
+! in the range 0-8.
+
+ character*22 msg0
+ character*22 message !Message to be generated
+ character*22 msgsent !Message as it will be received
+ integer*4 i4Msg6BitWords(13) !72-bit message as 6-bit words
+ integer*1 i1Msg8BitBytes(13) !72 bits and zero tail as 8-bit bytes
+ integer*1 i1EncodedBits(207) !Encoded information-carrying bits
+ integer*1 i1ScrambledBits(207) !Encoded bits after interleaving
+ integer*4 i4DataSymbols(69) !Data symbols (values 0-7)
+ integer*4 i4GrayCodedSymbols(69) !Gray-coded symbols (values 0-7)
+ integer*4 i4tone(85) !Tone #s, data and sync (values 0-8)
+ logical text
+ include 'jt9sync.f90'
+ save
+
+ message=msg0
+ do i=1,22
+ if(ichar(message(i:i)).eq.0) then
+ message(i:)=' '
+ exit
+ endif
+ enddo
+
+ do i=1,22 !Strip leading blanks
+ if(message(1:1).ne.' ') exit
+ message=message(i+1:)
+ enddo
+
+ call packmsg(message,i4Msg6BitWords,text) !Pack message into 12 6-bit bytes
+ itext=0
+ if(text) itext=1
+ call unpackmsg(i4Msg6BitWords,msgsent) !Unpack to get msgsent
+ if(ichk.ne.0) go to 999
+ call entail(i4Msg6BitWords,i1Msg8BitBytes) !Add tail, convert to 8-bit bytes
+ nsym2=206
+ call encode232(i1Msg8BitBytes,nsym2,i1EncodedBits) !Encode K=32, r=1/2
+ call interleave9(i1EncodedBits,1,i1ScrambledBits) !Interleave the bits
+ call packbits(i1ScrambledBits,nsym2,3,i4DataSymbols) !Pack 3-bits into words
+ call graycode(i4DataSymbols,69,1,i4GrayCodedSymbols) !Apply Gray code
+
+! Insert sync symbols at ntone=0 and add 1 to the data-tone numbers.
+ j=0
+ do i=1,85
+ if(isync(i).eq.1) then
+ i4tone(i)=0
+ else
+ j=j+1
+ i4tone(i)=i4GrayCodedSymbols(j)+1
+ endif
+ enddo
+
+999 return
+end subroutine genjt9
diff --git a/lib/genmet.f90 b/lib/genmet.f90
new file mode 100644
index 00000000..0682bf80
--- /dev/null
+++ b/lib/genmet.f90
@@ -0,0 +1,88 @@
+program genmet
+
+! Generate metric table for M-FSK modulation.
+
+ character*12 arg
+ real*4 r(0:255)
+ integer hist(2,-128:128)
+ data hist/514*0/,idum/-1/
+
+ lim(x)=min(127,max(-128,nint(scale*x)))
+
+ nargs=iargc()
+ if(nargs.ne.5) then
+ print*,'Usage: genmet ncoh nadd m0 snr iters'
+ go to 999
+ endif
+ call getarg(1,arg)
+ read(arg,*) ncoh
+ call getarg(2,arg)
+ read(arg,*) nadd
+ call getarg(3,arg)
+ read(arg,*) m0
+ call getarg(4,arg)
+ read(arg,*) snr
+ call getarg(5,arg)
+ read(arg,*) iters
+
+ ntones=2**m0
+ xm0=m0
+ scale=5.0
+ fac=sqrt(1.0/nadd)
+ s=sqrt(10.0**(0.1*snr))
+ hist=0
+ nerr=0
+
+ do iter=1,iters
+ do i=0,ntones-1
+ r(i)=0.
+ do n=1,nadd
+ x1=0.707*gran()
+ y1=0.707*gran()
+ if(i.eq.0) x1=x1+s
+ if(ncoh.eq.0) r(i)=r(i) + x1*x1 + y1*y1
+ if(ncoh.ne.0) r(i)=r(i) + x1
+ enddo
+ r(i)=fac*r(i)
+ enddo
+ do m=0,m0-1
+ n=2**m
+ r1=0.
+ r2=0.
+ do i=0,ntones-1
+ if(iand(i,n).ne.0) r1=max(r1,r(i))
+ if(iand(i,n).eq.0) r2=max(r2,r(i))
+ enddo
+ don=r2-r1
+ doff=r1-r2
+ if(don.lt.0.0) nerr=nerr+1
+ j1=lim(doff)
+ hist(1,j1)=hist(1,j1)+1
+ j2=lim(don)
+ hist(2,j2)=hist(2,j2)+1
+ enddo
+ enddo
+
+ do i=-128,127
+ write(13,1010) i/scale,hist(1,i)/(xm0*iters),hist(2,i)/(xm0*iters)
+1010 format(f8.3,2f12.9)
+ enddo
+
+ ber=nerr/(xm0*iters)
+ write(*,1020) nadd,m0,snr,ber
+1020 format('nadd:',i3,' m0:',i2,' snr: 'f5.1,' BER:',f8.3)
+
+ xln2=log(2.0)
+ do i=-128,127
+ p1=hist(2,i)/(xm0*iters)
+ p0=hist(1,i)/(xm0*iters)
+ if(p0+p1.eq.0.0 .and. i.lt.0) p0=1.e-6
+ if(p0+p1.eq.0.0 .and. i.gt.0) p1=1.e-6
+ xlhd0=log(max(0.001,2.0*p0/(p0+p1)))/xln2
+ xlhd1=log(max(0.001,2.0*p1/(p0+p1)))/xln2
+ write(14,1012) i/scale,xlhd0,xlhd1,p0/(p0+p1),p1/(p0+p1)
+1012 format(f7.1,2f8.3,2f9.6)
+ enddo
+
+999 end program genmet
+
diff --git a/lib/geodist.f90 b/lib/geodist.f90
new file mode 100644
index 00000000..2ca75535
--- /dev/null
+++ b/lib/geodist.f90
@@ -0,0 +1,96 @@
+subroutine geodist(Eplat,Eplon,Stlat,Stlon,Az,Baz,Dist)
+ implicit none
+ real eplat, eplon, stlat, stlon, az, baz, dist
+
+! JHT: In actual fact, I use the first two arguments for "My Location",
+! the second two for "His location"; West longitude is positive.
+
+! Taken directly from:
+! Thomas, P.D., 1970, Spheroidal geodesics, reference systems,
+! & local geometry, U.S. Naval Oceanographi!Office SP-138,
+! 165 pp.
+! assumes North Latitude and East Longitude are positive
+
+! EpLat, EpLon = End point Lat/Long
+! Stlat, Stlon = Start point lat/long
+! Az, BAz = direct & reverse azimuith
+! Dist = Dist (km); Deg = central angle, discarded
+
+ real BOA, F, P1R, P2R, L1R, L2R, DLR, T1R, T2R, TM, &
+ DTM, STM, CTM, SDTM,CDTM, KL, KK, SDLMR, L, &
+ CD, DL, SD, T, U, V, D, X, E, Y, A, FF64, TDLPM, &
+ HAPBR, HAMBR, A1M2, A2M1
+
+ real AL,BL,D2R,Pi2
+
+ data AL/6378206.4/ ! Clarke 1866 ellipsoid
+ data BL/6356583.8/
+! real pi /3.14159265359/
+ data D2R/0.01745329251994/ ! degrees to radians conversion factor
+ data Pi2/6.28318530718/
+
+ BOA = BL/AL
+ F = 1.0 - BOA
+! Convert st/end pts to radians
+ P1R = Eplat * D2R
+ P2R = Stlat * D2R
+ L1R = Eplon * D2R
+ L2R = StLon * D2R
+ DLR = L2R - L1R ! DLR = Delta Long in Rads
+ T1R = ATan(BOA * Tan(P1R))
+ T2R = ATan(BOA * Tan(P2R))
+ TM = (T1R + T2R) / 2.0
+ DTM = (T2R - T1R) / 2.0
+ STM = Sin(TM)
+ CTM = Cos(TM)
+ SDTM = Sin(DTM)
+ CDTM = Cos(DTM)
+ KL = STM * CDTM
+ KK = SDTM * CTM
+ SDLMR = Sin(DLR/2.0)
+ L = SDTM * SDTM + SDLMR * SDLMR * (CDTM * CDTM - STM * STM)
+ CD = 1.0 - 2.0 * L
+ DL = ACos(CD)
+ SD = Sin(DL)
+ T = DL/SD
+ U = 2.0 * KL * KL / (1.0 - L)
+ V = 2.0 * KK * KK / L
+ D = 4.0 * T * T
+ X = U + V
+ E = -2.0 * CD
+ Y = U - V
+ A = -D * E
+ FF64 = F * F / 64.0
+ Dist = AL*SD*(T -(F/4.0)*(T*X-Y)+FF64*(X*(A+(T-(A+E) &
+ /2.0)*X)+Y*(-2.0*D+E*Y)+D*X*Y))/1000.0
+ TDLPM = Tan((DLR+(-((E*(4.0-X)+2.0*Y)*((F/2.0)*T+FF64* &
+ (32.0*T+(A-20.0*T)*X-2.0*(D+2.0)*Y))/4.0)*Tan(DLR)))/2.0)
+ HAPBR = ATan2(SDTM,(CTM*TDLPM))
+ HAMBR = Atan2(CDTM,(STM*TDLPM))
+ A1M2 = Pi2 + HAMBR - HAPBR
+ A2M1 = Pi2 - HAMBR - HAPBR
+
+1 If ((A1M2 .ge. 0.0) .AND. (A1M2 .lt. Pi2)) GOTO 5
+ If (A1M2 .lt. Pi2) GOTO 4
+ A1M2 = A1M2 - Pi2
+ GOTO 1
+4 A1M2 = A1M2 + Pi2
+ GOTO 1
+
+! All of this gens the proper az, baz (forward and back azimuth)
+
+5 If ((A2M1 .ge. 0.0) .AND. (A2M1 .lt. Pi2)) GOTO 9
+ If (A2M1 .lt. Pi2) GOTO 8
+ A2M1 = A2M1 - Pi2
+ GOTO 5
+8 A2M1 = A2M1 + Pi2
+ GOTO 5
+
+9 Az = A1M2 / D2R
+ BAZ = A2M1 / D2R
+
+!Fix the mirrored coords here.
+
+ az = 360.0 - az
+ baz = 360.0 - baz
+end subroutine geodist
diff --git a/lib/getlags.f90 b/lib/getlags.f90
new file mode 100644
index 00000000..0d1f5d6e
--- /dev/null
+++ b/lib/getlags.f90
@@ -0,0 +1,27 @@
+subroutine getlags(nsps8,lag0,lag1,lag2)
+ if(nsps8.eq.864) then
+ lag1=39
+ lag2=291
+ lag0=123
+ else if(nsps8.eq.1920) then
+ lag1=70
+ lag2=184
+ lag0=108
+ else if(nsps8.eq.5120) then
+ lag1=84
+ lag2=129
+ lag0=99
+ else if(nsps8.eq.10368) then
+ lag1=91
+ lag2=112
+ lag0=98
+ else if(nsps8.eq.31500) then
+ lag1=93
+ lag2=102
+ lag0=96
+ else
+ stop 'Error in getlags'
+ endif
+
+ return
+end subroutine getlags
diff --git a/lib/getmet24.f90 b/lib/getmet24.f90
new file mode 100644
index 00000000..f35a90ae
--- /dev/null
+++ b/lib/getmet24.f90
@@ -0,0 +1,52 @@
+subroutine getmet24(mode,mettab)
+
+! Return appropriate metric table for soft-decision convolutional decoder.
+
+! Metric table (RxSymbol,TxSymbol)
+ integer mettab(0:255,0:1)
+ real*4 xx0(0:255)
+ data xx0/ &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, &
+ 0.988, 1.000, 0.991, 0.993, 1.000, 0.995, 1.000, 0.991, &
+ 1.000, 0.991, 0.992, 0.991, 0.990, 0.990, 0.992, 0.996, &
+ 0.990, 0.994, 0.993, 0.991, 0.992, 0.989, 0.991, 0.987, &
+ 0.985, 0.989, 0.984, 0.983, 0.979, 0.977, 0.971, 0.975, &
+ 0.974, 0.970, 0.970, 0.970, 0.967, 0.962, 0.960, 0.957, &
+ 0.956, 0.953, 0.942, 0.946, 0.937, 0.933, 0.929, 0.920, &
+ 0.917, 0.911, 0.903, 0.895, 0.884, 0.877, 0.869, 0.858, &
+ 0.846, 0.834, 0.821, 0.806, 0.790, 0.775, 0.755, 0.737, &
+ 0.713, 0.691, 0.667, 0.640, 0.612, 0.581, 0.548, 0.510, &
+ 0.472, 0.425, 0.378, 0.328, 0.274, 0.212, 0.146, 0.075, &
+ 0.000,-0.079,-0.163,-0.249,-0.338,-0.425,-0.514,-0.606, &
+ -0.706,-0.796,-0.895,-0.987,-1.084,-1.181,-1.280,-1.376, &
+ -1.473,-1.587,-1.678,-1.790,-1.882,-1.992,-2.096,-2.201, &
+ -2.301,-2.411,-2.531,-2.608,-2.690,-2.829,-2.939,-3.058, &
+ -3.164,-3.212,-3.377,-3.463,-3.550,-3.768,-3.677,-3.975, &
+ -4.062,-4.098,-4.186,-4.261,-4.472,-4.621,-4.623,-4.608, &
+ -4.822,-4.870,-4.652,-4.954,-5.108,-5.377,-5.544,-5.995, &
+ -5.632,-5.826,-6.304,-6.002,-6.559,-6.369,-6.658,-7.016, &
+ -6.184,-7.332,-6.534,-6.152,-6.113,-6.288,-6.426,-6.313, &
+ -9.966,-6.371,-9.966,-7.055,-9.966,-6.629,-6.313,-9.966, &
+ -5.858,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, &
+ -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966/
+ save
+
+ bias=0.5
+ scale=10.0
+ do i=0,255
+ mettab(i,0)=nint(scale*(xx0(i)-bias))
+ if(i.ge.1) mettab(256-i,1)=mettab(i,0)
+ enddo
+
+ return
+end subroutine getmet24
+
diff --git a/lib/getpfx1.f90 b/lib/getpfx1.f90
new file mode 100644
index 00000000..4d4e7aa0
--- /dev/null
+++ b/lib/getpfx1.f90
@@ -0,0 +1,97 @@
+subroutine getpfx1(callsign,k,nv2)
+
+ character*12 callsign0,callsign,lof,rof
+ character*8 c
+ character addpfx*8,tpfx*4,tsfx*3
+ logical ispfx,issfx,invalid
+ common/pfxcom/addpfx
+ include 'pfx.f90'
+
+ callsign0=callsign
+ nv2=0
+ iz=index(callsign,' ') - 1
+ if(iz.lt.0) iz=12
+ islash=index(callsign(1:iz),'/')
+ k=0
+ if(k.eq.0) go to 10 !### Always use JT65v2 ###
+ c=' '
+ if(islash.gt.0 .and. islash.le.(iz-4)) then
+! Add-on prefix
+ c=callsign(1:islash-1)
+ callsign=callsign(islash+1:iz)
+ do i=1,NZ
+ if(pfx(i)(1:4).eq.c) then
+ k=i
+ go to 10
+ endif
+ enddo
+ if(addpfx.eq.c) then
+ k=449
+ go to 10
+ endif
+
+ else if(islash.eq.(iz-1)) then
+! Add-on suffix
+ c=callsign(islash+1:iz)
+ callsign=callsign(1:islash-1)
+ do i=1,NZ2
+ if(sfx(i).eq.c(1:1)) then
+ k=400+i
+ go to 10
+ endif
+ enddo
+ endif
+
+10 if(islash.ne.0 .and.k.eq.0) then
+! Original JT65 would force this compound callsign to be treated as
+! plain text. In JT65v2, we will encode the prefix or suffix into nc1.
+! The task here is to compute the proper value of k.
+ lof=callsign0(:islash-1)
+ rof=callsign0(islash+1:)
+ llof=len_trim(lof)
+ lrof=len_trim(rof)
+ ispfx=(llof.gt.0 .and. llof.le.4)
+ issfx=(lrof.gt.0 .and. lrof.le.3)
+ invalid=.not.(ispfx.or.issfx)
+ if(ispfx.and.issfx) then
+ if(llof.lt.3) issfx=.false.
+ if(lrof.lt.3) ispfx=.false.
+ if(ispfx.and.issfx) then
+ i=ichar(callsign0(islash-1:islash-1))
+ if(i.ge.ichar('0') .and. i.le.ichar('9')) then
+ issfx=.false.
+ else
+ ispfx=.false.
+ endif
+ endif
+ endif
+
+ if(invalid) then
+ k=-1
+ else
+ if(ispfx) then
+ tpfx=lof(1:4)
+ k=nchar(tpfx(1:1))
+ k=37*k + nchar(tpfx(2:2))
+ k=37*k + nchar(tpfx(3:3))
+ k=37*k + nchar(tpfx(4:4))
+ nv2=1
+ i=index(callsign0,'/')
+ callsign=callsign0(:i-1)
+ callsign=callsign0(i+1:)
+ endif
+ if(issfx) then
+ tsfx=rof(1:3)
+ k=nchar(tsfx(1:1))
+ k=37*k + nchar(tsfx(2:2))
+ k=37*k + nchar(tsfx(3:3))
+ nv2=2
+ i=index(callsign0,'/')
+ callsign=callsign0(:i-1)
+ endif
+ endif
+ endif
+
+ return
+end subroutine getpfx1
+
diff --git a/lib/getpfx2.f90 b/lib/getpfx2.f90
new file mode 100644
index 00000000..d747e7f2
--- /dev/null
+++ b/lib/getpfx2.f90
@@ -0,0 +1,24 @@
+subroutine getpfx2(k0,callsign)
+
+ character callsign*12
+ include 'pfx.f90'
+ character addpfx*8
+ common/pfxcom/addpfx
+
+ k=k0
+ if(k.gt.450) k=k-450
+ if(k.ge.1 .and. k.le.NZ) then
+ iz=index(pfx(k),' ') - 1
+ callsign=pfx(k)(1:iz)//'/'//callsign
+ else if(k.ge.401 .and. k.le.400+NZ2) then
+ iz=index(callsign,' ') - 1
+ callsign=callsign(1:iz)//'/'//sfx(k-400)
+ else if(k.eq.449) then
+ iz=index(addpfx,' ') - 1
+ if(iz.lt.1) iz=8
+ callsign=addpfx(1:iz)//'/'//callsign
+ endif
+
+ return
+end subroutine getpfx2
+
diff --git a/lib/gran.c b/lib/gran.c
new file mode 100644
index 00000000..ceeb6da7
--- /dev/null
+++ b/lib/gran.c
@@ -0,0 +1,28 @@
+#include <stdlib.h>
+#include <math.h>
+
+/* Generate gaussian random float with mean=0 and std_dev=1 */
+float gran_()
+{
+ float fac,rsq,v1,v2;
+ static float gset;
+ static int iset;
+
+ if(iset){
+ /* Already got one */
+ iset = 0;
+ return gset;
+ }
+ /* Generate two evenly distributed numbers between -1 and +1
+ * that are inside the unit circle
+ */
+ do {
+ v1 = 2.0 * (float)rand() / RAND_MAX - 1;
+ v2 = 2.0 * (float)rand() / RAND_MAX - 1;
+ rsq = v1*v1 + v2*v2;
+ } while(rsq >= 1.0 || rsq == 0.0);
+ fac = sqrt(-2.0*log(rsq)/rsq);
+ gset = v1*fac;
+ iset++;
+ return v2*fac;
+}
diff --git a/lib/graycode.f90 b/lib/graycode.f90
new file mode 100644
index 00000000..21c1f908
--- /dev/null
+++ b/lib/graycode.f90
@@ -0,0 +1,9 @@
+subroutine graycode(ia,n,idir,ib)
+
+ integer ia(n),ib(n)
+ do i=1,n
+ ib(i)=igray(ia(i),idir)
+ enddo
+
+ return
+end subroutine graycode
diff --git a/lib/graycode65.f90 b/lib/graycode65.f90
new file mode 100644
index 00000000..3ee9a42f
--- /dev/null
+++ b/lib/graycode65.f90
@@ -0,0 +1,9 @@
+subroutine graycode65(dat,n,idir)
+
+ integer dat(n)
+ do i=1,n
+ dat(i)=igray(dat(i),idir)
+ enddo
+
+ return
+end subroutine graycode65
diff --git a/lib/grid2deg.f90 b/lib/grid2deg.f90
new file mode 100644
index 00000000..843fc848
--- /dev/null
+++ b/lib/grid2deg.f90
@@ -0,0 +1,38 @@
+subroutine grid2deg(grid0,dlong,dlat)
+
+! Converts Maidenhead grid locator to degrees of West longitude
+! and North latitude.
+
+ character*6 grid0,grid
+ character*1 g1,g2,g3,g4,g5,g6
+
+ grid=grid0
+ i=ichar(grid(5:5))
+ if(grid(5:5).eq.' ' .or. i.le.64 .or. i.ge.128) grid(5:6)='mm'
+
+ if(grid(1:1).ge.'a' .and. grid(1:1).le.'z') grid(1:1)= &
+ char(ichar(grid(1:1))+ichar('A')-ichar('a'))
+ if(grid(2:2).ge.'a' .and. grid(2:2).le.'z') grid(2:2)= &
+ char(ichar(grid(2:2))+ichar('A')-ichar('a'))
+ if(grid(5:5).ge.'A' .and. grid(5:5).le.'Z') grid(5:5)= &
+ char(ichar(grid(5:5))-ichar('A')+ichar('a'))
+ if(grid(6:6).ge.'A' .and. grid(6:6).le.'Z') grid(6:6)= &
+ char(ichar(grid(6:6))-ichar('A')+ichar('a'))
+
+ g1=grid(1:1)
+ g2=grid(2:2)
+ g3=grid(3:3)
+ g4=grid(4:4)
+ g5=grid(5:5)
+ g6=grid(6:6)
+
+ nlong = 180 - 20*(ichar(g1)-ichar('A'))
+ n20d = 2*(ichar(g3)-ichar('0'))
+ xminlong = 5*(ichar(g5)-ichar('a')+0.5)
+ dlong = nlong - n20d - xminlong/60.0
+ nlat = -90+10*(ichar(g2)-ichar('A')) + ichar(g4)-ichar('0')
+ xminlat = 2.5*(ichar(g6)-ichar('a')+0.5)
+ dlat = nlat + xminlat/60.0
+
+ return
+end subroutine grid2deg
diff --git a/lib/grid2k.f90 b/lib/grid2k.f90
new file mode 100644
index 00000000..f68b1409
--- /dev/null
+++ b/lib/grid2k.f90
@@ -0,0 +1,12 @@
+subroutine grid2k(grid,k)
+
+ character*6 grid
+
+ call grid2deg(grid,xlong,xlat)
+ nlong=nint(xlong)
+ nlat=nint(xlat)
+ k=0
+ if(nlat.ge.85) k=5*(nlong+179)/2 + nlat-84
+
+ return
+end subroutine grid2k
diff --git a/lib/grid2n.f90 b/lib/grid2n.f90
new file mode 100644
index 00000000..d02d786d
--- /dev/null
+++ b/lib/grid2n.f90
@@ -0,0 +1,10 @@
+subroutine grid2n(grid,n)
+ character*4 grid
+
+ i1=ichar(grid(1:1))-ichar('A')
+ i2=ichar(grid(3:3))-ichar('0')
+ i=10*i1 + i2
+ n=-i - 31
+
+ return
+end subroutine grid2n
diff --git a/lib/igray.c b/lib/igray.c
new file mode 100644
index 00000000..4646898b
--- /dev/null
+++ b/lib/igray.c
@@ -0,0 +1,18 @@
+int igray_(int *n0, int *idir)
+{
+ int n;
+ unsigned long sh;
+ unsigned long nn;
+ n=*n0;
+
+ if(*idir>0) return (n ^ (n >> 1));
+
+ sh = 1;
+ nn = (n >> sh);
+ while (nn > 0) {
+ n ^= nn;
+ sh <<= 1;
+ nn = (n >> sh);
+ }
+ return (n);
+}
diff --git a/lib/indexx.f90 b/lib/indexx.f90
new file mode 100644
index 00000000..57c1ec07
--- /dev/null
+++ b/lib/indexx.f90
@@ -0,0 +1,19 @@
+subroutine indexx(n,arr,indx)
+
+ parameter (NMAX=3000)
+ integer indx(n)
+ real arr(n)
+ real brr(NMAX)
+ if(n.gt.NMAX) then
+ print*,'n=',n,' too big in indexx.'
+ stop
+ endif
+ do i=1,n
+ brr(i)=arr(i)
+ indx(i)=i
+ enddo
+ call ssort(brr,indx,n,2)
+
+ return
+end subroutine indexx
+
diff --git a/lib/init_rs.c b/lib/init_rs.c
new file mode 100644
index 00000000..eb271194
--- /dev/null
+++ b/lib/init_rs.c
@@ -0,0 +1,126 @@
+/* Initialize a RS codec
+ *
+ * Copyright 2002 Phil Karn, KA9Q
+ * May be used under the terms of the GNU General Public License (GPL)
+ */
+#include <stdlib.h>
+
+#ifdef CCSDS
+#include "ccsds.h"
+#elif defined(BIGSYM)
+#include "int.h"
+#else
+#include "char.h"
+#endif
+
+//#define NULL ((void *)0)
+
+void FREE_RS(void *p){
+ struct rs *rs = (struct rs *)p;
+
+ free(rs->alpha_to);
+ free(rs->index_of);
+ free(rs->genpoly);
+ free(rs);
+}
+
+/* Initialize a Reed-Solomon codec
+ * symsize = symbol size, bits (1-8)
+ * gfpoly = Field generator polynomial coefficients
+ * fcr = first root of RS code generator polynomial, index form
+ * prim = primitive element to generate polynomial roots
+ * nroots = RS code generator polynomial degree (number of roots)
+ * pad = padding bytes at front of shortened block
+ */
+void *INIT_RS(int symsize,int gfpoly,int fcr,int prim,
+ int nroots,int pad){
+ struct rs *rs;
+ int i, j, sr,root,iprim;
+
+ /* Check parameter ranges */
+ if(symsize < 0 || symsize > 8*sizeof(DTYPE))
+ return NULL; /* Need version with ints rather than chars */
+
+ if(fcr < 0 || fcr >= (1<<symsize))
+ return NULL;
+ if(prim <= 0 || prim >= (1<<symsize))
+ return NULL;
+ if(nroots < 0 || nroots >= (1<<symsize))
+ return NULL; /* Can't have more roots than symbol values! */
+ if(pad < 0 || pad >= ((1<<symsize) -1 - nroots))
+ return NULL; /* Too much padding */
+
+ rs = (struct rs *)calloc(1,sizeof(struct rs));
+ rs->mm = symsize;
+ rs->nn = (1<<symsize)-1;
+ rs->pad = pad;
+
+ rs->alpha_to = (DTYPE *)malloc(sizeof(DTYPE)*(rs->nn+1));
+ if(rs->alpha_to == NULL){
+ free(rs);
+ return NULL;
+ }
+ rs->index_of = (DTYPE *)malloc(sizeof(DTYPE)*(rs->nn+1));
+ if(rs->index_of == NULL){
+ free(rs->alpha_to);
+ free(rs);
+ return NULL;
+ }
+
+ /* Generate Galois field lookup tables */
+ rs->index_of[0] = A0; /* log(zero) = -inf */
+ rs->alpha_to[A0] = 0; /* alpha**-inf = 0 */
+ sr = 1;
+ for(i=0;i<rs->nn;i++){
+ rs->index_of[sr] = i;
+ rs->alpha_to[i] = sr;
+ sr <<= 1;
+ if(sr & (1<<symsize))
+ sr ^= gfpoly;
+ sr &= rs->nn;
+ }
+ if(sr != 1){
+ /* field generator polynomial is not primitive! */
+ free(rs->alpha_to);
+ free(rs->index_of);
+ free(rs);
+ return NULL;
+ }
+
+ /* Form RS code generator polynomial from its roots */
+ rs->genpoly = (DTYPE *)malloc(sizeof(DTYPE)*(nroots+1));
+ if(rs->genpoly == NULL){
+ free(rs->alpha_to);
+ free(rs->index_of);
+ free(rs);
+ return NULL;
+ }
+ rs->fcr = fcr;
+ rs->prim = prim;
+ rs->nroots = nroots;
+
+ /* Find prim-th root of 1, used in decoding */
+ for(iprim=1;(iprim % prim) != 0;iprim += rs->nn)
+ ;
+ rs->iprim = iprim / prim;
+
+ rs->genpoly[0] = 1;
+ for (i = 0,root=fcr*prim; i < nroots; i++,root += prim) {
+ rs->genpoly[i+1] = 1;
+
+ /* Multiply rs->genpoly[] by @**(root + x) */
+ for (j = i; j > 0; j--){
+ if (rs->genpoly[j] != 0)
+ rs->genpoly[j] = rs->genpoly[j-1] ^ rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[j]] + root)];
+ else
+ rs->genpoly[j] = rs->genpoly[j-1];
+ }
+ /* rs->genpoly[0] can never be zero */
+ rs->genpoly[0] = rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[0]] + root)];
+ }
+ /* convert rs->genpoly[] to index form for quicker encoding */
+ for (i = 0; i <= nroots; i++)
+ rs->genpoly[i] = rs->index_of[rs->genpoly[i]];
+
+ return rs;
+}
diff --git a/lib/int.h b/lib/int.h
new file mode 100644
index 00000000..056241e1
--- /dev/null
+++ b/lib/int.h
@@ -0,0 +1,57 @@
+/* Include file to configure the RS codec for integer symbols
+ *
+ * Copyright 2002, Phil Karn, KA9Q
+ * May be used under the terms of the GNU General Public License (GPL)
+ */
+#define DTYPE int
+
+/* Reed-Solomon codec control block */
+struct rs {
+ int mm; /* Bits per symbol */
+ int nn; /* Symbols per block (= (1<<mm)-1) */
+ DTYPE *alpha_to; /* log lookup table */
+ DTYPE *index_of; /* Antilog lookup table */
+ DTYPE *genpoly; /* Generator polynomial */
+ int nroots; /* Number of generator roots = number of parity symbols */
+ int fcr; /* First consecutive root, index form */
+ int prim; /* Primitive element, index form */
+ int iprim; /* prim-th root of 1, index form */
+ int pad; /* Padding bytes in shortened block */
+};
+
+static int modnn(struct rs *rs,int x){
+ while (x >= rs->nn) {
+ x -= rs->nn;
+ x = (x >> rs->mm) + (x & rs->nn);
+ }
+ return x;
+}
+#define MODNN(x) modnn(rs,x)
+
+#define MM (rs->mm)
+#define NN (rs->nn)
+#define ALPHA_TO (rs->alpha_to)
+#define INDEX_OF (rs->index_of)
+#define GENPOLY (rs->genpoly)
+//#define NROOTS (rs->nroots)
+#define NROOTS (51)
+#define FCR (rs->fcr)
+#define PRIM (rs->prim)
+#define IPRIM (rs->iprim)
+#define PAD (rs->pad)
+#define A0 (NN)
+
+#define ENCODE_RS encode_rs_int
+#define DECODE_RS decode_rs_int
+#define INIT_RS init_rs_int
+#define FREE_RS free_rs_int
+
+void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity);
+int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras);
+void *INIT_RS(int symsize,int gfpoly,int fcr,
+ int prim,int nroots,int pad);
+void FREE_RS(void *p);
+
+
+
+
diff --git a/lib/interleave24.f90 b/lib/interleave24.f90
new file mode 100644
index 00000000..3cdd9c52
--- /dev/null
+++ b/lib/interleave24.f90
@@ -0,0 +1,43 @@
+subroutine interleave24(id,ndir)
+ integer*1 id(0:205),itmp(0:205)
+ integer j0(0:205)
+ logical first
+ data first/.true./
+ save first,j0
+
+ if(first) then
+ k=-1
+ do i=0,255
+ m=i
+ n=iand(m,1)
+ n=2*n + iand(m/2,1)
+ n=2*n + iand(m/4,1)
+ n=2*n + iand(m/8,1)
+ n=2*n + iand(m/16,1)
+ n=2*n + iand(m/32,1)
+ n=2*n + iand(m/64,1)
+ n=2*n + iand(m/128,1)
+ if(n.le.205) then
+ k=k+1
+ j0(k)=n
+ endif
+ enddo
+ first=.false.
+ endif
+
+ if(ndir.eq.1) then
+ do i=0,205
+ itmp(j0(i))=id(i)
+ enddo
+ else
+ do i=0,205
+ itmp(i)=id(j0(i))
+ enddo
+ endif
+
+ do i=0,205
+ id(i)=itmp(i)
+ enddo
+
+ return
+end subroutine interleave24
diff --git a/lib/interleave63.f90 b/lib/interleave63.f90
new file mode 100644
index 00000000..048244e6
--- /dev/null
+++ b/lib/interleave63.f90
@@ -0,0 +1,25 @@
+subroutine interleave63(d1,idir)
+
+! Interleave (idir=1) or de-interleave (idir=-1) the array d1.
+
+ integer d1(0:6,0:8)
+ integer d2(0:8,0:6)
+
+ if(idir.ge.0) then
+ do i=0,6
+ do j=0,8
+ d2(j,i)=d1(i,j)
+ enddo
+ enddo
+ call move(d2,d1,63)
+ else
+ call move(d1,d2,63)
+ do i=0,6
+ do j=0,8
+ d1(i,j)=d2(j,i)
+ enddo
+ enddo
+ endif
+
+ return
+end subroutine interleave63
diff --git a/lib/interleave8.f90 b/lib/interleave8.f90
new file mode 100644
index 00000000..e13346ec
--- /dev/null
+++ b/lib/interleave8.f90
@@ -0,0 +1,17 @@
+subroutine interleave8(idat,jdat)
+
+ integer idat(66),jdat(66)
+ integer ii(66),jj(66)
+ data ii/ &
+ 64,32,16,48, 8,40,24,56, 4,36,20,52,12,44,28,60, 2,66,34,18, &
+ 50,10,42,26,58, 6,38,22,54,14,46,30,62, 1,65,33,17,49, 9,41, &
+ 25,57, 5,37,21,53,13,45,29,61, 3,35,19,51,11,43,27,59, 7,39, &
+ 23,55,15,47,31,63/
+ data jj/ &
+ 34,17,51, 9,43,26,59, 5,39,22,55,13,47,30,63, 3,37,20,53,11, &
+ 45,28,61, 7,41,24,57,15,49,32,65, 2,36,19,52,10,44,27,60, 6, &
+ 40,23,56,14,48,31,64, 4,38,21,54,12,46,29,62, 8,42,25,58,16, &
+ 50,33,66, 1,35,18/
+
+ return
+end subroutine interleave8
diff --git a/lib/interleave9.f90 b/lib/interleave9.f90
new file mode 100644
index 00000000..e3026a9b
--- /dev/null
+++ b/lib/interleave9.f90
@@ -0,0 +1,39 @@
+subroutine interleave9(ia,ndir,ib)
+ integer*1 ia(0:205),ib(0:205)
+ integer j0(0:205)
+ logical first
+ data first/.true./
+ save first,j0 !Save not working, or j0 overwritten ???
+
+ if(first) then
+ k=-1
+ do i=0,255
+ m=i
+ n=iand(m,1)
+ n=2*n + iand(m/2,1)
+ n=2*n + iand(m/4,1)
+ n=2*n + iand(m/8,1)
+ n=2*n + iand(m/16,1)
+ n=2*n + iand(m/32,1)
+ n=2*n + iand(m/64,1)
+ n=2*n + iand(m/128,1)
+ if(n.le.205) then
+ k=k+1
+ j0(k)=n
+ endif
+ enddo
+! first=.false.
+ endif
+
+ if(ndir.gt.0) then
+ do i=0,205
+ ib(j0(i))=ia(i)
+ enddo
+ else
+ do i=0,205
+ ib(i)=ia(j0(i))
+ enddo
+ endif
+
+ return
+end subroutine interleave9
diff --git a/lib/ipcomm.cpp b/lib/ipcomm.cpp
new file mode 100644
index 00000000..d845a604
--- /dev/null
+++ b/lib/ipcomm.cpp
@@ -0,0 +1,50 @@
+#include <QDebug>
+#include <QString>
+#include <QSharedMemory>
+#include <QSystemSemaphore>
+
+// Multiple instances: KK1D, 17 Jul 2013
+QSharedMemory mem_jt9;
+
+// Semaphore not changed, as the acquire/release calls do not
+// appear to be used anywhere.
+QSystemSemaphore sem_jt9("sem_jt9", 1, QSystemSemaphore::Open);
+
+extern "C" {
+ bool attach_jt9_();
+ bool create_jt9_(int nsize);
+ bool detach_jt9_();
+ bool lock_jt9_();
+ bool unlock_jt9_();
+ char* address_jt9_();
+ int size_jt9_();
+// Multiple instances: wrapper for QSharedMemory::setKey()
+ bool setkey_jt9_(char* mykey, int mykey_len);
+
+ bool acquire_jt9_();
+ bool release_jt9_();
+
+ extern struct {
+ char c[10];
+ } jt9com_;
+}
+
+bool attach_jt9_() {return mem_jt9.attach();}
+bool create_jt9_(int nsize) {return mem_jt9.create(nsize);}
+bool detach_jt9_() {return mem_jt9.detach();}
+bool lock_jt9_() {return mem_jt9.lock();}
+bool unlock_jt9_() {return mem_jt9.unlock();}
+char* address_jt9_() {return (char*)mem_jt9.constData();}
+int size_jt9_() {return (int)mem_jt9.size();}
+
+// Multiple instances:
+bool setkey_jt9_(char* mykey, int mykey_len) {
+ char *tempstr = (char *)calloc(mykey_len+1,1);
+ memset(tempstr, 0, mykey_len+1);
+ strncpy(tempstr, mykey, mykey_len);
+ QString s1 = QString(QLatin1String(tempstr));
+ mem_jt9.setKey(s1);
+ return true;}
+
+bool acquire_jt9_() {return sem_jt9.acquire();}
+bool release_jt9_() {return sem_jt9.release();}
diff --git a/lib/jt65.f90 b/lib/jt65.f90
new file mode 100644
index 00000000..10f7525a
--- /dev/null
+++ b/lib/jt65.f90
@@ -0,0 +1,68 @@
+program jt65
+
+! Test the JT65 decoder for WSJT-X
+
+ parameter (NZMAX=60*12000)
+ integer*4 ihdr(11)
+ integer*2 id2(NZMAX)
+ real*4 dd(NZMAX)
+ character*80 infile
+ integer*2 nfmt2,nchan2,nbitsam2,nbytesam2
+ character*4 ariff,awave,afmt,adata
+ common/hdr/ariff,lenfile,awave,afmt,lenfmt,nfmt2,nchan2, &
+ nsamrate,nbytesec,nbytesam2,nbitsam2,adata,ndata
+ common/tracer/limtrace,lu
+ equivalence (lenfile,ihdr(2))
+
+ nargs=iargc()
+ if(nargs.lt.1) then
+ print*,'Usage: jt65 file1 [file2 ...]'
+ go to 999
+ endif
+ limtrace=0
+ lu=12
+
+ newdat=1
+ ntol=50
+ nfa=2700
+! nfb=4000
+ nfqso=933
+ nagain=0
+
+ open(12,file='timer.out',status='unknown')
+ open(22,file='kvasd.dat',access='direct',recl=1024,status='unknown')
+
+ call timer('jt65 ',0)
+
+ do ifile=1,nargs
+ call getarg(ifile,infile)
+ open(10,file=infile,access='stream',status='old',err=998)
+
+ call timer('read ',0)
+ read(10) ihdr
+ nutc=ihdr(1) !Silence compiler warning
+ i1=index(infile,'.wav')
+ read(infile(i1-4:i1-1),*,err=10) nutc
+ go to 20
+10 nutc=0
+20 npts=52*12000
+ read(10) id2(1:npts)
+ call timer('read ',1)
+ dd(1:npts)=id2(1:npts)
+ dd(npts+1:)=0.
+
+ call timer('jt65a ',0)
+ call jt65a(dd,npts,newdat,nutc,ntol,nfa,nfqso,nagain,ndecoded)
+ call timer('jt65a ',1)
+ enddo
+
+ call timer('jt65 ',1)
+ call timer('jt65 ',101)
+ call four2a(a,-1,1,1,1) !Free the memory used for plans
+ call filbig(a,-1,1,0.0,0,0,0,0,0) ! (ditto)
+ go to 999
+
+998 print*,'Cannot open file:'
+ print*,infile
+
+999 end program jt65
diff --git a/lib/jt65a.f90 b/lib/jt65a.f90
new file mode 100644
index 00000000..0c061eda
--- /dev/null
+++ b/lib/jt65a.f90
@@ -0,0 +1,85 @@
+subroutine jt65a(dd,npts,newdat,nutc,nfa,nfqso,ntol,nagain,ndecoded)
+
+! Process dd() data to find and decode JT65 signals.
+
+ parameter (NSZ=3413)
+ parameter (NZMAX=60*12000)
+ parameter (NFFT=8192)
+ real dd(NZMAX)
+ real*4 ss(322,NSZ)
+ real*4 savg(NSZ)
+ logical done(NSZ)
+ real a(5)
+ character decoded*22
+ save
+
+ if(newdat.ne.0) then
+ call timer('symsp65 ',0)
+ call symspec65(dd,npts,ss,nhsym,savg) !Get normalized symbol spectra
+ call timer('symsp65 ',1)
+ endif
+
+ df=12000.0/NFFT !df = 12000.0/16384 = 0.732 Hz
+ ftol=16.0 !Frequency tolerance (Hz)
+ mode65=1 !Decoding JT65A only, for now.
+ done=.false.
+ freq0=-999.
+
+ do nqd=1,0,-1
+ if(nqd.eq.1) then !Quick decode, at fQSO
+ fa=nfqso - ntol
+ fb=nfqso + ntol
+ else !Wideband decode at all freqs
+ fa=200
+ fb=nfa
+ endif
+ ia=max(51,nint(fa/df))
+ ib=min(NSZ-51,nint(fb/df))
+
+ thresh0=1.5
+
+ do i=ia,ib !Search over freq range
+ freq=i*df
+ if(savg(i).lt.thresh0 .or. done(i)) cycle
+
+ call timer('ccf65 ',0)
+ call ccf65(ss(1,i),nhsym,savg(i),sync1,dt,flipk,syncshort,snr2,dt2)
+ call timer('ccf65 ',1)
+
+ ftest=abs(freq-freq0)
+ thresh1=1.0
+ if(nqd.eq.1 .and. ntol.le.100) thresh1=0.
+ if(sync1.lt.thresh1 .or. ftest.lt.ftol) cycle
+
+ nflip=nint(flipk)
+ call timer('decod65a',0)
+ call decode65a(dd,npts,newdat,freq,nflip,mode65,sync2,a,dt, &
+ nbmkv,nhist,decoded)
+ call timer('decod65a',1)
+
+ ftest=abs(freq+a(1)-freq0)
+ if(ftest.lt.ftol) cycle
+
+ if(decoded.ne.' ') then
+ ndecoded=1
+ nfreq=nint(freq+a(1))
+ ndrift=nint(2.0*a(2))
+ s2db=10.0*log10(sync2) - 32 !### empirical (was 40) ###
+ nsnr=nint(s2db)
+ if(nsnr.lt.-30) nsnr=-30
+ if(nsnr.gt.-1) nsnr=-1
+ write(*,1010) nutc,nsnr,dt,nfreq,decoded
+1010 format(i4.4,i4,f5.1,i5,1x,'#',1x,a22)
+ write(13,1012) nutc,nint(sync1),nsnr,dt,float(nfreq),ndrift, &
+ decoded,nbmkv
+1012 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a22,' JT65',i4)
+ freq0=freq+a(1)
+ i2=min(NSZ,i+15) !### ??? ###
+ done(i:i2)=.true.
+ endif
+ enddo
+ if(nagain.eq.1) exit
+ enddo
+
+ return
+end subroutine jt65a
diff --git a/lib/jt9.f90 b/lib/jt9.f90
new file mode 100644
index 00000000..1f0a619d
--- /dev/null
+++ b/lib/jt9.f90
@@ -0,0 +1,111 @@
+program jt9
+
+! Decoder for JT9. Can run stand-alone, reading data from *.wav files;
+! or as the back end of wsjt-x, with data placed in a shared memory region.
+
+ include 'constants.f90'
+ integer*4 ihdr(11)
+ real*4 s(NSMAX)
+ integer*2 id2
+ character*80 arg,infile
+ common/jt9com/ss(184,NSMAX),savg(NSMAX),id2(NMAX),nutc,ndiskdat, &
+ ntr,mousefqso,newdat,nfa,nfb,ntol,kin,nzhsym,nsynced,ndecoded
+ common/tracer/limtrace,lu
+
+ nargs=iargc()
+ if(nargs.lt.1) then
+ print*,'Usage: jt9 TRperiod ndepth rxfreq file1 [file2 ...]'
+ print*,' Reads data from *.wav files.'
+ print*,''
+ print*,' jt9 -s <key>'
+ print*,' Gets data from shared memory region with key==<key>'
+ go to 999
+ endif
+ call getarg(1,arg)
+ if(arg(1:2).eq.'-s') then
+! Multiple instances:
+ call getarg(2,arg)
+ i0=len(trim(arg))
+ call jt9a(trim(arg))
+ go to 999
+ endif
+ read(arg,*) ntrperiod
+ call getarg(2,arg)
+ read(arg,*) ndepth
+ call getarg(3,arg)
+ read(arg,*) nrxfreq
+ ifile1=4
+
+ limtrace=0
+ lu=12
+
+ do ifile=ifile1,nargs
+ call getarg(ifile,infile)
+ open(10,file=infile,access='stream',status='old',err=998)
+ read(10) ihdr
+ nutc0=ihdr(1) !Silence compiler warning
+ i1=index(infile,'.wav')
+ read(infile(i1-4:i1-1),*,err=1) nutc0
+ go to 2
+1 nutc0=0
+2 nsps=0
+ if(ntrperiod.eq.1) then
+ nsps=6912
+ nzhsym=173
+ else if(ntrperiod.eq.2) then
+ nsps=15360
+ nzhsym=178
+ else if(ntrperiod.eq.5) then
+ nsps=40960
+ nzhsym=172
+ else if(ntrperiod.eq.10) then
+ nsps=82944
+ nzhsym=171
+ else if(ntrperiod.eq.30) then
+ nsps=252000
+ nzhsym=167
+ endif
+ if(nsps.eq.0) stop 'Error: bad TRperiod'
+
+ kstep=nsps/2
+ k=0
+ nhsym0=-999
+ npts=(60*ntrperiod-6)*12000
+ if(ifile.eq.ifile1) then
+ open(12,file='timer.out',status='unknown')
+ call timer('jt9 ',0)
+ endif
+
+ id2=0 !??? Why is this necessary ???
+
+ do iblk=1,npts/kstep
+ k=iblk*kstep
+ call timer('read_wav',0)
+ read(10,end=10) id2(k-kstep+1:k)
+ call timer('read_wav',1)
+
+ nhsym=(k-2048)/kstep
+ if(nhsym.ge.1 .and. nhsym.ne.nhsym0) then
+! Emit signal readyForFFT
+ ingain=0
+ call timer('symspec ',0)
+ call symspec(k,ntrperiod,nsps,ingain,slope,pxdb,s,df3,ihsym,npts8)
+ call timer('symspec ',1)
+ nhsym0=nhsym
+ if(ihsym.ge.173) go to 10
+ endif
+ enddo
+
+10 close(10)
+ call fillcom(nutc0,ndepth,nrxfreq)
+ call decoder(ss,id2)
+ enddo
+
+ call timer('jt9 ',1)
+ call timer('jt9 ',101)
+ go to 999
+
+998 print*,'Cannot open file:'
+ print*,infile
+
+999 end program jt9
diff --git a/lib/jt9a.f90 b/lib/jt9a.f90
new file mode 100644
index 00000000..113533c7
--- /dev/null
+++ b/lib/jt9a.f90
@@ -0,0 +1,72 @@
+subroutine jt9a(thekey)
+
+ character(len=*), intent(in):: thekey
+
+! These routines connect the shared memory region to the decoder.
+ interface
+ function address_jt9()
+ integer*1, pointer :: address_jt9
+ end function address_jt9
+ end interface
+
+ integer*1 attach_jt9
+! integer*1 lock_jt9,unlock_jt9
+ integer size_jt9
+ integer*1, pointer :: p_jt9
+ character*80 cwd
+! Multiple instances:
+ character*80 mykey
+ logical fileExists
+ common/tracer/limtrace,lu
+
+! Multiple instances:
+ i0 = len(trim(thekey))
+
+ call getcwd(cwd)
+ open(12,file='timer.out',status='unknown')
+
+ limtrace=0
+! limtrace=-1 !Disable all calls to timer()
+ lu=12
+
+! Multiple instances: set the shared memory key before attaching
+ mykey=trim(repeat(thekey,1))
+ i0 = len(mykey)
+ i0=setkey_jt9(trim(mykey))
+
+ i1=attach_jt9()
+
+10 inquire(file=trim(cwd)//'/.lock',exist=fileExists)
+ if(fileExists) then
+ call sleep_msec(100)
+ go to 10
+ endif
+
+ inquire(file=trim(cwd)//'/.quit',exist=fileExists)
+ if(fileExists) then
+! call ftnquit
+ i1=detach_jt9()
+ go to 999
+ endif
+ if(i1.eq.999999) stop !Silence compiler warning
+
+ nbytes=size_jt9()
+ if(nbytes.le.0) then
+ print*,'jt9a: Shared memory mem_jt9 does not exist.'
+ print*,"Must start 'jt9 -s <thekey>' from within WSJT-X."
+ go to 999
+ endif
+ p_jt9=>address_jt9()
+ call timer('jt9b ',0)
+ call jt9b(p_jt9,nbytes)
+ call timer('jt9b ',1)
+
+100 inquire(file=trim(cwd)//'/.lock',exist=fileExists)
+ if(fileExists) go to 10
+ call sleep_msec(100)
+ go to 100
+
+999 call timer('jt9b ',101)
+
+ return
+end subroutine jt9a
diff --git a/lib/jt9b.f90 b/lib/jt9b.f90
new file mode 100644
index 00000000..63de536b
--- /dev/null
+++ b/lib/jt9b.f90
@@ -0,0 +1,12 @@
+subroutine jt9b(jt9com,nbytes)
+
+ include 'constants.f90'
+ integer*1 jt9com(0:nbytes-1)
+ kss=0
+ ksavg=kss + 4*184*NSMAX
+ kid2=ksavg + 4*NSMAX
+ knutc=kid2 + 2*NTMAX*12000
+ call jt9c(jt9com(kss),jt9com(ksavg),jt9com(kid2),jt9com(knutc))
+
+ return
+end subroutine jt9b
diff --git a/lib/jt9c.f90 b/lib/jt9c.f90
new file mode 100644
index 00000000..57b3cb25
--- /dev/null
+++ b/lib/jt9c.f90
@@ -0,0 +1,21 @@
+subroutine jt9c(ss,savg,id2,nparams0)
+
+ include 'constants.f90'
+ real*4 ss(184*NSMAX),savg(NSMAX)
+ integer*2 id2(NTMAX*12000)
+
+ integer nparams0(21),nparams(21)
+ character*20 datetime
+ common/npar/nutc,ndiskdat,ntrperiod,nfqso,newdat,npts8,nfa,nfb,ntol, &
+ kin,nzhsym,nsave,nagain,ndepth,ntxmode,nmode,datetime
+ equivalence (nparams,nutc)
+
+ nutc=id2(1)+int(savg(1)) !Silence compiler warning
+ nparams=nparams0 !Copy parameters into common/npar/
+
+ call flush(6)
+! if(sum(nparams).ne.0) call decoder(ss,id2)
+ call decoder(ss,id2)
+
+ return
+end subroutine jt9c
diff --git a/lib/jt9code.f90 b/lib/jt9code.f90
new file mode 100644
index 00000000..a4f0d3e7
--- /dev/null
+++ b/lib/jt9code.f90
@@ -0,0 +1,29 @@
+program jt9code
+
+! Generate simulated data for testing of WSJT-X
+
+ character msg*22,msg0*22,decoded*22
+ integer*4 i4tone(85) !Channel symbols (values 0-8)
+ include 'jt9sync.f90'
+
+ nargs=iargc()
+ if(nargs.ne.1) then
+ print*,'Usage: jt9code "message"'
+ go to 999
+ endif
+
+ call getarg(1,msg0)
+ write(*,1000) msg0
+1000 format('Message:',3x,a22)
+ msg=msg0
+ ichk=0
+ itext=0
+ call genjt9(msg,ichk,decoded,i4tone,itext) !Encode message into tone #s
+ write(*,1002) i4tone
+1002 format('Channel symbols:'/(30i2))
+ if(itext.eq.0) write(*,1004) decoded
+1004 format('Decoded message:',1x,a22)
+ if(itext.ne.0) write(*,1005) decoded
+1005 format('Decoded message:',1x,a22,3x,'(free text)')
+
+999 end program jt9code
diff --git a/lib/jt9sim.f90 b/lib/jt9sim.f90
new file mode 100644
index 00000000..f4f0cf62
--- /dev/null
+++ b/lib/jt9sim.f90
@@ -0,0 +1,166 @@
+program jt9sim
+
+! Generate simulated data for testing of WSJT-X
+
+ parameter (NTMAX=120)
+ parameter (NMAX=NTMAX*12000)
+ integer ihdr(11)
+ integer*2 iwave !Generated waveform (no noise)
+ real*8 f0,f,dt,twopi,phi,dphi,baud,fspan,fsample,freq
+ character msg*22,msg0*22,message*22,msgsent*22,arg*8,fname*11
+
+ integer*4 i4tone(85) !Channel symbols (values 0-8)
+ integer*4 i4DataSymNoGray(69) !Data Symbols, values 0-7
+ integer*1 i1ScrambledBits(207) !Unpacked bits, scrambled order
+ integer*1 i1Bits(207) !Encoded information-carrying bits
+ integer*1 i1SoftSymbols(207)
+ include 'jt9sync.f90'
+ common/acom/dat(NMAX),iwave(NMAX)
+
+ nargs=iargc()
+ if(nargs.ne.6) then
+ print*,'Usage: jt9sim "message" fspan nsigs minutes SNR nfiles'
+ print*,'Example: "CQ K1ABC FN42" 200 20 2 -28 1'
+ print*,' '
+ print*,'Enter message = "" to use entries in msgs.txt.'
+ print*,'Enter SNR = 0 to generate a range of SNRs.'
+ go to 999
+ endif
+
+ call getarg(1,msg0)
+ message=msg0 !Transmitted message
+ call getarg(2,arg)
+ read(arg,*) fspan !Total freq range (Hz)
+ call getarg(3,arg)
+ read(arg,*) nsigs !Number of signals in each file
+ call getarg(4,arg)
+ read(arg,*) minutes !Length of file (1 2 5 10 30 minutes)
+ call getarg(5,arg)
+ read(arg,*) snrdb !S/N in dB (2500 hz reference BW)
+ call getarg(6,arg)
+ read(arg,*) nfiles !Number of files
+
+ rmsdb=25.
+ rms=10.0**(0.05*rmsdb)
+ fsample=12000.d0 !Sample rate (Hz)
+ dt=1.d0/fsample !Sample interval (s)
+ twopi=8.d0*atan(1.d0)
+ npts=12000*(60*minutes-6)
+ nsps=0
+ if(minutes.eq.1) nsps=6912
+ if(minutes.eq.2) nsps=15360
+ if(minutes.eq.5) nsps=40960
+ if(minutes.eq.10) nsps=82944
+ if(minutes.eq.30) nsps=252000
+ if(nsps.eq.0) stop 'Bad value for minutes.'
+
+ f0=1400.d0 !Center frequency (Hz)
+! f0=1500.0
+! if(minutes.eq.5) f0=1100.
+! if(minutes.eq.10) f0=1050.
+! if(minutes.eq.30) f0=1025.
+
+ ihdr=0 !Temporary ###
+ k=0 !Silence compiler warning
+
+ if(msg0(1:3).eq.'sin') read(msg0(4:),*) sinfreq
+
+ open(12,file='msgs.txt',status='old')
+
+ write(*,1000)
+1000 format('File N freq S/N Message'/ &
+ '---------------------------------------------------')
+
+ do ifile=1,nfiles !Loop over all files
+ nmin=(ifile-1)*minutes
+ ihr=nmin/60
+ imin=mod(nmin,60)
+ write(fname,1002) ihr,imin !Create output filename
+1002 format('000000_',2i2.2)
+ open(10,file=fname//'.wav',access='stream',status='unknown')
+
+ if(snrdb.lt.90) then
+ do i=1,npts
+ dat(i)=gran()
+ enddo
+ else
+ dat(1:npts)=0.
+ endif
+
+ if(msg0.ne.' ') then
+ call genjt9(message,msgsent,i4tone) !Encode message into tone #s
+ endif
+
+ rewind 12
+ do isig=1,nsigs !Loop over multiple signals
+
+ if(msg0.eq.' ') then
+ read(12,1004) message !Use pre-generated message texts
+1004 format(a22)
+ call genjt9(message,msgsent,i4tone)
+ endif
+
+ f=f0
+ if(nsigs.gt.1) f=f0 - 0.5d0*fspan + fspan*(isig-1.d0)/(nsigs-1.d0)
+ snrdbx=snrdb
+! snrdbx=snrdb + (ifile-1)*4.0
+ sig=10.0**(0.05*snrdbx)
+ write(*,1020) ifile,isig,f,snrdbx,msgsent
+1020 format(i3,i4,f10.3,f7.1,2x,a22)
+
+ phi=0.
+ baud=12000.d0/nsps
+ k=12000 !Start audio at t = 1.0 s
+! f1=0.0001 * (ifile-1)
+ f1=0.
+! print*,ifile-1,f1
+ dphi2=0.
+ ddphi2=twopi*f1*dt/60.0
+ do isym=1,85
+ freq=f + i4tone(isym)*baud
+ if(msg0(1:3).eq.'sin') freq=sinfreq
+ dphi=twopi*freq*dt + dphi2
+ do i=1,nsps
+ phi=phi + dphi
+ dphi2=dphi2 + ddphi2
+ if(phi.lt.-twopi) phi=phi+twopi
+ if(phi.gt.twopi) phi=phi-twopi
+ xphi=phi
+ k=k+1
+ dat(k)=dat(k) + sig*sin(xphi) !Use lookup table for i*2 sin(x) ?
+ enddo
+ enddo
+ enddo
+
+ do i=1,npts
+ iwave(i)=nint(rms*dat(i))
+ enddo
+
+ write(10) ihdr,iwave(1:npts)
+ close(10)
+
+! We're done! Now decode the data symbols from i4tone, as a test.
+ if(msg0.ne.' ') then
+ j=0
+ do i=1,85
+ if(isync(i).eq.1) cycle
+ j=j+1
+ i4DataSymNoGray(j)=igray(i4tone(i)-1,-1)
+ enddo
+ call unpackbits(i4DataSymNoGray,69,3,i1ScrambledBits)
+ call interleave9(i1ScrambledBits,-1,i1Bits)
+
+ do i=1,206
+ i4=-10
+ if(i1Bits(i).eq.1) i4=10
+ i4=i4+128
+ if(i4.le.127) i1SoftSymbols(k)=i4
+ if(i4.ge.128) i1SoftSymbols(k)=i4-256
+ enddo
+ limit=1000
+ call decode9(i1SoftSymbols,limit,nlim,msg)
+ if(msg.ne.msg0) print*,'Decode error: ',msg0,' ',msg
+ endif
+ enddo
+
+999 end program jt9sim
diff --git a/lib/jt9sync.f90 b/lib/jt9sync.f90
new file mode 100644
index 00000000..a8e33685
--- /dev/null
+++ b/lib/jt9sync.f90
@@ -0,0 +1,18 @@
+ integer ii(16) !Locations of sync symbols
+ data ii/ 1,2,5,10,16,23,33,35,51,52,55,60,66,73,83,85/
+
+ integer ii2(16) !Locations of sync half-symbols
+ data ii2/1,3,9,19,31,45,65,69,101,103,109,119,131,145,165,169/
+
+ integer ka(16),kb(16) !Reference symbols for sync
+ data ka/5,5,11,21,33,47,63,71,97,105,111,121,133,147,159,163/
+ data kb/7,7,13,23,35,49,67,73,99,107,113,123,135,149,161,167/
+
+
+ integer isync(85) !Sync vector
+ data isync/ &
+ 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0, &
+ 0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, &
+ 0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,1, &
+ 0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0, &
+ 0,0,1,0,1/
diff --git a/lib/k2grid.f90 b/lib/k2grid.f90
new file mode 100644
index 00000000..aa763157
--- /dev/null
+++ b/lib/k2grid.f90
@@ -0,0 +1,12 @@
+subroutine k2grid(k,grid)
+ character grid*6
+
+ nlong=2*mod((k-1)/5,90)-179
+ if(k.gt.450) nlong=nlong+180
+ nlat=mod(k-1,5)+ 85
+ dlat=nlat
+ dlong=nlong
+ call deg2grid(dlong,dlat,grid)
+
+ return
+end subroutine k2grid
diff --git a/lib/libhamlib.dll.a b/lib/libhamlib.dll.a
new file mode 100644
index 00000000..7bb6d1bd
--- /dev/null
+++ b/lib/libhamlib.dll.a
Binary files differ
diff --git a/lib/met8.21 b/lib/met8.21
new file mode 100644
index 00000000..a5d3006e
--- /dev/null
+++ b/lib/met8.21
@@ -0,0 +1,256 @@
+ -25.6 1.000 -9.966 1.000000 0.000000
+ -25.4 1.000 -9.966 1.000000 0.000000
+ -25.2 1.000 -9.966 1.000000 0.000000
+ -25.0 1.000 -9.966 1.000000 0.000000
+ -24.8 1.000 -9.966 1.000000 0.000000
+ -24.6 1.000 -9.966 1.000000 0.000000
+ -24.4 1.000 -9.966 1.000000 0.000000
+ -24.2 1.000 -9.966 1.000000 0.000000
+ -24.0 1.000 -9.966 1.000000 0.000000
+ -23.8 1.000 -9.966 1.000000 0.000000
+ -23.6 1.000 -9.966 1.000000 0.000000
+ -23.4 1.000 -9.966 1.000000 0.000000
+ -23.2 1.000 -9.966 1.000000 0.000000
+ -23.0 1.000 -9.966 1.000000 0.000000
+ -22.8 1.000 -9.966 1.000000 0.000000
+ -22.6 1.000 -9.966 1.000000 0.000000
+ -22.4 1.000 -9.966 1.000000 0.000000
+ -22.2 1.000 -9.966 1.000000 0.000000
+ -22.0 1.000 -9.966 1.000000 0.000000
+ -21.8 1.000 -9.966 1.000000 0.000000
+ -21.6 1.000 -9.966 1.000000 0.000000
+ -21.4 1.000 -9.966 1.000000 0.000000
+ -21.2 1.000 -9.966 1.000000 0.000000
+ -21.0 1.000 -9.966 1.000000 0.000000
+ -20.8 1.000 -9.966 1.000000 0.000000
+ -20.6 1.000 -9.966 1.000000 0.000000
+ -20.4 1.000 -9.966 1.000000 0.000000
+ -20.2 1.000 -9.966 1.000000 0.000000
+ -20.0 1.000 -9.966 1.000000 0.000000
+ -19.8 1.000 -9.966 1.000000 0.000000
+ -19.6 1.000 -9.966 1.000000 0.000000
+ -19.4 1.000 -9.966 1.000000 0.000000
+ -19.2 1.000 -9.966 1.000000 0.000000
+ -19.0 1.000 -9.966 1.000000 0.000000
+ -18.8 1.000 -9.966 1.000000 0.000000
+ -18.6 1.000 -9.966 1.000000 0.000000
+ -18.4 1.000 -9.966 1.000000 0.000000
+ -18.2 1.000 -9.966 1.000000 0.000000
+ -18.0 1.000 -9.966 1.000000 0.000000
+ -17.8 1.000 -9.966 1.000000 0.000000
+ -17.6 1.000 -9.966 1.000000 0.000000
+ -17.4 1.000 -9.966 1.000000 0.000000
+ -17.2 1.000 -9.966 1.000000 0.000000
+ -17.0 1.000 -9.966 1.000000 0.000000
+ -16.8 1.000 -9.966 1.000000 0.000000
+ -16.6 1.000 -9.966 1.000000 0.000000
+ -16.4 1.000 -9.966 1.000000 0.000000
+ -16.2 1.000 -9.966 1.000000 0.000000
+ -16.0 0.988 -5.858 0.991379 0.008621
+ -15.8 1.000 -9.966 1.000000 0.000000
+ -15.6 0.991 -6.313 0.993711 0.006289
+ -15.4 0.993 -6.629 0.994950 0.005051
+ -15.2 1.000 -9.966 1.000000 0.000000
+ -15.0 0.995 -7.055 0.996241 0.003759
+ -14.8 1.000 -9.966 1.000000 0.000000
+ -14.6 0.991 -6.371 0.993958 0.006042
+ -14.4 1.000 -9.966 1.000000 0.000000
+ -14.2 0.991 -6.313 0.993711 0.006289
+ -14.0 0.992 -6.426 0.994186 0.005814
+ -13.8 0.991 -6.288 0.993600 0.006400
+ -13.6 0.990 -6.113 0.992775 0.007225
+ -13.4 0.990 -6.152 0.992968 0.007032
+ -13.2 0.992 -6.534 0.994606 0.005394
+ -13.0 0.996 -7.332 0.996898 0.003102
+ -12.8 0.990 -6.184 0.993121 0.006879
+ -12.6 0.994 -7.016 0.996136 0.003864
+ -12.4 0.993 -6.658 0.995049 0.004950
+ -12.2 0.991 -6.369 0.993953 0.006047
+ -12.0 0.992 -6.559 0.994699 0.005301
+ -11.8 0.989 -6.002 0.992197 0.007803
+ -11.6 0.991 -6.304 0.993671 0.006329
+ -11.4 0.987 -5.826 0.991188 0.008812
+ -11.2 0.985 -5.632 0.989919 0.010081
+ -11.0 0.989 -5.995 0.992162 0.007838
+ -10.8 0.984 -5.544 0.989284 0.010717
+ -10.6 0.983 -5.377 0.987966 0.012034
+ -10.4 0.979 -5.108 0.985502 0.014498
+ -10.2 0.977 -4.954 0.983869 0.016131
+ -10.0 0.971 -4.652 0.980118 0.019882
+ -9.8 0.975 -4.870 0.982896 0.017104
+ -9.6 0.974 -4.822 0.982324 0.017676
+ -9.4 0.970 -4.608 0.979490 0.020510
+ -9.2 0.970 -4.623 0.979702 0.020298
+ -9.0 0.970 -4.621 0.979679 0.020321
+ -8.8 0.967 -4.472 0.977465 0.022535
+ -8.6 0.962 -4.261 0.973915 0.026085
+ -8.4 0.960 -4.186 0.972538 0.027462
+ -8.2 0.957 -4.098 0.970806 0.029194
+ -8.0 0.956 -4.062 0.970061 0.029939
+ -7.8 0.953 -3.975 0.968209 0.031791
+ -7.6 0.942 -3.677 0.960918 0.039082
+ -7.4 0.946 -3.768 0.963301 0.036699
+ -7.2 0.937 -3.550 0.957308 0.042692
+ -7.0 0.933 -3.463 0.954652 0.045348
+ -6.8 0.929 -3.377 0.951866 0.048134
+ -6.6 0.920 -3.212 0.946042 0.053958
+ -6.4 0.917 -3.164 0.944202 0.055798
+ -6.2 0.911 -3.058 0.939981 0.060019
+ -6.0 0.903 -2.939 0.934818 0.065182
+ -5.8 0.895 -2.829 0.929642 0.070358
+ -5.6 0.884 -2.690 0.922540 0.077459
+ -5.4 0.877 -2.608 0.917972 0.082028
+ -5.2 0.869 -2.531 0.913509 0.086491
+ -5.0 0.858 -2.411 0.905967 0.094033
+ -4.8 0.846 -2.301 0.898525 0.101475
+ -4.6 0.834 -2.201 0.891269 0.108731
+ -4.4 0.821 -2.096 0.883085 0.116915
+ -4.2 0.806 -1.992 0.874340 0.125660
+ -4.0 0.790 -1.882 0.864307 0.135693
+ -3.8 0.775 -1.790 0.855445 0.144555
+ -3.6 0.755 -1.678 0.843726 0.156274
+ -3.4 0.737 -1.587 0.833538 0.166462
+ -3.2 0.713 -1.473 0.819841 0.180159
+ -3.0 0.691 -1.376 0.807345 0.192655
+ -2.8 0.667 -1.280 0.794093 0.205907
+ -2.6 0.640 -1.181 0.779404 0.220596
+ -2.4 0.612 -1.084 0.764178 0.235822
+ -2.2 0.581 -0.987 0.747708 0.252292
+ -2.0 0.548 -0.895 0.731037 0.268963
+ -1.8 0.510 -0.796 0.712035 0.287965
+ -1.6 0.472 -0.706 0.693474 0.306526
+ -1.4 0.425 -0.606 0.671514 0.328486
+ -1.2 0.378 -0.514 0.649948 0.350053
+ -1.0 0.328 -0.425 0.627452 0.372548
+ -0.8 0.274 -0.338 0.604549 0.395451
+ -0.6 0.212 -0.249 0.579151 0.420849
+ -0.4 0.146 -0.163 0.553389 0.446611
+ -0.2 0.075 -0.079 0.526648 0.473352
+ 0.0 0.000 0.000 0.500000 0.500000
+ 0.2 -0.079 0.075 0.473352 0.526648
+ 0.4 -0.163 0.146 0.446611 0.553389
+ 0.6 -0.249 0.212 0.420849 0.579151
+ 0.8 -0.338 0.274 0.395451 0.604549
+ 1.0 -0.425 0.328 0.372548 0.627452
+ 1.2 -0.514 0.378 0.350053 0.649948
+ 1.4 -0.606 0.425 0.328486 0.671514
+ 1.6 -0.706 0.472 0.306526 0.693474
+ 1.8 -0.796 0.510 0.287965 0.712035
+ 2.0 -0.895 0.548 0.268963 0.731037
+ 2.2 -0.987 0.581 0.252292 0.747708
+ 2.4 -1.084 0.612 0.235822 0.764178
+ 2.6 -1.181 0.640 0.220596 0.779404
+ 2.8 -1.280 0.667 0.205907 0.794093
+ 3.0 -1.376 0.691 0.192655 0.807345
+ 3.2 -1.473 0.713 0.180159 0.819841
+ 3.4 -1.587 0.737 0.166462 0.833538
+ 3.6 -1.678 0.755 0.156274 0.843726
+ 3.8 -1.790 0.775 0.144555 0.855445
+ 4.0 -1.882 0.790 0.135693 0.864307
+ 4.2 -1.992 0.806 0.125660 0.874340
+ 4.4 -2.096 0.821 0.116915 0.883085
+ 4.6 -2.201 0.834 0.108731 0.891269
+ 4.8 -2.301 0.846 0.101475 0.898525
+ 5.0 -2.411 0.858 0.094033 0.905967
+ 5.2 -2.531 0.869 0.086491 0.913509
+ 5.4 -2.608 0.877 0.082028 0.917972
+ 5.6 -2.690 0.884 0.077459 0.922540
+ 5.8 -2.829 0.895 0.070358 0.929642
+ 6.0 -2.939 0.903 0.065182 0.934818
+ 6.2 -3.058 0.911 0.060019 0.939981
+ 6.4 -3.164 0.917 0.055798 0.944202
+ 6.6 -3.212 0.920 0.053958 0.946042
+ 6.8 -3.377 0.929 0.048134 0.951866
+ 7.0 -3.463 0.933 0.045348 0.954652
+ 7.2 -3.550 0.937 0.042692 0.957308
+ 7.4 -3.768 0.946 0.036699 0.963301
+ 7.6 -3.677 0.942 0.039082 0.960918
+ 7.8 -3.975 0.953 0.031791 0.968210
+ 8.0 -4.062 0.956 0.029939 0.970061
+ 8.2 -4.098 0.957 0.029194 0.970806
+ 8.4 -4.186 0.960 0.027462 0.972538
+ 8.6 -4.261 0.962 0.026085 0.973915
+ 8.8 -4.472 0.967 0.022535 0.977465
+ 9.0 -4.621 0.970 0.020321 0.979679
+ 9.2 -4.623 0.970 0.020298 0.979702
+ 9.4 -4.608 0.970 0.020510 0.979490
+ 9.6 -4.822 0.974 0.017676 0.982324
+ 9.8 -4.870 0.975 0.017104 0.982896
+ 10.0 -4.652 0.971 0.019882 0.980118
+ 10.2 -4.954 0.977 0.016131 0.983869
+ 10.4 -5.108 0.979 0.014498 0.985502
+ 10.6 -5.377 0.983 0.012034 0.987966
+ 10.8 -5.544 0.984 0.010717 0.989284
+ 11.0 -5.995 0.989 0.007838 0.992162
+ 11.2 -5.632 0.985 0.010081 0.989919
+ 11.4 -5.826 0.987 0.008812 0.991188
+ 11.6 -6.304 0.991 0.006329 0.993671
+ 11.8 -6.002 0.989 0.007803 0.992197
+ 12.0 -6.559 0.992 0.005301 0.994699
+ 12.2 -6.369 0.991 0.006047 0.993953
+ 12.4 -6.658 0.993 0.004950 0.995049
+ 12.6 -7.016 0.994 0.003864 0.996136
+ 12.8 -6.184 0.990 0.006879 0.993121
+ 13.0 -7.332 0.996 0.003102 0.996898
+ 13.2 -6.534 0.992 0.005394 0.994606
+ 13.4 -6.152 0.990 0.007032 0.992968
+ 13.6 -6.113 0.990 0.007225 0.992775
+ 13.8 -6.288 0.991 0.006400 0.993600
+ 14.0 -6.426 0.992 0.005814 0.994186
+ 14.2 -6.313 0.991 0.006289 0.993711
+ 14.4 -9.966 1.000 0.000000 1.000000
+ 14.6 -6.371 0.991 0.006042 0.993958
+ 14.8 -9.966 1.000 0.000000 1.000000
+ 15.0 -7.055 0.995 0.003759 0.996241
+ 15.2 -9.966 1.000 0.000000 1.000000
+ 15.4 -6.629 0.993 0.005051 0.994949
+ 15.6 -6.313 0.991 0.006289 0.993711
+ 15.8 -9.966 1.000 0.000000 1.000000
+ 16.0 -5.858 0.988 0.008621 0.991379
+ 16.2 -9.966 1.000 0.000000 1.000000
+ 16.4 -9.966 1.000 0.000000 1.000000
+ 16.6 -9.966 1.000 0.000000 1.000000
+ 16.8 -9.966 1.000 0.000000 1.000000
+ 17.0 -9.966 1.000 0.000000 1.000000
+ 17.2 -9.966 1.000 0.000000 1.000000
+ 17.4 -9.966 1.000 0.000000 1.000000
+ 17.6 -9.966 1.000 0.000000 1.000000
+ 17.8 -9.966 1.000 0.000000 1.000000
+ 18.0 -9.966 1.000 0.000000 1.000000
+ 18.2 -9.966 1.000 0.000000 1.000000
+ 18.4 -9.966 1.000 0.000000 1.000000
+ 18.6 -9.966 1.000 0.000000 1.000000
+ 18.8 -9.966 1.000 0.000000 1.000000
+ 19.0 -9.966 1.000 0.000000 1.000000
+ 19.2 -9.966 1.000 0.000000 1.000000
+ 19.4 -9.966 1.000 0.000000 1.000000
+ 19.6 -9.966 1.000 0.000000 1.000000
+ 19.8 -9.966 1.000 0.000000 1.000000
+ 20.0 -9.966 1.000 0.000000 1.000000
+ 20.2 -9.966 1.000 0.000000 1.000000
+ 20.4 -9.966 1.000 0.000000 1.000000
+ 20.6 -9.966 1.000 0.000000 1.000000
+ 20.8 -9.966 1.000 0.000000 1.000000
+ 21.0 -9.966 1.000 0.000000 1.000000
+ 21.2 -9.966 1.000 0.000000 1.000000
+ 21.4 -9.966 1.000 0.000000 1.000000
+ 21.6 -9.966 1.000 0.000000 1.000000
+ 21.8 -9.966 1.000 0.000000 1.000000
+ 22.0 -9.966 1.000 0.000000 1.000000
+ 22.2 -9.966 1.000 0.000000 1.000000
+ 22.4 -9.966 1.000 0.000000 1.000000
+ 22.6 -9.966 1.000 0.000000 1.000000
+ 22.8 -9.966 1.000 0.000000 1.000000
+ 23.0 -9.966 1.000 0.000000 1.000000
+ 23.2 -9.966 1.000 0.000000 1.000000
+ 23.4 -9.966 1.000 0.000000 1.000000
+ 23.6 -9.966 1.000 0.000000 1.000000
+ 23.8 -9.966 1.000 0.000000 1.000000
+ 24.0 -9.966 1.000 0.000000 1.000000
+ 24.2 -9.966 1.000 0.000000 1.000000
+ 24.4 -9.966 1.000 0.000000 1.000000
+ 24.6 -9.966 1.000 0.000000 1.000000
+ 24.8 -9.966 1.000 0.000000 1.000000
+ 25.0 -9.966 1.000 0.000000 1.000000
+ 25.2 -9.966 1.000 0.000000 1.000000
+ 25.4 -9.966 1.000 0.000000 1.000000
diff --git a/lib/morse.f90 b/lib/morse.f90
new file mode 100644
index 00000000..de5f7a1b
--- /dev/null
+++ b/lib/morse.f90
@@ -0,0 +1,86 @@
+subroutine morse(msg,idat,n)
+
+! Convert ascii message to a Morse code bit string.
+! Dash = 3 dots
+! Space between dots, dashes = 1 dot
+! Space between letters = 3 dots
+! Space between words = 7 dots
+
+ character*(*) msg
+ integer idat(250)
+ integer*1 ic(21,38)
+ data ic/ &
+ 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,20, &
+ 1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,18, &
+ 1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,16, &
+ 1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, &
+ 1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,14, &
+ 1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,16, &
+ 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,18, &
+ 1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, &
+ 1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2, &
+ 1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, &
+ 1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, &
+ 1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, &
+ 1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,14, &
+ 1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, &
+ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, &
+ 1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, &
+ 1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, &
+ 1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, &
+ 1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, &
+ 1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,14, &
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2/ !Incremental word space
+ save
+
+ msglen=len(msg)
+ idat=0
+ n=6
+ do k=1,msglen
+ jj=ichar(msg(k:k))
+ if(jj.ge.97 .and. jj.le.122) jj=jj-32 !Convert lower to upper case
+ if(jj.ge.48 .and. jj.le.57) j=jj-48 !Numbers
+ if(jj.ge.65 .and. jj.le.90) j=jj-55 !Letters
+ if(jj.eq.47) j=36 !Slash (/)
+ if(jj.eq.32) j=37 !Word space
+ j=j+1
+
+! Insert this character
+ nmax=ic(21,j)
+ do i=1,nmax
+ n=n+1
+ idat(n)=ic(i,j)
+ enddo
+
+! Insert character space of 2 dit lengths:
+ n=n+1
+ idat(n)=0
+ n=n+1
+ idat(n)=0
+ enddo
+
+! Insert word space at end of message
+ do j=1,4
+ n=n+1
+ idat(n)=0
+ enddo
+
+ return
+end subroutine morse
diff --git a/lib/move.f90 b/lib/move.f90
new file mode 100644
index 00000000..13783dc7
--- /dev/null
+++ b/lib/move.f90
@@ -0,0 +1,7 @@
+subroutine move(x,y,n)
+ real x(n),y(n)
+ do i=1,n
+ y(i)=x(i)
+ enddo
+ return
+end subroutine move
diff --git a/lib/msgs.txt b/lib/msgs.txt
new file mode 100644
index 00000000..c38aba97
--- /dev/null
+++ b/lib/msgs.txt
@@ -0,0 +1,60 @@
+W1AAA K2BBB EM00
+W2CCC K3DDD EM01
+W3EEE K4FFF EM02
+W5GGG K6HHH EM03
+W7III K8JJJ EM04
+W9KKK K0LLL EM05
+G0MMM F1NNN JN06
+G2OOO F3PPP JN07
+G4QQQ F5RRR JN08
+G6SSS F7TTT JN09
+W1XAA K2XBB EM10
+W2XCC K3XDD EM11
+W3XEE K4XFF EM12
+W5XGG K6XHH EM13
+W7XII K8XJJ EM14
+W9XKK K0XLL EM15
+G0XMM F1XNN JN16
+G2XOO F3XPP JN17
+G4XQQ F5XRR JN18
+G6XSS F7XTT JN19
+W1YAA K2YBB EM20
+W2YCC K3YDD EM21
+W3YEE K4YFF EM22
+W5YGG K6YHH EM23
+W7YII K8YJJ EM24
+W9YKK K0YLL EM25
+G0YMM F1YNN JN26
+G2YOO F3YPP JN27
+G4YQQ F5YRR JN28
+G6YSS F7YTT JN29
+W1ZAA K2ZBB EM30
+W2ZCC K3ZDD EM31
+W3ZEE K4ZFF EM32
+W5ZGG K6ZHH EM33
+W7ZII K8ZJJ EM34
+W9ZKK K0ZLL EM35
+G0ZMM F1ZNN JN36
+G2ZOO F3ZPP JN37
+G4ZQQ F5ZRR JN38
+G6ZSS F7ZTT JN39
+W1AXA K2BXB EM40
+W2CXC K3DXD EM41
+W3EXE K4FXF EM42
+W5GXG K6HXH EM43
+W7IXI K8JXJ EM44
+W9KXK K0LXL EM45
+G0MXM F1NXN JN46
+G2OXO F3PXP JN47
+G4QXQ F5RXR JN48
+G6SXS F7TXT JN49
+W1AYA K2BYB EM50
+W2CYC K3DYD EM51
+W3EYE K4FYF EM52
+W5GYG K6HYH EM53
+W7IYI K8JYJ EM54
+W9KYK K0LYL EM55
+G0MYM F1NYN JN56
+G2OYO F3PYP JN57
+G4QYQ F5RYR JN58
+G6SYS F7TYT JN59
diff --git a/lib/n2grid.f90 b/lib/n2grid.f90
new file mode 100644
index 00000000..ed22a7d5
--- /dev/null
+++ b/lib/n2grid.f90
@@ -0,0 +1,14 @@
+subroutine n2grid(n,grid)
+ character*4 grid
+
+ if(n.gt.-31 .or. n.lt.-70) stop 'Error in n2grid'
+ i=-(n+31) !NB: 0 <= i <= 39
+ i1=i/10
+ i2=mod(i,10)
+ grid(1:1)=char(ichar('A')+i1)
+ grid(2:2)='A'
+ grid(3:3)=char(ichar('0')+i2)
+ grid(4:4)='0'
+
+ return
+end subroutine n2grid
diff --git a/lib/nchar.f90 b/lib/nchar.f90
new file mode 100644
index 00000000..167992ae
--- /dev/null
+++ b/lib/nchar.f90
@@ -0,0 +1,23 @@
+function nchar(c)
+
+! Convert ascii number, letter, or space to 0-36 for callsign packing.
+
+ character c*1
+
+ n=0 !Silence compiler warning
+ if(c.ge.'0' .and. c.le.'9') then
+ n=ichar(c)-ichar('0')
+ else if(c.ge.'A' .and. c.le.'Z') then
+ n=ichar(c)-ichar('A') + 10
+ else if(c.ge.'a' .and. c.le.'z') then
+ n=ichar(c)-ichar('a') + 10
+ else if(c.ge.' ') then
+ n=36
+ else
+ Print*,'Invalid character in callsign ',c,' ',ichar(c)
+ stop
+ endif
+ nchar=n
+
+ return
+end function nchar
diff --git a/lib/noisegen.f90 b/lib/noisegen.f90
new file mode 100644
index 00000000..f92a9df0
--- /dev/null
+++ b/lib/noisegen.f90
@@ -0,0 +1,13 @@
+subroutine noisegen(d4,nmax)
+
+ real*4 d4(4,nmax)
+
+ do i=1,nmax
+ d4(1,i)=gran()
+ d4(2,i)=gran()
+ d4(3,i)=gran()
+ d4(4,i)=gran()
+ enddo
+
+ return
+end subroutine noisegen
diff --git a/lib/packbits.f90 b/lib/packbits.f90
new file mode 100644
index 00000000..88851866
--- /dev/null
+++ b/lib/packbits.f90
@@ -0,0 +1,21 @@
+subroutine packbits(dbits,nsymd,m0,sym)
+
+! Pack 0s and 1s from dbits() into sym() with m0 bits per word.
+! NB: nsymd is the number of packed output words.
+
+ integer sym(nsymd)
+ integer*1 dbits(*)
+
+ k=0
+ do i=1,nsymd
+ n=0
+ do j=1,m0
+ k=k+1
+ m=dbits(k)
+ n=ior(ishft(n,1),m)
+ enddo
+ sym(i)=n
+ enddo
+
+ return
+end subroutine packbits
diff --git a/lib/packcall.f90 b/lib/packcall.f90
new file mode 100644
index 00000000..c4de474a
--- /dev/null
+++ b/lib/packcall.f90
@@ -0,0 +1,79 @@
+subroutine packcall(callsign,ncall,text)
+
+! Pack a valid callsign into a 28-bit integer.
+
+ parameter (NBASE=37*36*10*27*27*27)
+ character callsign*6,c*1,tmp*6
+ logical text
+
+ text=.false.
+
+! Work-around for Swaziland prefix:
+ if(callsign(1:4).eq.'3DA0') callsign='3D0'//callsign(5:6)
+
+ if(callsign(1:3).eq.'CQ ') then
+ ncall=NBASE + 1
+ if(callsign(4:4).ge.'0' .and. callsign(4:4).le.'9' .and. &
+ callsign(5:5).ge.'0' .and. callsign(5:5).le.'9' .and. &
+ callsign(6:6).ge.'0' .and. callsign(6:6).le.'9') then
+ read(callsign(4:6),*) nfreq
+ ncall=NBASE + 3 + nfreq
+ endif
+ return
+ else if(callsign(1:4).eq.'QRZ ') then
+ ncall=NBASE + 2
+ return
+ else if(callsign(1:3).eq.'DE ') then
+ ncall=267796945
+ return
+ endif
+
+ tmp=' '
+ if(callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') then
+ tmp=callsign
+ else if(callsign(2:2).ge.'0' .and. callsign(2:2).le.'9') then
+ if(callsign(6:6).ne.' ') then
+ text=.true.
+ return
+ endif
+ tmp=' '//callsign(:5)
+ else
+ text=.true.
+ return
+ endif
+
+ do i=1,6
+ c=tmp(i:i)
+ if(c.ge.'a' .and. c.le.'z') &
+ tmp(i:i)=char(ichar(c)-ichar('a')+ichar('A'))
+ enddo
+
+ n1=0
+ if((tmp(1:1).ge.'A'.and.tmp(1:1).le.'Z').or.tmp(1:1).eq.' ') n1=1
+ if(tmp(1:1).ge.'0' .and. tmp(1:1).le.'9') n1=1
+ n2=0
+ if(tmp(2:2).ge.'A' .and. tmp(2:2).le.'Z') n2=1
+ if(tmp(2:2).ge.'0' .and. tmp(2:2).le.'9') n2=1
+ n3=0
+ if(tmp(3:3).ge.'0' .and. tmp(3:3).le.'9') n3=1
+ n4=0
+ if((tmp(4:4).ge.'A'.and.tmp(4:4).le.'Z').or.tmp(4:4).eq.' ') n4=1
+ n5=0
+ if((tmp(5:5).ge.'A'.and.tmp(5:5).le.'Z').or.tmp(5:5).eq.' ') n5=1
+ n6=0
+ if((tmp(6:6).ge.'A'.and.tmp(6:6).le.'Z').or.tmp(6:6).eq.' ') n6=1
+
+ if(n1+n2+n3+n4+n5+n6 .ne. 6) then
+ text=.true.
+ return
+ endif
+
+ ncall=nchar(tmp(1:1))
+ ncall=36*ncall+nchar(tmp(2:2))
+ ncall=10*ncall+nchar(tmp(3:3))
+ ncall=27*ncall+nchar(tmp(4:4))-10
+ ncall=27*ncall+nchar(tmp(5:5))-10
+ ncall=27*ncall+nchar(tmp(6:6))-10
+
+ return
+end subroutine packcall
diff --git a/lib/packdxcc.f90 b/lib/packdxcc.f90
new file mode 100644
index 00000000..74f2789b
--- /dev/null
+++ b/lib/packdxcc.f90
@@ -0,0 +1,64 @@
+subroutine packdxcc(c,ng,ldxcc)
+
+ character*3 c
+ logical ldxcc
+
+ parameter (NZ=303)
+ character*5 pfx(NZ)
+ data pfx/ &
+ '1A ','1S ','3A ','3B6 ','3B8 ','3B9 ','3C ','3C0 ', &
+ '3D2 ', '3DA ','3V ','3W ','3X ','3Y ', &
+ '4J ','4L ','4S ','4U1 ', '4W ', &
+ '4X ','5A ','5B ','5H ','5N ','5R ','5T ','5U ', &
+ '5V ','5W ','5X ','5Z ','6W ','6Y ','7O ','7P ', &
+ '7Q ','7X ','8P ','8Q ','8R ','9A ','9G ','9H ', &
+ '9J ','9K ','9L ','9M2 ','9M6 ','9N ','9Q ','9U ', &
+ '9V ','9X ','9Y ','A2 ','A3 ','A4 ','A5 ','A6 ', &
+ 'A7 ','A9 ','AP ','BS7 ','BV ','BV9 ','BY ','C2 ', &
+ 'C3 ','C5 ','C6 ','C9 ','CE ','CE0 ', &
+ 'CE9 ','CM ','CN ','CP ','CT ','CT3 ','CU ','CX ', &
+ 'CY0 ','CY9 ','D2 ','D4 ','D6 ','DL ','DU ','E3 ', &
+ 'E4 ','EA ','EA6 ','EA8 ','EA9 ','EI ','EK ','EL ', &
+ 'EP ','ER ','ES ','ET ','EU ','EX ','EY ','EZ ', &
+ 'F ','FG ','FH ','FJ ','FK ', 'FM ','FO ', &
+ 'FP ','FR ', &
+ 'FT5 ', 'FW ','FY ','M ','MD ','MI ', &
+ 'MJ ','MM ', 'MU ','MW ','H4 ','H40 ','HA ', &
+ 'HB ','HB0 ','HC ','HC8 ','HH ','HI ','HK ','HK0 ', &
+ 'HL ','HM ','HP ','HR ','HS ','HV ','HZ ', &
+ 'I ','IG9 ','IS ','IT9 ','J2 ','J3 ','J5 ','J6 ', &
+ 'J7 ','J8 ','JA ','JD ', 'JT ','JW ', &
+ 'JX ','JY ','K ','KG4 ','KH0 ','KH1 ','KH2 ','KH3 ', &
+ 'KH4 ','KH5 ', 'KH6 ','KH7 ','KH8 ','KH9 ','KL ', &
+ 'KP1 ','KP2 ','KP4 ','KP5 ','LA ','LU ','LX ','LY ', &
+ 'LZ ','OA ','OD ','OE ','OH ','OH0 ','OJ0 ','OK ', &
+ 'OM ','ON ','OX ','OY ','OZ ','P2 ','P4 ','PA ', &
+ 'PJ2 ','PJ7 ','PY ','PY0 ', 'PZ ','R1F ', &
+ 'R1M ','S0 ','S2 ','S5 ','S7 ','S9 ','SM ','SP ', &
+ 'ST ','SU ','SV ', 'SV5 ','SV9 ','T2 ','T30 ', &
+ 'T31 ','T32 ','T33 ','T5 ','T7 ','T8 ','T9 ','TA ', &
+ 'TA1 ','TF ','TG ','TI ','TI9 ','TJ ','TK ','TL ', &
+ 'TN ','TR ','TT ','TU ','TY ','TZ ','UA ','UA2 ', &
+ 'UA9 ','UK ','UN ','UR ','V2 ','V3 ','V4 ','V5 ', &
+ 'V6 ','V7 ','V8 ','VE ','VK ','VK0 ', 'VK9 ', &
+ 'VP2 ', &
+ 'VP5 ','VP6 ', 'VP8 ', &
+ 'VP9 ','VQ9 ','VR ','VU ','VU4 ','VU7 ','XE ','XF4 ', &
+ 'XT ','XU ','XW ','XX9 ','XZ ','YA ','YB ','YI ', &
+ 'YJ ','YK ','YL ','YN ','YO ','YS ','YU ','YV ', &
+ 'YV0 ','Z2 ','Z3 ','ZA ','ZB ','ZC4 ','ZD7 ','ZD8 ', &
+ 'ZD9 ','ZF ','ZK1 ', 'ZK2 ','ZK3 ','ZL ','ZL7 ', &
+ 'ZL8 ','ZL9 ','ZP ','ZS ','ZS8 '/
+
+ ldxcc=.false.
+ ng=0
+ do i=1,NZ
+ if(pfx(i)(1:3).eq.c) go to 10
+ enddo
+ go to 20
+
+10 ng=180*180+61+i
+ ldxcc=.true.
+
+20 return
+end subroutine packdxcc
diff --git a/lib/packgrid.f90 b/lib/packgrid.f90
new file mode 100644
index 00000000..1cdb7313
--- /dev/null
+++ b/lib/packgrid.f90
@@ -0,0 +1,76 @@
+subroutine packgrid(grid,ng,text)
+
+ parameter (NGBASE=180*180)
+ character*4 grid
+ character*1 c1
+ logical text
+
+ text=.false.
+ if(grid.eq.' ') go to 90 !Blank grid is OK
+
+! First, handle signal reports in the original range, -01 to -30 dB
+ if(grid(1:1).eq.'-') then
+ read(grid(2:3),*,err=800,end=800) n
+ if(n.ge.1 .and. n.le.30) then
+ ng=NGBASE+1+n
+ go to 900
+ endif
+ go to 10
+ else if(grid(1:2).eq.'R-') then
+ read(grid(3:4),*,err=800,end=800) n
+ if(n.ge.1 .and. n.le.30) then
+ ng=NGBASE+31+n
+ go to 900
+ endif
+ go to 10
+! Now check for RO, RRR, or 73 in the message field normally used for grid
+ else if(grid(1:4).eq.'RO ') then
+ ng=NGBASE+62
+ go to 900
+ else if(grid(1:4).eq.'RRR ') then
+ ng=NGBASE+63
+ go to 900
+ else if(grid(1:4).eq.'73 ') then
+ ng=NGBASE+64
+ go to 900
+ endif
+
+! Now check for extended-range signal reports: -50 to -31, and 0 to +49.
+10 n=99
+ c1=grid(1:1)
+ read(grid,*,err=20,end=20) n
+ go to 30
+20 read(grid(2:4),*,err=30,end=30) n
+30 if(n.ge.-50 .and. n.le.49) then
+ if(c1.eq.'R') then
+ write(grid,1002) n+50
+1002 format('LA',i2.2)
+ else
+ write(grid,1003) n+50
+1003 format('KA',i2.2)
+ endif
+ go to 40
+ endif
+
+! Maybe it's free text ?
+ if(grid(1:1).lt.'A' .or. grid(1:1).gt.'R') text=.true.
+ if(grid(2:2).lt.'A' .or. grid(2:2).gt.'R') text=.true.
+ if(grid(3:3).lt.'0' .or. grid(3:3).gt.'9') text=.true.
+ if(grid(4:4).lt.'0' .or. grid(4:4).gt.'9') text=.true.
+ if(text) go to 900
+
+! OK, we have a properly formatted grid locator
+40 call grid2deg(grid//'mm',dlong,dlat)
+ long=int(dlong)
+ lat=int(dlat+ 90.0)
+ ng=((long+180)/2)*180 + lat
+ go to 900
+
+90 ng=NGBASE + 1
+ go to 900
+
+800 text=.true.
+900 continue
+
+ return
+end subroutine packgrid
diff --git a/lib/packmsg.f90 b/lib/packmsg.f90
new file mode 100644
index 00000000..6c7619bd
--- /dev/null
+++ b/lib/packmsg.f90
@@ -0,0 +1,113 @@
+subroutine packmsg(msg,dat,text)
+
+ parameter (NBASE=37*36*10*27*27*27)
+ parameter (NBASE2=262178562)
+ character*22 msg
+ integer dat(12)
+ character*12 c1,c2
+ character*4 c3
+ character*6 grid6
+ logical text1,text2,text3,text
+
+ text=.false.
+! Convert all letters to upper case
+ iz=22
+ do i=1,22
+ if(msg(i:i).ge.'a' .and. msg(i:i).le.'z') &
+ msg(i:i)= char(ichar(msg(i:i))+ichar('A')-ichar('a'))
+ if(msg(i:i).ne.' ') iz=i
+ enddo
+ do iter=1,5 !Collapse multiple blanks into one
+ ib2=index(msg(1:iz),' ')
+ if(ib2.lt.1) go to 5
+ msg=msg(1:ib2)//msg(ib2+2:)
+ iz=iz-1
+ enddo
+
+5 if(msg(1:6).eq.'CQ DX ') msg(3:3)='9'
+
+! See if it's a CQ message
+ if(msg(1:3).eq.'CQ ') then
+ i=3
+! ... and if so, does it have a reply frequency?
+ if(msg(4:4).ge.'0' .and. msg(4:4).le.'9' .and. &
+ msg(5:5).ge.'0' .and. msg(5:5).le.'9' .and. &
+ msg(6:6).ge.'0' .and. msg(6:6).le.'9') i=7
+ go to 1
+ endif
+
+ do i=1,22
+ if(msg(i:i).eq.' ') go to 1 !Get 1st blank
+ enddo
+ go to 10 !Consider msg as plain text
+
+1 ia=i
+ c1=msg(1:ia-1)
+ do i=ia+1,22
+ if(msg(i:i).eq.' ') go to 2 !Get 2nd blank
+ enddo
+ go to 10 !Consider msg as plain text
+
+2 ib=i
+ c2=msg(ia+1:ib-1)
+
+ do i=ib+1,22
+ if(msg(i:i).eq.' ') go to 3 !Get 3rd blank
+ enddo
+ go to 10 !Consider msg as plain text
+
+3 ic=i
+ c3=' '
+ if(ic.ge.ib+1) c3=msg(ib+1:ic)
+ if(c3.eq.'OOO ') c3=' ' !Strip out the OOO flag
+ call getpfx1(c1,k1,junk)
+ call packcall(c1,nc1,text1)
+ call getpfx1(c2,k2,nv2)
+ call packcall(c2,nc2,text2)
+ if(nv2.eq.0) then
+ if(k1.lt.0 .or. k2.lt.0 .or. k1*k2.ne.0) go to 10
+ if(k2.gt.0) k2=k2+450
+ k=max(k1,k2)
+ if(k.gt.0) then
+ call k2grid(k,grid6)
+ c3=grid6(:4)
+ endif
+ endif
+ call packgrid(c3,ng,text3)
+ if(nv2.eq.0 .and. (.not.text1) .and. (.not.text2) .and. &
+ (.not.text3)) go to 20
+ if(nv2.gt.0) then
+ if(nv2.eq.1) then
+ if(c1(1:3).eq.'CQ ') nc1=262178563 + k2
+ if(c1(1:4).eq.'QRZ ') nc1=264002072 + k2
+ if(c1(1:3).eq.'DE ') nc1=265825581 + k2
+ endif
+ if(nv2.eq.2) then
+ if(c1(1:3).eq.'CQ ') nc1=267649090 + k2
+ if(c1(1:4).eq.'QRZ ') nc1=267698375 + k2
+ if(c1(1:3).eq.'DE ') nc1=267747660 + k2
+ endif
+ go to 20
+ endif
+
+! The message will be treated as plain text.
+10 text=.true.
+ call packtext(msg,nc1,nc2,ng)
+ ng=ng+32768
+
+! Encode data into 6-bit words
+20 dat(1)=iand(ishft(nc1,-22),63) !6 bits
+ dat(2)=iand(ishft(nc1,-16),63) !6 bits
+ dat(3)=iand(ishft(nc1,-10),63) !6 bits
+ dat(4)=iand(ishft(nc1, -4),63) !6 bits
+ dat(5)=4*iand(nc1,15)+iand(ishft(nc2,-26),3) !4+2 bits
+ dat(6)=iand(ishft(nc2,-20),63) !6 bits
+ dat(7)=iand(ishft(nc2,-14),63) !6 bits
+ dat(8)=iand(ishft(nc2, -8),63) !6 bits
+ dat(9)=iand(ishft(nc2, -2),63) !6 bits
+ dat(10)=16*iand(nc2,3)+iand(ishft(ng,-12),15) !2+4 bits
+ dat(11)=iand(ishft(ng,-6),63)
+ dat(12)=iand(ng,63)
+
+ return
+end subroutine packmsg
diff --git a/lib/packtext.f90 b/lib/packtext.f90
new file mode 100644
index 00000000..10f34887
--- /dev/null
+++ b/lib/packtext.f90
@@ -0,0 +1,47 @@
+subroutine packtext(msg,nc1,nc2,nc3)
+
+ parameter (MASK28=2**28 - 1)
+ character*13 msg
+ character*42 c
+ data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/
+
+ nc1=0
+ nc2=0
+ nc3=0
+
+ do i=1,5 !First 5 characters in nc1
+ do j=1,42 !Get character code
+ if(msg(i:i).eq.c(j:j)) go to 10
+ enddo
+ j=37
+10 j=j-1 !Codes should start at zero
+ nc1=42*nc1 + j
+ enddo
+
+ do i=6,10 !Characters 6-10 in nc2
+ do j=1,42 !Get character code
+ if(msg(i:i).eq.c(j:j)) go to 20
+ enddo
+ j=37
+20 j=j-1 !Codes should start at zero
+ nc2=42*nc2 + j
+ enddo
+
+ do i=11,13 !Characters 11-13 in nc3
+ do j=1,42 !Get character code
+ if(msg(i:i).eq.c(j:j)) go to 30
+ enddo
+ j=37
+30 j=j-1 !Codes should start at zero
+ nc3=42*nc3 + j
+ enddo
+
+! We now have used 17 bits in nc3. Must move one each to nc1 and nc2.
+ nc1=nc1+nc1
+ if(iand(nc3,32768).ne.0) nc1=nc1+1
+ nc2=nc2+nc2
+ if(iand(nc3,65536).ne.0) nc2=nc2+1
+ nc3=iand(nc3,32767)
+
+ return
+end subroutine packtext
diff --git a/lib/pctile.f90 b/lib/pctile.f90
new file mode 100644
index 00000000..35ee3a7d
--- /dev/null
+++ b/lib/pctile.f90
@@ -0,0 +1,22 @@
+subroutine pctile(x,npts,npct,xpct)
+
+ parameter (NMAX=32768)
+ real*4 x(npts)
+ real*4 tmp(NMAX)
+
+ if(npts.le.0) then
+ xpct=1.0
+ go to 900
+ endif
+ if(npts.gt.NMAX) stop
+
+ tmp(1:npts)=x
+ call sort(npts,tmp)
+ j=nint(npts*0.01*npct)
+ if(j.lt.1) j=1
+ if(j.gt.npts) j=npts
+ xpct=tmp(j)
+
+900 continue
+ return
+end subroutine pctile
diff --git a/lib/peakdt9.f90 b/lib/peakdt9.f90
new file mode 100644
index 00000000..eac256ef
--- /dev/null
+++ b/lib/peakdt9.f90
@@ -0,0 +1,54 @@
+subroutine peakdt9(c2,nz2,nsps8,nspsd,c3,nz3,xdt)
+
+ complex c2(0:4096-1)
+ complex c3(0:4096-1)
+ complex z
+ real p(0:3300)
+ include 'jt9sync.f90'
+
+ p=0.
+ i0=5*nspsd
+ do i=0,nz2-1
+ z=1.e-3*sum(c2(max(i-(nspsd-1),0):i))
+ p(i0+i)=real(z)**2 + aimag(z)**2 !Integrated symbol power at freq=0
+ enddo
+
+ call getlags(nsps8,lag0,lag1,lag2)
+ tsymbol=nsps8/1500.0
+ dtlag=tsymbol/nspsd
+ smax=0.
+ lagpk=0
+ do lag=lag1,lag2
+ sum0=0.
+ sum1=0.
+ j=-nspsd
+ do i=1,85
+ j=j+nspsd
+ if(isync(i).eq.1) then
+ sum1=sum1+p(j+lag)
+ else
+ sum0=sum0+p(j+lag)
+ endif
+ enddo
+ ss=(sum1/16.0)/(sum0/69.0) - 1.0
+ xdt=(lag-lag0)*dtlag
+ if(ss.gt.smax) then
+ smax=ss
+ lagpk=lag
+ endif
+ enddo
+
+ xdt=(lagpk-lag0)*dtlag
+
+ nz3=nspsd*85
+ do i=0,nz3-1
+ j=i+lagpk-i0-nspsd+1
+ if(j.ge.0 .and. j.le.nz2) then
+ c3(i)=c2(j)
+ else
+ c3(i)=0.
+ endif
+ enddo
+
+ return
+end subroutine peakdt9
diff --git a/lib/peakup.f90 b/lib/peakup.f90
new file mode 100644
index 00000000..8e5aedaf
--- /dev/null
+++ b/lib/peakup.f90
@@ -0,0 +1,8 @@
+subroutine peakup(ym,y0,yp,dx)
+
+ b=(yp-ym)/2.0
+ c=(yp+ym-2.0*y0)/2.0
+ dx=-b/(2.0*c)
+
+ return
+end subroutine peakup
diff --git a/lib/pfx.f90 b/lib/pfx.f90
new file mode 100644
index 00000000..ca487181
--- /dev/null
+++ b/lib/pfx.f90
@@ -0,0 +1,50 @@
+ parameter (NZ=339) !Total number of prefixes
+ parameter (NZ2=12) !Total number of suffixes
+ character*1 sfx(NZ2)
+ character*5 pfx(NZ)
+
+ data sfx/'P','0','1','2','3','4','5','6','7','8','9','A'/
+ data pfx/ &
+ '1A ','1S ','3A ','3B6 ','3B8 ','3B9 ','3C ','3C0 ', &
+ '3D2 ','3D2C ','3D2R ','3DA ','3V ','3W ','3X ','3Y ', &
+ '3YB ','3YP ','4J ','4L ','4S ','4U1I ','4U1U ','4W ', &
+ '4X ','5A ','5B ','5H ','5N ','5R ','5T ','5U ', &
+ '5V ','5W ','5X ','5Z ','6W ','6Y ','7O ','7P ', &
+ '7Q ','7X ','8P ','8Q ','8R ','9A ','9G ','9H ', &
+ '9J ','9K ','9L ','9M2 ','9M6 ','9N ','9Q ','9U ', &
+ '9V ','9X ','9Y ','A2 ','A3 ','A4 ','A5 ','A6 ', &
+ 'A7 ','A9 ','AP ','BS7 ','BV ','BV9 ','BY ','C2 ', &
+ 'C3 ','C5 ','C6 ','C9 ','CE ','CE0X ','CE0Y ','CE0Z ', &
+ 'CE9 ','CM ','CN ','CP ','CT ','CT3 ','CU ','CX ', &
+ 'CY0 ','CY9 ','D2 ','D4 ','D6 ','DL ','DU ','E3 ', &
+ 'E4 ','EA ','EA6 ','EA8 ','EA9 ','EI ','EK ','EL ', &
+ 'EP ','ER ','ES ','ET ','EU ','EX ','EY ','EZ ', &
+ 'F ','FG ','FH ','FJ ','FK ','FKC ','FM ','FO ', &
+ 'FOA ','FOC ','FOM ','FP ','FR ','FRG ','FRJ ','FRT ', &
+ 'FT5W ','FT5X ','FT5Z ','FW ','FY ','M ','MD ','MI ', &
+ 'MJ ','MM ', 'MU ','MW ','H4 ','H40 ','HA ', &
+ 'HB ','HB0 ','HC ','HC8 ','HH ','HI ','HK ','HK0A ', &
+ 'HK0M ','HL ','HM ','HP ','HR ','HS ','HV ','HZ ', &
+ 'I ','IS ','IS0 ', 'J2 ','J3 ','J5 ','J6 ', &
+ 'J7 ','J8 ','JA ','JDM ','JDO ','JT ','JW ', &
+ 'JX ','JY ','K ','KG4 ','KH0 ','KH1 ','KH2 ','KH3 ', &
+ 'KH4 ','KH5 ','KH5K ','KH6 ','KH7 ','KH8 ','KH9 ','KL ', &
+ 'KP1 ','KP2 ','KP4 ','KP5 ','LA ','LU ','LX ','LY ', &
+ 'LZ ','OA ','OD ','OE ','OH ','OH0 ','OJ0 ','OK ', &
+ 'OM ','ON ','OX ','OY ','OZ ','P2 ','P4 ','PA ', &
+ 'PJ2 ','PJ7 ','PY ','PY0F ','PT0S ','PY0T ','PZ ','R1F ', &
+ 'R1M ','S0 ','S2 ','S5 ','S7 ','S9 ','SM ','SP ', &
+ 'ST ','SU ','SV ','SVA ','SV5 ','SV9 ','T2 ','T30 ', &
+ 'T31 ','T32 ','T33 ','T5 ','T7 ','T8 ','T9 ','TA ', &
+ 'TF ','TG ','TI ','TI9 ','TJ ','TK ','TL ', &
+ 'TN ','TR ','TT ','TU ','TY ','TZ ','UA ','UA2 ', &
+ 'UA9 ','UK ','UN ','UR ','V2 ','V3 ','V4 ','V5 ', &
+ 'V6 ','V7 ','V8 ','VE ','VK ','VK0H ','VK0M ','VK9C ', &
+ 'VK9L ','VK9M ','VK9N ','VK9W ','VK9X ','VP2E ','VP2M ','VP2V ', &
+ 'VP5 ','VP6 ','VP6D ','VP8 ','VP8G ','VP8H ','VP8O ','VP8S ', &
+ 'VP9 ','VQ9 ','VR ','VU ','VU4 ','VU7 ','XE ','XF4 ', &
+ 'XT ','XU ','XW ','XX9 ','XZ ','YA ','YB ','YI ', &
+ 'YJ ','YK ','YL ','YN ','YO ','YS ','YU ','YV ', &
+ 'YV0 ','Z2 ','Z3 ','ZA ','ZB ','ZC4 ','ZD7 ','ZD8 ', &
+ 'ZD9 ','ZF ','ZK1N ','ZK1S ','ZK2 ','ZK3 ','ZL ','ZL7 ', &
+ 'ZL8 ','ZL9 ','ZP ','ZS ','ZS8 ','KC4 ','E5 '/
diff --git a/lib/pfxdump.f90 b/lib/pfxdump.f90
new file mode 100644
index 00000000..7587dbf7
--- /dev/null
+++ b/lib/pfxdump.f90
@@ -0,0 +1,13 @@
+subroutine pfxdump(fname)
+ character*(*) fname
+ include 'pfx.f90'
+
+ open(11,file=fname,status='unknown')
+ write(11,1001) sfx
+1001 format('Supported Suffixes:'/(11('/',a1,2x)))
+ write(11,1002) pfx
+1002 format(/'Supported Add-On DXCC Prefixes:'/(15(a5,1x)))
+ close(11)
+
+ return
+end subroutine pfxdump
diff --git a/lib/ps24.f90 b/lib/ps24.f90
new file mode 100644
index 00000000..241e49fa
--- /dev/null
+++ b/lib/ps24.f90
@@ -0,0 +1,27 @@
+subroutine ps24(dat,nfft,s)
+
+ parameter (NMAX=2520+2)
+ parameter (NHMAX=NMAX/2-1)
+ real dat(nfft)
+ real dat2(NMAX)
+ real s(NHMAX)
+ complex c(0:NMAX)
+ equivalence(dat2,c)
+
+ nh=nfft/2
+ do i=1,nh
+ dat2(i)=dat(i)/128.0 !### Why 128 ??
+ enddo
+ do i=nh+1,nfft
+ dat2(i)=0.
+ enddo
+
+ call four2a(c,nfft,1,-1,0)
+
+ fac=1.0/nfft
+ do i=1,nh
+ s(i)=fac*(real(c(i))**2 + aimag(c(i))**2)
+ enddo
+
+ return
+end subroutine ps24
diff --git a/lib/ptt.c b/lib/ptt.c
new file mode 100644
index 00000000..902193fd
--- /dev/null
+++ b/lib/ptt.c
@@ -0,0 +1,50 @@
+#include <windows.h>
+#include <stdio.h>
+
+int ptt_(int *nport, int *ntx, int *iptt)
+{
+ static HANDLE hFile;
+ static int open=0;
+ char s[10];
+ int i3=1,i4=1,i5=1,i6=1,i9=1,i00=1;
+
+ if(*nport==0) {
+ *iptt=*ntx;
+ return(0);
+ }
+
+ if(*ntx && (!open)) {
+ sprintf(s,"\\\\.\\COM%d",*nport);
+ hFile=CreateFile(TEXT(s),GENERIC_WRITE,0,NULL,OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,NULL);
+ if(hFile==INVALID_HANDLE_VALUE) {
+ // printf("PTT: Cannot open COM port %d.\n",*nport);
+ return 1;
+ }
+ open=1;
+ }
+
+ if(*ntx && open) {
+ i3=EscapeCommFunction(hFile,3);
+ i5=EscapeCommFunction(hFile,5);
+ *iptt=1;
+ }
+
+ else {
+ i4=EscapeCommFunction(hFile,4);
+ i6=EscapeCommFunction(hFile,6);
+ i9=EscapeCommFunction(hFile,9);
+ i00=CloseHandle(hFile);
+ *iptt=0;
+ open=0;
+ }
+ /*
+ if(i3==0) return 3;
+ if(i4==0) return 4;
+ if(i5==0) return 5;
+ if(i6==0) return 6;
+ if(i9==0) return 9;
+ if(i00==0) return 10;
+ */
+ return 0;
+}
diff --git a/lib/rig_control.c b/lib/rig_control.c
new file mode 100644
index 00000000..7c8b2f62
--- /dev/null
+++ b/lib/rig_control.c
@@ -0,0 +1,99 @@
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "tstrig.h"
+
+RIG *my_rig; // handle to rig
+
+int set_conf(RIG *my_rig, char *conf_parms);
+
+//------------------------------------------------------------------------
+int set_conf(RIG *my_rig, char *conf_parms)
+{
+ char *p, *q, *n;
+ int iret;
+
+ p = conf_parms;
+ while (p && *p != '\0') {
+ /* FIXME: left hand value of = cannot be null */
+ q = strchr(p, '=');
+ if ( !q )
+ return -RIG_EINVAL;
+ *q++ = '\0';
+ n = strchr(q, ',');
+ if (n) *n++ = '\0';
+ iret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q);
+ if (iret != RIG_OK)
+ return iret;
+ p = n;
+ }
+ return RIG_OK;
+}
+
+//------------------------------------------------------------------------
+int rigOpen(int verbose, rig_model_t my_model, const char* rig_file,
+ int serial_rate, const char* conf_parms2)
+{
+ int iret; /* generic return code from functions */
+ char *civaddr = NULL; /* NULL means no need to set conf */
+ // const char *rig_file;
+ // const char *conf_parms2;
+ // int serial_rate;
+
+ rig_set_debug(verbose);
+ my_rig=rig_init(my_model);
+
+ if (!my_rig) {
+ // fprintf(stderr, "Unknown rig num %d, or initialization error.\n",my_model);
+ return -1;
+ }
+
+ // rig_file="COM1";
+ // serial_rate=4800;
+ // conf_parms2="data_bits=8,stop_bits=2,serial_handshake=Hardware";
+
+ iret=set_conf(my_rig, conf_parms2);
+ if (iret!=RIG_OK) {
+ // fprintf(stderr, "Config parameter error: %s\n", rigerror(iret));
+ return -2;
+ }
+
+ if (rig_file)
+ strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
+
+ if (serial_rate!=0)
+ my_rig->state.rigport.parm.serial.rate = serial_rate;
+
+ if (civaddr)
+ rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
+
+ iret = rig_open(my_rig);
+ if(iret!=0) return -3;
+ return 0;
+}
+
+int rigSetFreq(int fHz)
+{
+ return rig_set_freq(my_rig,RIG_VFO_CURR,fHz);
+}
+
+int rigFreq(int *fHz)
+{
+ int iret=0;
+ freq_t freq;
+ iret=rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
+ *fHz=freq;
+ return iret;
+}
+
+int rigSetPTT(int iptt)
+{
+ return rig_set_ptt(my_rig, RIG_VFO_CURR, iptt);
+}
+
+void rigClose()
+{
+ rig_close(my_rig);
+ rig_cleanup(my_rig);
+}
diff --git a/lib/rs.h b/lib/rs.h
new file mode 100644
index 00000000..06cbe344
--- /dev/null
+++ b/lib/rs.h
@@ -0,0 +1,35 @@
+/* User include file for the Reed-Solomon codec
+ * Copyright 2002, Phil Karn KA9Q
+ * May be used under the terms of the GNU General Public License (GPL)
+ */
+
+/* General purpose RS codec, 8-bit symbols */
+void encode_rs_char(void *rs,unsigned char *data,unsigned char *parity);
+int decode_rs_char(void *rs,unsigned char *data,int *eras_pos,
+ int no_eras);
+void *init_rs_char(int symsize,int gfpoly,
+ int fcr,int prim,int nroots,
+ int pad);
+void free_rs_char(void *rs);
+
+/* General purpose RS codec, integer symbols */
+void encode_rs_int(void *rs,int *data,int *parity);
+int decode_rs_int(void *rs,int *data,int *eras_pos,int no_eras);
+void *init_rs_int(int symsize,int gfpoly,int fcr,
+ int prim,int nroots,int pad);
+void free_rs_int(void *rs);
+
+/* CCSDS standard (255,223) RS codec with conventional (*not* dual-basis)
+ * symbol representation
+ */
+void encode_rs_8(unsigned char *data,unsigned char *parity,int pad);
+int decode_rs_8(unsigned char *data,int *eras_pos,int no_eras,int pad);
+
+/* CCSDS standard (255,223) RS codec with dual-basis symbol representation */
+void encode_rs_ccsds(unsigned char *data,unsigned char *parity,int pad);
+int decode_rs_ccsds(unsigned char *data,int *eras_pos,int no_eras,int pad);
+
+/* Tables to map from conventional->dual (Taltab) and
+ * dual->conventional (Tal1tab) bases
+ */
+extern unsigned char Taltab[],Tal1tab[];
diff --git a/lib/s3avg.f90 b/lib/s3avg.f90
new file mode 100644
index 00000000..f8f68ac5
--- /dev/null
+++ b/lib/s3avg.f90
@@ -0,0 +1,60 @@
+subroutine s3avg(nsave,mode65,nutc,nhz,xdt,npol,ntol,s3,nsum,nkv,decoded)
+
+! Save the current synchronized spectra, s3(64,63), for possible
+! decoding of average.
+
+ real s3(64,63) !Synchronized spectra for 63 symbols
+ real s3a(64,63,64) !Saved spectra
+ real s3b(64,63) !Average spectra
+ integer iutc(64),ihz(64),ipol(64)
+ real dt(64)
+ character*22 decoded
+ logical ltext,first
+ data first/.true./
+ save
+
+ if(first) then
+ iutc=-1
+ ihz=0
+ ipol=0
+ first=.false.
+ ihzdiff=min(100,ntol)
+ dtdiff=0.2
+ endif
+
+ do i=1,64
+ if(nutc.eq.iutc(i) .and. abs(nhz-ihz(i)).lt.ihzdiff) then
+ nsave=mod(nsave-1+64,64)+1
+ go to 10
+ endif
+ enddo
+
+ iutc(nsave)=nutc !Save UTC
+ ihz(nsave)=nhz !Save freq in Hz
+ ipol(nsave)=npol !Save pol
+ dt(nsave)=xdt !Save DT
+ s3a(1:64,1:63,nsave)=s3 !Save the spectra
+
+10 s3b=0.
+ do i=1,64 !Accumulate avg spectra
+ if(iutc(i).lt.0) cycle
+ if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same sequence
+ if(abs(nhz-ihz(i)).gt.ihzdiff) cycle !Freq must match
+ if(abs(xdt-dt(i)).gt.dtdiff) cycle !DT must match
+ s3b=s3b + s3a(1:64,1:63,i)
+ nsum=nsum+1
+ enddo
+
+ decoded=' '
+ if(nsum.ge.2) then !Try decoding the sverage
+ nadd=mode65*nsum
+ call extract(s3b,nadd,ncount,nhist,decoded,ltext) !Extract the message
+ nkv=nsum
+ if(ncount.lt.0) then
+ nkv=0
+ decoded=' '
+ endif
+ endif
+
+ return
+end subroutine s3avg
diff --git a/lib/sec_midn.f90 b/lib/sec_midn.f90
new file mode 100644
index 00000000..0bbe62c2
--- /dev/null
+++ b/lib/sec_midn.f90
@@ -0,0 +1,11 @@
+real function sec_midn()
+ sec_midn=secnds(0.0)
+ return
+end function sec_midn
+
+subroutine sleep_msec(n)
+
+ call usleep(1000*n)
+
+ return
+end subroutine sleep_msec
diff --git a/lib/setup65.f90 b/lib/setup65.f90
new file mode 100644
index 00000000..608b41b9
--- /dev/null
+++ b/lib/setup65.f90
@@ -0,0 +1,96 @@
+subroutine setup65
+
+! Defines arrays related to the JT65 pseudo-random synchronizing pattern.
+! Executed at program start.
+
+ integer nprc(126)
+ common/prcom/pr(126),mdat(126),mref(126,2),mdat2(126),mref2(126,2)
+
+! JT65
+ data nprc/ &
+ 1,0,0,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0, &
+ 0,1,0,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,1,1, &
+ 0,1,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1, &
+ 0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,1, &
+ 1,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1, &
+ 0,1,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1, &
+ 1,1,1,1,1,1/
+ data mr2/0/ !Silence compiler warning
+
+! Put the appropriate pseudo-random sequence into pr
+ nsym=126
+ do i=1,nsym
+ pr(i)=2*nprc(i)-1
+ enddo
+
+! Determine locations of data and reference symbols
+ k=0
+ mr1=0
+ do i=1,nsym
+ if(pr(i).lt.0.0) then
+ k=k+1
+ mdat(k)=i
+ else
+ mr2=i
+ if(mr1.eq.0) mr1=i
+ endif
+ enddo
+ nsig=k
+
+! Determine the reference symbols for each data symbol.
+ do k=1,nsig
+ m=mdat(k)
+ mref(k,1)=mr1
+ do n=1,10 !Get ref symbol before data
+ if((m-n).gt.0) then
+ if (pr(m-n).gt.0.0) go to 10
+ endif
+ enddo
+ go to 12
+10 mref(k,1)=m-n
+12 mref(k,2)=mr2
+ do n=1,10 !Get ref symbol after data
+ if((m+n).le.nsym) then
+ if (pr(m+n).gt.0.0) go to 20
+ endif
+ enddo
+ cycle
+20 mref(k,2)=m+n
+ enddo
+
+! Now do it all again, using opposite logic on pr(i)
+ k=0
+ mr1=0
+ do i=1,nsym
+ if(pr(i).gt.0.0) then
+ k=k+1
+ mdat2(k)=i
+ else
+ mr2=i
+ if(mr1.eq.0) mr1=i
+ endif
+ enddo
+ nsig=k
+
+ do k=1,nsig
+ m=mdat2(k)
+ mref2(k,1)=mr1
+ do n=1,10
+ if((m-n).gt.0) then
+ if (pr(m-n).lt.0.0) go to 110
+ endif
+ enddo
+ go to 112
+110 mref2(k,1)=m-n
+112 mref2(k,2)=mr2
+ do n=1,10
+ if((m+n).le.nsym) then
+ if (pr(m+n).lt.0.0) go to 120
+ endif
+ enddo
+ cycle
+120 mref2(k,2)=m+n
+ enddo
+
+ return
+end subroutine setup65
diff --git a/lib/sleep.h b/lib/sleep.h
new file mode 100644
index 00000000..df60bc92
--- /dev/null
+++ b/lib/sleep.h
@@ -0,0 +1,32 @@
+/*
+ * sleep.h 1.0 02/03/10
+ *
+ * Defines cross-platform sleep, usleep, etc.
+ *
+ * By Wu Yongwei
+ *
+ */
+
+#ifndef _SLEEP_H
+#define _SLEEP_H
+
+#ifdef _WIN32
+# if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__))
+# include <stdlib.h>
+# define sleep(t) _sleep((t) * 1000)
+# else
+# include <windows.h>
+# define sleep(t) Sleep((t) * 1000)
+# endif
+# ifndef _NEED_SLEEP_ONLY
+# define msleep(t) Sleep(t)
+# define usleep(t) Sleep((t) / 1000)
+# endif
+#else
+# include <unistd.h>
+# ifndef _NEED_SLEEP_ONLY
+# define msleep(t) usleep((t) * 1000)
+# endif
+#endif
+
+#endif /* _SLEEP_H */
diff --git a/lib/sleep_msec.f90 b/lib/sleep_msec.f90
new file mode 100644
index 00000000..1a8dbe4f
--- /dev/null
+++ b/lib/sleep_msec.f90
@@ -0,0 +1,4 @@
+subroutine sleep_msec(n)
+ call usleep(n*1000)
+ return
+end subroutine sleep_msec
diff --git a/lib/slope.f90 b/lib/slope.f90
new file mode 100644
index 00000000..5581ade1
--- /dev/null
+++ b/lib/slope.f90
@@ -0,0 +1,40 @@
+subroutine slope(y,npts,xpk)
+
+! Remove best-fit slope from data in y(i). When fitting the straight line,
+! ignore the peak around xpk +/- 2.
+
+ real y(npts)
+ real x(100)
+
+ do i=1,npts
+ x(i)=i
+ enddo
+
+ sumw=0.
+ sumx=0.
+ sumy=0.
+ sumx2=0.
+ sumxy=0.
+ sumy2=0.
+
+ do i=1,npts
+ if(abs(i-xpk).gt.2.0) then
+ sumw=sumw + 1.0
+ sumx=sumx + x(i)
+ sumy=sumy + y(i)
+ sumx2=sumx2 + x(i)**2
+ sumxy=sumxy + x(i)*y(i)
+ sumy2=sumy2 + y(i)**2
+ endif
+ enddo
+
+ delta=sumw*sumx2 - sumx**2
+ a=(sumx2*sumy - sumx*sumxy) / delta
+ b=(sumw*sumxy - sumx*sumy) / delta
+
+ do i=1,npts
+ y(i)=y(i)-(a + b*x(i))
+ enddo
+
+ return
+end subroutine slope
diff --git a/lib/smo121.f90 b/lib/smo121.f90
new file mode 100644
index 00000000..7ae30ad1
--- /dev/null
+++ b/lib/smo121.f90
@@ -0,0 +1,13 @@
+subroutine smo121(x,nz)
+
+ real x(nz)
+
+ x0=x(1)
+ do i=2,nz-1
+ x1=x(i)
+ x(i)=0.5*x(i) + 0.25*(x0+x(i+1))
+ x0=x1
+ enddo
+
+ return
+end subroutine smo121
diff --git a/lib/softsym.f90 b/lib/softsym.f90
new file mode 100644
index 00000000..8eda5e73
--- /dev/null
+++ b/lib/softsym.f90
@@ -0,0 +1,50 @@
+subroutine softsym(id2,npts8,nsps8,newdat,fpk,syncpk,snrdb,xdt, &
+ freq,drift,schk,i1SoftSymbols)
+
+! Compute the soft symbols
+
+ complex c2(0:4096-1)
+ complex c3(0:4096-1)
+ complex c5(0:4096-1)
+ real a(3)
+ integer*1 i1SoftSymbolsScrambled(207)
+ integer*1 i1SoftSymbols(207)
+ include 'jt9sync.f90'
+
+ nspsd=16
+ ndown=nsps8/nspsd
+
+! Mix, low-pass filter, and downsample to 16 samples per symbol
+ call timer('downsam9',0)
+ call downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2,nz2)
+ call timer('downsam9',1)
+
+ call timer('peakdt9 ',0)
+ call peakdt9(c2,nz2,nsps8,nspsd,c3,nz3,xdt) !Find DT
+ call timer('peakdt9 ',1)
+
+ fsample=1500.0/ndown
+ a=0.
+ call timer('afc9 ',0)
+ call afc9(c3,nz3,fsample,a,syncpk) !Find deltaF, fDot, fDDot
+ call timer('afc9 ',1)
+ freq=fpk - a(1)
+ drift=-2.0*a(2)
+
+ call timer('twkfreq ',0)
+ call twkfreq(c3,c5,nz3,fsample,a) !Correct for delta f, f1, f2 ==> a(1:3)
+ call timer('twkfreq ',1)
+
+! Compute soft symbols (in scrambled order)
+ call timer('symspec2',0)
+ call symspec2(c5,nz3,nsps8,nspsd,fsample,freq,drift,snrdb,schk, &
+ i1SoftSymbolsScrambled)
+ call timer('symspec2',1)
+
+! Remove interleaving
+ call timer('interlv9',0)
+ call interleave9(i1SoftSymbolsScrambled,-1,i1SoftSymbols)
+ call timer('interlv9',1)
+
+ return
+end subroutine softsym
diff --git a/lib/sort.f90 b/lib/sort.f90
new file mode 100644
index 00000000..281ce027
--- /dev/null
+++ b/lib/sort.f90
@@ -0,0 +1,4 @@
+subroutine sort(n,arr)
+ call ssort(arr,tmp,n,1)
+ return
+end subroutine sort
diff --git a/lib/ss.bat b/lib/ss.bat
new file mode 100644
index 00000000..37f669a1
--- /dev/null
+++ b/lib/ss.bat
@@ -0,0 +1 @@
+svn status | grep -v '?'
diff --git a/lib/ssort.f90 b/lib/ssort.f90
new file mode 100644
index 00000000..7d712388
--- /dev/null
+++ b/lib/ssort.f90
@@ -0,0 +1,264 @@
+subroutine ssort (x,y,n,kflag)
+! Sort an array and optionally make the same interchanges in
+! an auxiliary array. the array may be sorted in increasing
+! or decreasing order. a slightly modified quicksort
+! algorithm is used.
+
+! ssort sorts array x and optionally makes the same interchanges in
+! array y. the array x may be sorted in increasing order or
+! decreasing order. a slightly modified quicksort algorithm is used.
+
+! Description of parameters
+! x - array of values to be sorted
+! y - array to be (optionally) carried along
+! n - number of values in array x to be sorted
+! kflag - control parameter
+! = 2 means sort x in increasing order and carry y along.
+! = 1 means sort x in increasing order (ignoring y)
+! = -1 means sort x in decreasing order (ignoring y)
+! = -2 means sort x in decreasing order and carry y along.
+
+ integer kflag, n
+ integer x(n), y(n)
+ real r
+ integer t, tt, tty, ty
+ integer i, ij, j, k, kk, l, m, nn
+ integer il(21), iu(21)
+
+ nn = n
+ if (nn .lt. 1) then
+! print*,'ssort: The number of sort elements is not positive.'
+! print*,'ssort: n = ',nn,' kflag = ',kflag
+ return
+ endif
+
+ kk = abs(kflag)
+ if (kk.ne.1 .and. kk.ne.2) then
+ print *,'the sort control parameter, k, is not 2, 1, -1, or -2.'
+ return
+ endif
+
+! Alter array x to get decreasing order if needed
+
+ if (kflag .le. -1) then
+ do i=1,nn
+ x(i) = -x(i)
+ enddo
+ endif
+
+ if (kk .eq. 2) go to 100
+
+! Sort x only
+
+ m = 1
+ i = 1
+ j = nn
+ r = 0.375e0
+
+20 if (i .eq. j) go to 60
+ if (r .le. 0.5898437e0) then
+ r = r+3.90625e-2
+ else
+ r = r-0.21875e0
+ endif
+
+30 k = i
+
+! Select a central element of the array and save it in location t
+
+ ij = i + int((j-i)*r)
+ t = x(ij)
+
+! If first element of array is greater than t, interchange with t
+
+ if (x(i) .gt. t) then
+ x(ij) = x(i)
+ x(i) = t
+ t = x(ij)
+ endif
+ l = j
+
+! If last element of array is less than than t, interchange with t
+ if (x(j) .lt. t) then
+ x(ij) = x(j)
+ x(j) = t
+ t = x(ij)
+
+! If first element of array is greater than t, interchange with t
+ if (x(i) .gt. t) then
+ x(ij) = x(i)
+ x(i) = t
+ t = x(ij)
+ endif
+ endif
+
+! Find an element in the second half of the array which is smaller than t
+40 l = l-1
+ if (x(l) .gt. t) go to 40
+
+! Find an element in the first half of the array which is greater than t
+50 k = k+1
+ if (x(k) .lt. t) go to 50
+
+! Interchange these elements
+ if (k .le. l) then
+ tt = x(l)
+ x(l) = x(k)
+ x(k) = tt
+ go to 40
+ endif
+
+! Save upper and lower subscripts of the array yet to be sorted
+ if (l-i .gt. j-k) then
+ il(m) = i
+ iu(m) = l
+ i = k
+ m = m+1
+ else
+ il(m) = k
+ iu(m) = j
+ j = l
+ m = m+1
+ endif
+ go to 70
+
+! Begin again on another portion of the unsorted array
+60 m = m-1
+ if (m .eq. 0) go to 190
+ i = il(m)
+ j = iu(m)
+
+70 if (j-i .ge. 1) go to 30
+ if (i .eq. 1) go to 20
+ i = i-1
+
+80 i = i+1
+ if (i .eq. j) go to 60
+ t = x(i+1)
+ if (x(i) .le. t) go to 80
+ k = i
+
+90 x(k+1) = x(k)
+ k = k-1
+ if (t .lt. x(k)) go to 90
+ x(k+1) = t
+ go to 80
+
+! Sort x and carry y along
+
+100 m = 1
+ i = 1
+ j = nn
+ r = 0.375e0
+
+110 if (i .eq. j) go to 150
+ if (r .le. 0.5898437e0) then
+ r = r+3.90625e-2
+ else
+ r = r-0.21875e0
+ endif
+
+ 120 k = i
+! Select a central element of the array and save it in location t
+ ij = i + int((j-i)*r)
+ t = x(ij)
+ ty = y(ij)
+
+! If first element of array is greater than t, interchange with t
+ if (x(i) .gt. t) then
+ x(ij) = x(i)
+ x(i) = t
+ t = x(ij)
+ y(ij) = y(i)
+ y(i) = ty
+ ty = y(ij)
+ endif
+ l = j
+
+! If last element of array is less than t, interchange with t
+ if (x(j) .lt. t) then
+ x(ij) = x(j)
+ x(j) = t
+ t = x(ij)
+ y(ij) = y(j)
+ y(j) = ty
+ ty = y(ij)
+
+! If first element of array is greater than t, interchange with t
+ if (x(i) .gt. t) then
+ x(ij) = x(i)
+ x(i) = t
+ t = x(ij)
+ y(ij) = y(i)
+ y(i) = ty
+ ty = y(ij)
+ endif
+ endif
+
+! Find an element in the second half of the array which is smaller than t
+130 l = l-1
+ if (x(l) .gt. t) go to 130
+
+! Find an element in the first half of the array which is greater than t
+140 k = k+1
+ if (x(k) .lt. t) go to 140
+
+! Interchange these elements
+ if (k .le. l) then
+ tt = x(l)
+ x(l) = x(k)
+ x(k) = tt
+ tty = y(l)
+ y(l) = y(k)
+ y(k) = tty
+ go to 130
+ endif
+
+! Save upper and lower subscripts of the array yet to be sorted
+ if (l-i .gt. j-k) then
+ il(m) = i
+ iu(m) = l
+ i = k
+ m = m+1
+ else
+ il(m) = k
+ iu(m) = j
+ j = l
+ m = m+1
+ endif
+ go to 160
+
+! Begin again on another portion of the unsorted array
+150 m = m-1
+ if (m .eq. 0) go to 190
+ i = il(m)
+ j = iu(m)
+
+160 if (j-i .ge. 1) go to 120
+ if (i .eq. 1) go to 110
+ i = i-1
+
+170 i = i+1
+ if (i .eq. j) go to 150
+ t = x(i+1)
+ ty = y(i+1)
+ if (x(i) .le. t) go to 170
+ k = i
+
+180 x(k+1) = x(k)
+ y(k+1) = y(k)
+ k = k-1
+ if (t .lt. x(k)) go to 180
+ x(k+1) = t
+ y(k+1) = ty
+ go to 170
+
+! Clean up
+190 if (kflag .le. -1) then
+ do i=1,nn
+ x(i) = -x(i)
+ enddo
+ endif
+
+ return
+end subroutine ssort
diff --git a/lib/stdmsg.f90 b/lib/stdmsg.f90
new file mode 100644
index 00000000..bc8d489a
--- /dev/null
+++ b/lib/stdmsg.f90
@@ -0,0 +1,12 @@
+logical*1 function stdmsg(msg0)
+
+ character*22 msg0,msg
+ integer dat(12)
+ logical text
+
+ call packmsg(msg0,dat,text)
+ call unpackmsg(dat,msg)
+ stdmsg=msg.eq.msg0 .and. (.not.text)
+
+ return
+end function stdmsg
diff --git a/lib/symspec.f90 b/lib/symspec.f90
new file mode 100644
index 00000000..2facb490
--- /dev/null
+++ b/lib/symspec.f90
@@ -0,0 +1,113 @@
+subroutine symspec(k,ntrperiod,nsps,ingain,slope,pxdb,s,df3,ihsym,npts8)
+
+! Input:
+! k pointer to the most recent new data
+! ntrperiod T/R sequence length, minutes
+! nsps samples per symbol, at 12000 Hz
+! ndiskdat 0/1 to indicate if data from disk
+! nb 0/1 status of noise blanker (off/on)
+! nbslider NB setting, 0-100
+
+! Output:
+! pxdb power (0-60 dB)
+! s() current spectrum for waterfall display
+! ihsym index number of this half-symbol (1-184)
+
+! jt9com
+! ss() JT9 symbol spectra at half-symbol steps
+! savg() average spectra for waterfall display
+
+ include 'constants.f90'
+ real*4 w3(MAXFFT3)
+ real*4 s(NSMAX)
+ real*4 scale(NSMAX)
+ real*4 ssum(NSMAX)
+ real*4 xc(0:MAXFFT3-1)
+ complex cx(0:MAXFFT3/2)
+ integer*2 id2
+ common/jt9com/ss(184,NSMAX),savg(NSMAX),id2(NMAX),nutc,ndiskdat, &
+ ntr,mousefqso,newdat,nfa,nfb,ntol,kin,nzhsym,nsynced,ndecoded
+ data rms/999.0/,k0/99999999/,nfft3z/0/,slope0/0.0/
+ equivalence (xc,cx)
+ save
+
+ if(ntrperiod.eq.-999) stop !Silence compiler warning
+ nfft3=16384 !df=12000.0/16384 = 0.732422
+ jstep=nsps/2 !Step size = half-symbol in id2()
+ if(k.gt.NMAX) go to 900
+ if(k.lt.2048) then !(2048 was nfft3) (Any need for this ???)
+ ihsym=0
+ go to 900 !Wait for enough samples to start
+ endif
+
+ if(nfft3.ne.nfft3z .or. slope.ne.slope0) then !New nfft3, compute window
+ pi=4.0*atan(1.0)
+ do i=1,nfft3
+ w3(i)=2.0*(sin(i*pi/nfft3))**2 !Window for nfft3 spectrum
+ enddo
+ nfft3z=nfft3
+ nh=NSMAX/2
+ do i=1,NSMAX
+ x=slope*float(i)/nh - 1.0 + 2.6
+ scale(i)=10.0**x
+ enddo
+ slope0=slope
+ endif
+
+ if(k.lt.k0) then !Start a new data block
+ ja=0
+ ssum=0.
+ ihsym=0
+ if(ndiskdat.eq.0) id2(k+1:)=0 !Needed to prevent "ghosts". Not sure why.
+ endif
+ gain=10.0**(0.05*ingain)
+ sq=0.
+ do i=k0+1,k
+ x1=id2(i)
+ sq=sq + x1*x1
+ enddo
+ sq=sq * gain**2
+ rms=sqrt(sq/(k-k0))
+ pxdb=0.
+ if(rms.gt.0.0) pxdb=20.0*log10(rms)
+ if(pxdb.gt.60.0) pxdb=60.0
+
+
+ k0=k
+ ja=ja+jstep !Index of first sample
+
+ fac0=0.1
+ do i=0,nfft3-1 !Copy data into cx
+ j=ja+i-(nfft3-1)
+ xc(i)=0.
+ if(j.ge.1) xc(i)=fac0*id2(j)
+ enddo
+
+ if(ihsym.lt.184) ihsym=ihsym+1
+
+ xc(0:nfft3-1)=w3(1:nfft3)*xc(0:nfft3-1) !Apply window w3
+ call four2a(xc,nfft3,1,-1,0) !Real-to-complex FFT
+
+ n=min(184,ihsym)
+ df3=12000.0/nfft3 !JT9-1: 0.732 Hz = 0.42 * tone spacing
+! i0=nint(1000.0/df3)
+ i0=0
+ iz=min(NSMAX,nint(5000.0/df3))
+ fac=(1.0/nfft3)**2
+ do i=1,iz
+ j=i0+i-1
+ if(j.lt.0) j=j+nfft3
+ sx=fac*(real(cx(j))**2 + aimag(cx(j))**2)
+ ss(n,i)=sx
+ ssum(i)=ssum(i) + sx
+ s(i)=gain*sx
+ enddo
+
+! s=0.05*s/ref
+ s=scale*s
+ savg=scale*ssum/ihsym
+
+900 npts8=k/8
+
+ return
+end subroutine symspec
diff --git a/lib/symspec2.f90 b/lib/symspec2.f90
new file mode 100644
index 00000000..92dc5715
--- /dev/null
+++ b/lib/symspec2.f90
@@ -0,0 +1,88 @@
+subroutine symspec2(c5,nz3,nsps8,nspsd,fsample,freq,drift,snrdb,schk, &
+ i1SoftSymbolsScrambled)
+
+! Compute soft symbols from the final downsampled data
+
+ complex c5(0:4096-1)
+ complex z
+ integer*1 i1SoftSymbolsScrambled(207)
+ real aa(3)
+ real ss2(0:8,85)
+ real ss3(0:7,69)
+ include 'jt9sync.f90'
+ data scale/10.0/
+
+ aa(1)=-1500.0/nsps8
+ aa(2)=0.
+ aa(3)=0.
+ do i=0,8 !Loop over the 9 tones
+ if(i.ge.1) call twkfreq(c5,c5,nz3,fsample,aa)
+ m=0
+ k=-1
+ do j=1,85 !Loop over all symbols
+ z=0.
+ do n=1,nspsd !Sum over 16 samples
+ k=k+1
+ z=z+c5(k)
+ enddo
+ ss2(i,j)=real(z)**2 + aimag(z)**2 !Symbol speactra, data and sync
+ if(i.ge.1 .and. isync(j).eq.0) then
+ m=m+1
+ ss3(i-1,m)=ss2(i,j) !Symbol speactra, data only
+ endif
+ enddo
+ enddo
+
+ call chkss2(ss2,freq,drift,schk)
+ if(schk.lt.2.0) go to 900
+
+ ss=0.
+ sig=0.
+ do j=1,69
+ smax=0.
+ do i=0,7
+ smax=max(smax,ss3(i,j))
+ ss=ss+ss3(i,j)
+ enddo
+ sig=sig+smax
+ ss=ss-smax
+ enddo
+ ave=ss/(69*7) !Baseline
+ call pctile(ss2,9*85,35,xmed)
+ ss3=ss3/ave
+ sig=sig/69. !Signal
+ t=max(1.0,sig - 1.0)
+ snrdb=db(t) - 61.3
+
+ m0=3
+ k=0
+ do j=1,69
+ smax=0.
+ do i=0,7
+ if(ss3(i,j).gt.smax) smax=ss3(i,j)
+ enddo
+
+ do m=m0-1,0,-1 !Get bit-wise soft symbols
+ if(m.eq.2) then
+ r1=max(ss3(4,j),ss3(5,j),ss3(6,j),ss3(7,j))
+ r0=max(ss3(0,j),ss3(1,j),ss3(2,j),ss3(3,j))
+ else if(m.eq.1) then
+ r1=max(ss3(2,j),ss3(3,j),ss3(4,j),ss3(5,j))
+ r0=max(ss3(0,j),ss3(1,j),ss3(6,j),ss3(7,j))
+ else
+ r1=max(ss3(1,j),ss3(2,j),ss3(4,j),ss3(7,j))
+ r0=max(ss3(0,j),ss3(3,j),ss3(5,j),ss3(6,j))
+ endif
+
+ k=k+1
+ i4=nint(scale*(r1-r0))
+ if(i4.lt.-127) i4=-127
+ if(i4.gt.127) i4=127
+ i4=i4+128
+ if(i4.le.127) i1SoftSymbolsScrambled(k)=i4
+ if(i4.ge.128) i1SoftSymbolsScrambled(k)=i4-256
+ enddo
+ enddo
+
+900 return
+end subroutine symspec2
diff --git a/lib/symspec65.f90 b/lib/symspec65.f90
new file mode 100644
index 00000000..5f6da88f
--- /dev/null
+++ b/lib/symspec65.f90
@@ -0,0 +1,47 @@
+subroutine symspec65(dd,npts,ss,nhsym,savg)
+
+! Compute JT65 symbol spectra at half-symbol steps
+
+ parameter (NFFT=8192)
+ parameter (NSZ=3413) !NFFT*5000/12000
+ parameter (MAXHSYM=322)
+ real*8 hstep
+ real*4 dd(npts)
+ real*4 ss(MAXHSYM,NSZ)
+ real*4 savg(NSZ)
+ real*4 x(NFFT)
+ complex c(0:NFFT/2)
+ common/refspec/dfref,ref(NSZ)
+ equivalence (x,c)
+ save /refspec/
+
+ hstep=2048.d0*12000.d0/11025.d0 !half-symbol = 2229.116 samples
+ nsps=nint(2*hstep)
+ df=12000.0/NFFT
+ nhsym=npts/hstep - 1.0
+ savg=0.
+ fac1=1.e-3
+
+ do j=1,nhsym
+ i0=(j-1)*hstep
+ x(1:nsps)=fac1*dd(i0+1:i0+nsps)
+ x(nsps+1:)=0.
+ call four2a(c,NFFT,1,-1,0) !r2c forward FFT
+ do i=1,NSZ
+ s=real(c(i))**2 + aimag(c(i))**2
+ ss(j,i)=s
+ savg(i)=savg(i)+s
+ enddo
+ enddo
+ savg=savg/nhsym
+
+ call flat65(ss,nhsym,MAXHSYM,NSZ,ref) !Flatten the 2d spectrum, saving
+ dfref=df ! the reference spectrum ref()
+
+ savg=savg/ref
+ do j=1,nhsym
+ ss(j,1:NSZ)=ss(j,1:NSZ)/ref
+ enddo
+
+ return
+end subroutine symspec65
diff --git a/lib/sync24.f90 b/lib/sync24.f90
new file mode 100644
index 00000000..cf6bf5af
--- /dev/null
+++ b/lib/sync24.f90
@@ -0,0 +1,179 @@
+subroutine sync24(dat,jz,DFTolerance,NFreeze,MouseDF,mode,mode4, &
+ dtx,dfx,snrx,snrsync,ccfblue,ccfred1,flip,width)
+
+! Synchronizes JT4 data, finding the best-fit DT and DF.
+
+ parameter (NFFTMAX=2520) !Max length of FFTs
+ parameter (NHMAX=NFFTMAX/2) !Max length of power spectra
+ parameter (NSMAX=525) !Max number of half-symbol steps
+ integer DFTolerance !Range of DF search
+ real dat(jz)
+ real psavg(NHMAX) !Average spectrum of whole record
+ real s2(NHMAX,NSMAX) !2d spectrum, stepped by half-symbols
+ real ccfblue(-5:540) !CCF with pseudorandom sequence
+ real ccfred(-450:450) !Peak of ccfblue, as function of freq
+ real ccfred1(-224:224) !Peak of ccfblue, as function of freq
+ real tmp(1260)
+ save
+
+! Do FFTs of twice symbol length, stepped by half symbols. Note that
+! we have already downsampled the data by factor of 2.
+
+ nsym=207
+ nfft=2520
+ nh=nfft/2
+ nq=nfft/4
+ nsteps=jz/nq - 1
+ df=0.5*11025.0/nfft
+ psavg(1:nh)=0.
+
+ do j=1,nsteps !Compute spectrum for each step, get average
+ k=(j-1)*nq + 1
+ call ps24(dat(k),nfft,s2(1,j))
+ psavg(1:nh)=psavg(1:nh) + s2(1:nh,j)
+ enddo
+
+ call flat1(psavg,s2,nh,nsteps,NHMAX,NSMAX) !Flatten spectra
+
+! Set freq and lag ranges
+ famin=200.
+ fbmax=2700.
+ fa=famin
+ fb=fbmax
+ if(NFreeze.eq.1) then
+ fa=max(famin,1270.46+MouseDF-DFTolerance)
+ fb=min(fbmax,1270.46+MouseDF+DFTolerance)
+ else
+ fa=max(famin,1270.46+MouseDF-600)
+ fb=min(fbmax,1270.46+MouseDF+600)
+ endif
+ ia=fa/df
+ ib=fb/df
+ if(mode.eq.7) then
+ ia=ia - 3*mode4
+ ib=ib - 3*mode4
+ endif
+ i0=nint(1270.46/df)
+ lag1=-5
+ lag2=59
+ syncbest=-1.e30
+ syncbest2=-1.e30
+ ccfred=0.
+
+ do i=ia,ib !Find best frequency channel for CCF
+
+ call xcor24(s2,i,nsteps,nsym,lag1,lag2,mode4,ccfblue,ccf0,lagpk0,flip)
+ j=i-i0
+ if(mode.eq.7) j=j + 3*mode4
+ if(j.ge.-372 .and. j.le.372) ccfred(j)=ccf0
+
+! Find rms of the CCF, without main peak
+ call slope(ccfblue(lag1),lag2-lag1+1,lagpk0-lag1+1.0)
+ sync=abs(ccfblue(lagpk0))
+ ppmax=psavg(i)-1.0
+
+! Find best sync value
+ if(sync.gt.syncbest2) then
+ ipk2=i
+ lagpk2=lagpk0
+ syncbest2=sync
+ endif
+
+! We are most interested if snrx will be more than -30 dB.
+ if(ppmax.gt.0.2938) then !Corresponds to snrx.gt.-30.0
+ if(sync.gt.syncbest) then
+ ipk=i
+ lagpk=lagpk0
+ syncbest=sync
+ endif
+ endif
+ enddo
+
+! If we found nothing with snrx > -30 dB, take the best sync that *was* found.
+ if(syncbest.lt.-10.) then
+ ipk=ipk2
+ lagpk=lagpk2
+ syncbest=syncbest2
+ endif
+
+ dfx=(ipk-i0)*df
+ if(mode.eq.7) dfx=dfx + 3*mode4*df
+
+! Peak up in time, at best whole-channel frequency
+ call xcor24(s2,ipk,nsteps,nsym,lag1,lag2,mode4,ccfblue,ccfmax,lagpk,flip)
+ xlag=lagpk
+ if(lagpk.gt.lag1 .and. lagpk.lt.lag2) then
+ call peakup(ccfblue(lagpk-1),ccfmax,ccfblue(lagpk+1),dx2)
+ xlag=lagpk+dx2
+ endif
+
+! Find rms of the CCF, without the main peak
+ call slope(ccfblue(lag1),lag2-lag1+1,xlag-lag1+1.0)
+ sq=0.
+ nsq=0
+ do lag=lag1,lag2
+ if(abs(lag-xlag).gt.2.0) then
+ sq=sq+ccfblue(lag)**2
+ nsq=nsq+1
+ endif
+ enddo
+ rms=sqrt(sq/nsq)
+ snrsync=abs(ccfblue(lagpk))/rms - 1.1 !Empirical
+
+ dt=2.0/11025.0
+ istart=xlag*nq
+ dtx=istart*dt
+ snrx=-99.0
+ ppmax=psavg(ipk)-1.0
+
+ if(ppmax.gt.0.0001) then
+ snrx=db(ppmax*df/2500.0) + 7.5 !Empirical
+ if(mode.eq.7) snrx=snrx + 3.0 !Empirical
+ endif
+ if(snrx.lt.-33.0) snrx=-33.0
+
+! Compute width of sync tone to outermost -3 dB points
+ i1=max(-450,ia-i0)
+ i2=min(450,ib-i0)
+ call pctile(ccfred(i1),i2-i1+1,45,base)
+
+ jpk=ipk-i0
+ if(abs(jpk).gt.450) then
+ print*,'sync24 a:',jpk,ipk,i0
+ snrsync=0.
+ go to 999
+ else
+ stest=base + 0.5*(ccfred(jpk)-base) ! -3 dB
+ endif
+ do i=-10,0
+ if(jpk+i.ge.-371) then
+ if(ccfred(jpk+i).gt.stest) go to 30
+ endif
+ enddo
+ i=0
+30 continue
+ if(abs(jpk+i-1).gt.450 .or. abs(jpk+i).gt.450) then
+ print*,'sync24 b:',jpk,i
+ else
+ x1=i-0.5
+ endif
+
+ do i=10,0,-1
+ if(jpk+i.le.371) then
+ if(ccfred(jpk+i).gt.stest) go to 32
+ endif
+ enddo
+ i=0
+32 x2=i+0.5
+ width=x2-x1
+ if(width.gt.1.2) width=sqrt(width**2 - 1.44)
+ width=df*width
+ width=max(0.0,min(99.0,width))
+
+ do i=-224,224
+ ccfred1(i)=ccfred(i)
+ enddo
+
+999 return
+end subroutine sync24
+
diff --git a/lib/sync9.f90 b/lib/sync9.f90
new file mode 100644
index 00000000..433e11f7
--- /dev/null
+++ b/lib/sync9.f90
@@ -0,0 +1,101 @@
+subroutine sync9(ss,nzhsym,lag1,lag2,ia,ib,ccfred,red2,ipkbest)
+
+ include 'constants.f90'
+! parameter (NSMAX=1365) !Max length of saved spectra
+ real ss(184,NSMAX)
+ real ss1(184)
+ real ccfred(NSMAX)
+ real savg(NSMAX)
+ real savg2(NSMAX)
+ real smo(-5:25)
+ real sq(NSMAX)
+ real red2(NSMAX)
+ include 'jt9sync.f90'
+
+ ipk=0
+ ipkbest=0
+ sbest=0.
+ ccfred=0.
+
+ do i=ia,ib !Loop over freq range
+ ss1=ss(1:184,i)
+ call pctile(ss1,nzhsym,40,xmed)
+! xmed=sum(ss1(1:nzhsym))/nzhsym
+
+ ss1=ss1/xmed - 1.0
+ do j=1,nzhsym
+ if(ss1(j).gt.3.0) ss1(j)=3.0
+ enddo
+
+ call pctile(ss1,nzhsym,45,sbase)
+ ss1=ss1-sbase
+ sq0=dot_product(ss1(1:nzhsym),ss1(1:nzhsym))
+ rms=sqrt(sq0/(nzhsym-1))
+
+ smax=0.
+ do lag=lag1,lag2 !DT = 2.5 to 5.0 s
+ sum1=0.
+ sq2=sq0
+ nsum=nzhsym
+ do j=1,16 !Sum over 16 sync symbols
+ k=ii2(j) + lag
+ if(k.ge.1 .and. k.le.nzhsym) then
+ sum1=sum1 + ss1(k)
+ sq2=sq2 - ss1(k)*ss1(k)
+ nsum=nsum-1
+ endif
+ enddo
+ if(sum1.gt.smax) then
+ smax=sum1
+ ipk=i
+ endif
+ rms=sqrt(sq2/(nsum-1))
+ enddo
+ ccfred(i)=smax !Best at this freq, over all lags
+ if(smax.gt.sbest) then
+ sbest=smax
+ ipkbest=ipk
+ endif
+ enddo
+
+ call pctile(ccfred(ia),ib-ia+1,50,xmed)
+ if(xmed.le.0.0) xmed=1.0
+ ccfred=2.0*ccfred/xmed
+
+ savg=0.
+ do j=1,nzhsym
+ savg(ia:ib)=savg(ia:ib) + ss(j,ia:ib)
+ enddo
+! df=1500.0/2048.0 ! 0.732422
+! df9=12000.0/6912.0 ! 1.736111
+ savg(ia:ib)=savg(ia:ib)/nzhsym
+ smo(0:20)=1.0/21.0
+ smo(-5:-1)=-(1.0/21.0)*(21.0/10.0)
+ smo(21:25)=smo(-5)
+
+ do i=ia,ib
+ sm=0.
+ do j=-5,25
+ if(i+j.ge.1 .and. i+j.lt.NSMAX) sm=sm + smo(j)*savg(i+j)
+ enddo
+ savg2(i)=sm
+ sq(i)=sm*sm
+ enddo
+
+ call pctile(sq(ia:ib),ib-ia+1,20,sq0)
+ rms=sqrt(sq0)
+ savg2(ia:ib)=savg2(ia:ib)/(5.0*rms)
+
+ red2=0.
+ do i=ia+11,ib-10
+ ref=max(savg2(i-10),savg2(i+10))
+ red2(i)=savg2(i)-ref
+ if(red2(i).lt.-99.0) red2(i)=-99.0
+ if(red2(i).gt.99.0) red2(i)=99.0
+! write(30,3001) i,i*df+1000.0,savg2(i),red2(i),ccfred(i)
+!3001 format(i8,4f10.3)
+ enddo
+! call flush(30)
+
+ return
+end subroutine sync9
diff --git a/lib/tab.c b/lib/tab.c
new file mode 100644
index 00000000..3cd419aa
--- /dev/null
+++ b/lib/tab.c
@@ -0,0 +1,36 @@
+/* 8-bit parity lookup table, generated by partab.c */
+unsigned char Partab[] = {
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 0, 1, 1, 0, 1, 0, 0, 1,
+ 1, 0, 0, 1, 0, 1, 1, 0,
+};
+
diff --git a/lib/timer.f90 b/lib/timer.f90
new file mode 100644
index 00000000..16374932
--- /dev/null
+++ b/lib/timer.f90
@@ -0,0 +1,112 @@
+subroutine timer(dname,k)
+
+! Times procedure number n between a call with k=0 (tstart) and with
+! k=1 (tstop). Accumulates sums of these times in array ut (user time).
+! Also traces all calls (for debugging purposes) if limtrace.gt.0
+
+ character*8 dname,name(50),space,ename
+ character*16 sname
+ logical on(50)
+ real ut(50),ut0(50),dut(50)
+ integer ncall(50),nlevel(50),nparent(50)
+ integer onlevel(0:10)
+ common/tracer/ limtrace,lu
+ data eps/0.000001/,ntrace/0/
+ data level/0/,nmax/0/,space/' '/
+ data limtrace/0/,lu/-1/
+ save
+
+ if(limtrace.lt.0) go to 999
+ if(lu.lt.1) lu=6
+ if(k.gt.1) go to 40 !Check for "all done" (k>1)
+ onlevel(0)=0
+
+ do n=1,nmax !Check for existing name
+ if(name(n).eq.dname) go to 20
+ enddo
+
+ nmax=nmax+1 !This is a new one
+ n=nmax
+ ncall(n)=0
+ on(n)=.false.
+ ut(n)=eps
+ name(n)=dname
+
+20 if(k.eq.0) then !Get start times (k=0)
+ if(on(n)) print*,'Error in timer: ',dname,' already on.'
+ level=level+1 !Increment the level
+ on(n)=.true.
+ call system_clock(icount,irate)
+ ut0(n)=float(icount)/irate
+ ncall(n)=ncall(n)+1
+ if(ncall(n).gt.1.and.nlevel(n).ne.level) then
+ nlevel(n)=-1
+ else
+ nlevel(n)=level
+ endif
+ nparent(n)=onlevel(level-1)
+ onlevel(level)=n
+
+ else if(k.eq.1) then !Get stop times and accumulate sums. (k=1)
+ if(on(n)) then
+ on(n)=.false.
+ call system_clock(icount,irate)
+ ut1=float(icount)/irate
+ ut(n)=ut(n)+ut1-ut0(n)
+ endif
+ level=level-1
+ endif
+
+ ntrace=ntrace+1
+ if(ntrace.lt.limtrace) write(lu,1020) ntrace,dname,k,level,nparent(n)
+1020 format(i8,': ',a8,3i5)
+ go to 998
+
+! Write out the timer statistics
+
+40 write(lu,1040)
+1040 format(/' name time frac dtime', &
+ ' dfrac calls level parent'/73('-'))
+
+ if(k.gt.100) then
+ ndiv=k-100
+ do i=1,nmax
+ ncall(i)=ncall(i)/ndiv
+ ut(i)=ut(i)/ndiv
+ enddo
+ endif
+
+ total=ut(1)
+ sum=0.
+ sumf=0.
+ do i=1,nmax
+ dut(i)=ut(i)
+ do j=i,nmax
+ if(nparent(j).eq.i) dut(i)=dut(i)-ut(j)
+ enddo
+ utf=ut(i)/total
+ dutf=dut(i)/total
+ sum=sum+dut(i)
+ sumf=sumf+dutf
+ kk=nlevel(i)
+ sname=space(1:kk)//name(i)//space(1:8-kk)
+ ename=space
+ if(i.ge.2) ename=name(nparent(i))
+ write(lu,1060) float(i),sname,ut(i),utf,dut(i),dutf, &
+ ncall(i),nlevel(i),ename
+1060 format(f4.0,a16,2(f10.2,f6.2),i7,i5,2x,a8)
+ enddo
+
+ write(lu,1070) sum,sumf
+1070 format(/36x,f10.2,f6.2)
+ nmax=0
+ eps=0.000001
+ ntrace=0
+ level=0
+ space=' '
+ onlevel(0)=0
+
+998 flush(lu)
+
+999 return
+end subroutine timer
diff --git a/lib/timeval.h b/lib/timeval.h
new file mode 100644
index 00000000..100dda5a
--- /dev/null
+++ b/lib/timeval.h
@@ -0,0 +1,74 @@
+/*
+ * timeval.h 1.0 01/12/19
+ *
+ * Defines gettimeofday, timeval, etc. for Win32
+ *
+ * By Wu Yongwei
+ *
+ */
+
+#ifndef _TIMEVAL_H
+#define _TIMEVAL_H
+
+#ifdef _WIN32
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <time.h>
+
+#ifndef __GNUC__
+#define EPOCHFILETIME (116444736000000000i64)
+#else
+#define EPOCHFILETIME (116444736000000000LL)
+#endif
+
+//struct timeval {
+// long tv_sec; /* seconds */
+// long tv_usec; /* microseconds */
+//};
+
+struct timezone {
+ int tz_minuteswest; /* minutes W of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
+
+__inline int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ FILETIME ft;
+ LARGE_INTEGER li;
+ __int64 t;
+ static int tzflag;
+
+ if (tv)
+ {
+ GetSystemTimeAsFileTime(&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ t = li.QuadPart; /* In 100-nanosecond intervals */
+ t -= EPOCHFILETIME; /* Offset to the Epoch time */
+ t /= 10; /* In microseconds */
+ tv->tv_sec = (long)(t / 1000000);
+ tv->tv_usec = (long)(t % 1000000);
+ }
+
+ if (tz)
+ {
+ if (!tzflag)
+ {
+ _tzset();
+ tzflag++;
+ }
+ tz->tz_minuteswest = _timezone / 60;
+ tz->tz_dsttime = _daylight;
+ }
+
+ return 0;
+}
+
+#else /* _WIN32 */
+
+#include <sys/time.h>
+
+#endif /* _WIN32 */
+
+#endif /* _TIMEVAL_H */
diff --git a/lib/tstrig.c b/lib/tstrig.c
new file mode 100644
index 00000000..2e77fea5
--- /dev/null
+++ b/lib/tstrig.c
@@ -0,0 +1,26 @@
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "tstrig.h"
+
+int set_conf(RIG *my_rig, char *conf_parms);
+
+int rig_control(rig_model_t my_model, int verbose);
+
+int main (int argc, char *argv[])
+{
+ rig_model_t my_model = RIG_MODEL_DUMMY;
+ int verbose=0;
+
+ my_model=214;
+ rig_control(my_model,verbose);
+ return 0;
+}
+
+/*
+gcc -c -Wall -I../include rig_control.c
+gcc -c -Wall -I../include tstrig.c
+gcc -o tstrig.exe -Wl,--enable-auto-import tstrig.o rig_control.o libhamlib.dll.a
+strip tstrig.exe
+*/
diff --git a/lib/tstrig.h b/lib/tstrig.h
new file mode 100644
index 00000000..ce62d3d7
--- /dev/null
+++ b/lib/tstrig.h
@@ -0,0 +1,50 @@
+/*
+ * rigctl_parse.h - (C) Stephane Fillod 2000-2010
+ *
+ * This program test/control a radio using Hamlib.
+ * It takes commands in interactive mode as well as
+ * from command line options.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef RIGCTL_PARSE_H
+#define RIGCTL_PARSE_H
+
+#include <stdio.h>
+#include <hamlib/rig.h>
+
+/*
+ * external prototype
+ */
+
+int dumpcaps (RIG *, FILE *);
+int dumpconf (RIG *, FILE *);
+
+/*
+ * Prototypes
+ */
+void usage_rig(FILE *);
+void version();
+void list_models();
+int dump_chan(FILE *, RIG*, channel_t*);
+int print_conf_list(const struct confparams *cfp, rig_ptr_t data);
+int set_conf(RIG *my_rig, char *conf_parms);
+
+int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc);
+
+#endif /* RIGCTL_PARSE_H */
diff --git a/lib/twkfreq.f90 b/lib/twkfreq.f90
new file mode 100644
index 00000000..0a9b34d2
--- /dev/null
+++ b/lib/twkfreq.f90
@@ -0,0 +1,28 @@
+subroutine twkfreq(c3,c4,npts,fsample,a)
+
+ complex c3(npts)
+ complex c4(npts)
+ complex w,wstep
+ real a(3)
+ data twopi/6.283185307/
+
+! Mix the complex signal
+ w=1.0
+ wstep=1.0
+ x0=0.5*(npts+1)
+ s=2.0/npts
+ do i=1,npts
+ x=s*(i-x0)
+ if(mod(i,100).eq.1) then
+ p2=1.5*x*x - 0.5
+! p3=2.5*(x**3) - 1.5*x
+! p4=4.375*(x**4) - 3.75*(x**2) + 0.375
+ dphi=(a(1) + x*a(2) + p2*a(3)) * (twopi/fsample)
+ wstep=cmplx(cos(dphi),sin(dphi))
+ endif
+ w=w*wstep
+ c4(i)=w*c3(i)
+ enddo
+
+ return
+end subroutine twkfreq
diff --git a/lib/twkfreq65.f90 b/lib/twkfreq65.f90
new file mode 100644
index 00000000..85847c7b
--- /dev/null
+++ b/lib/twkfreq65.f90
@@ -0,0 +1,25 @@
+subroutine twkfreq65(c4aa,n5,a)
+
+ complex c4aa(n5)
+ real a(5)
+ complex w,wstep
+ data twopi/6.283185307/
+
+! Apply AFC corrections to the c4aa data
+ w=1.0
+ wstep=1.0
+ x0=0.5*(n5+1)
+ s=2.0/n5
+ do i=1,n5
+ x=s*(i-x0)
+ if(mod(i,100).eq.1) then
+ p2=1.5*x*x - 0.5
+ dphi=(a(1) + x*a(2) + p2*a(3)) * (twopi/1378.125)
+ wstep=cmplx(cos(dphi),sin(dphi))
+ endif
+ w=w*wstep
+ c4aa(i)=w*c4aa(i)
+ enddo
+
+ return
+end subroutine twkfreq65
diff --git a/lib/unpackbits.f90 b/lib/unpackbits.f90
new file mode 100644
index 00000000..a3ff15f1
--- /dev/null
+++ b/lib/unpackbits.f90
@@ -0,0 +1,22 @@
+subroutine unpackbits(sym,nsymd,m0,dbits)
+
+! Unpack bits from sym() into dbits(), one bit per byte.
+! NB: nsymd is the number of input words, and m0 their length.
+! there will be m0*nsymd output bytes, each 0 or 1.
+
+ integer sym(nsymd)
+ integer*1 dbits(*)
+
+ k=0
+ do i=1,nsymd
+ mask=ishft(1,m0-1)
+ do j=1,m0
+ k=k+1
+ dbits(k)=0
+ if(iand(mask,sym(i)).ne.0) dbits(k)=1
+ mask=ishft(mask,-1)
+ enddo
+ enddo
+
+ return
+end subroutine unpackbits
diff --git a/lib/unpackcall.f90 b/lib/unpackcall.f90
new file mode 100644
index 00000000..f738926c
--- /dev/null
+++ b/lib/unpackcall.f90
@@ -0,0 +1,142 @@
+subroutine unpackcall(ncall,word,iv2,psfx)
+
+ parameter (NBASE=37*36*10*27*27*27)
+ character word*12,c*37,psfx*4
+
+ data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/
+
+ n=ncall
+ iv2=0
+ if(n.ge.262177560) go to 20
+ word='......'
+ if(n.ge.262177560) go to 999 !Plain text message ...
+ i=mod(n,27)+11
+ word(6:6)=c(i:i)
+ n=n/27
+ i=mod(n,27)+11
+ word(5:5)=c(i:i)
+ n=n/27
+ i=mod(n,27)+11
+ word(4:4)=c(i:i)
+ n=n/27
+ i=mod(n,10)+1
+ word(3:3)=c(i:i)
+ n=n/10
+ i=mod(n,36)+1
+ word(2:2)=c(i:i)
+ n=n/36
+ i=n+1
+ word(1:1)=c(i:i)
+ do i=1,4
+ if(word(i:i).ne.' ') go to 10
+ enddo
+ go to 999
+10 word=word(i:)
+ go to 999
+
+20 if(n.ge.267796946) go to 999
+
+! We have a JT65v2 message
+ if((n.ge.262178563) .and. (n.le.264002071)) Then
+! CQ with prefix
+ iv2=1
+ n=n-262178563
+ i=mod(n,37)+1
+ psfx(4:4)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(3:3)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(2:2)=c(i:i)
+ n=n/37
+ i=n+1
+ psfx(1:1)=c(i:i)
+ endif
+
+ if((n.ge.264002072) .and. (n.le.265825580)) Then
+! QRZ with prefix
+ iv2=2
+ n=n-264002072
+ i=mod(n,37)+1
+ psfx(4:4)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(3:3)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(2:2)=c(i:i)
+ n=n/37
+ i=n+1
+ psfx(1:1)=c(i:i)
+ endif
+
+ if((n.ge.265825581) .and. (n.le.267649089)) Then
+! DE with prefix
+ iv2=3
+ n=n-265825581
+ i=mod(n,37)+1
+ psfx(4:4)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(3:3)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(2:2)=c(i:i)
+ n=n/37
+ i=n+1
+ psfx(1:1)=c(i:i)
+ endif
+
+ if((n.ge.267649090) .and. (n.le.267698374)) Then
+! CQ with suffix
+ iv2=4
+ n=n-267649090
+ i=mod(n,37)+1
+ psfx(3:3)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(2:2)=c(i:i)
+ n=n/37
+ i=n+1
+ psfx(1:1)=c(i:i)
+ endif
+
+ if((n.ge.267698375) .and. (n.le.267747659)) Then
+! QRZ with suffix
+ iv2=5
+ n=n-267698375
+ i=mod(n,37)+1
+ psfx(3:3)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(2:2)=c(i:i)
+ n=n/37
+ i=n+1
+ psfx(1:1)=c(i:i)
+ endif
+
+ if((n.ge.267747660) .and. (n.le.267796944)) Then
+! DE with suffix
+ iv2=6
+ n=n-267747660
+ i=mod(n,37)+1
+ psfx(3:3)=c(i:i)
+ n=n/37
+ i=mod(n,37)+1
+ psfx(2:2)=c(i:i)
+ n=n/37
+ i=n+1
+ psfx(1:1)=c(i:i)
+ endif
+
+ if(n.eq.267796945) Then
+! DE with no prefix or suffix
+ iv2=7
+ psfx = ' '
+ endif
+
+999 if(word(1:3).eq.'3D0') word='3DA0'//word(4:)
+
+ return
+end subroutine unpackcall
diff --git a/lib/unpackgrid.f90 b/lib/unpackgrid.f90
new file mode 100644
index 00000000..84dc7441
--- /dev/null
+++ b/lib/unpackgrid.f90
@@ -0,0 +1,45 @@
+subroutine unpackgrid(ng,grid)
+
+ parameter (NGBASE=180*180)
+ character grid*4,grid6*6
+
+ grid=' '
+ if(ng.ge.32400) go to 10
+ dlat=mod(ng,180)-90
+ dlong=(ng/180)*2 - 180 + 2
+ call deg2grid(dlong,dlat,grid6)
+ grid=grid6(:4)
+ if(grid(1:2).eq.'KA') then
+ read(grid(3:4),*) n
+ n=n-50
+ write(grid,1001) n
+1001 format(i3.2)
+ if(grid(1:1).eq.' ') grid(1:1)='+'
+ else if(grid(1:2).eq.'LA') then
+ read(grid(3:4),*) n
+ n=n-50
+ write(grid,1002) n
+1002 format('R',i3.2)
+ if(grid(2:2).eq.' ') grid(2:2)='+'
+ endif
+ go to 900
+
+10 n=ng-NGBASE-1
+ if(n.ge.1 .and.n.le.30) then
+ write(grid,1012) -n
+1012 format(i3.2)
+ else if(n.ge.31 .and.n.le.60) then
+ n=n-30
+ write(grid,1022) -n
+1022 format('R',i3.2)
+ else if(n.eq.61) then
+ grid='RO'
+ else if(n.eq.62) then
+ grid='RRR'
+ else if(n.eq.63) then
+ grid='73'
+ endif
+
+900 return
+end subroutine unpackgrid
+
diff --git a/lib/unpackmsg.f90 b/lib/unpackmsg.f90
new file mode 100644
index 00000000..aca7cfc6
--- /dev/null
+++ b/lib/unpackmsg.f90
@@ -0,0 +1,107 @@
+subroutine unpackmsg(dat,msg)
+
+ parameter (NBASE=37*36*10*27*27*27)
+ parameter (NGBASE=180*180)
+ integer dat(12)
+ character c1*12,c2*12,grid*4,msg*22,grid6*6,psfx*4,junk2*4
+ logical cqnnn
+
+ cqnnn=.false.
+ nc1=ishft(dat(1),22) + ishft(dat(2),16) + ishft(dat(3),10)+ &
+ ishft(dat(4),4) + iand(ishft(dat(5),-2),15)
+
+ nc2=ishft(iand(dat(5),3),26) + ishft(dat(6),20) + &
+ ishft(dat(7),14) + ishft(dat(8),8) + ishft(dat(9),2) + &
+ iand(ishft(dat(10),-4),3)
+
+ ng=ishft(iand(dat(10),15),12) + ishft(dat(11),6) + dat(12)
+
+ if(ng.ge.32768) then
+ call unpacktext(nc1,nc2,ng,msg)
+ go to 100
+ endif
+
+ call unpackcall(nc1,c1,iv2,psfx)
+ if(iv2.eq.0) then
+! This is an "original JT65" message
+ if(nc1.eq.NBASE+1) c1='CQ '
+ if(nc1.eq.NBASE+2) c1='QRZ '
+ nfreq=nc1-NBASE-3
+ if(nfreq.ge.0 .and. nfreq.le.999) then
+ write(c1,1002) nfreq
+1002 format('CQ ',i3.3)
+ cqnnn=.true.
+ endif
+ endif
+
+ call unpackcall(nc2,c2,junk1,junk2)
+ call unpackgrid(ng,grid)
+
+ if(iv2.gt.0) then
+! This is a JT65v2 message
+ do i=1,4
+ if(ichar(psfx(i:i)).eq.0) psfx(i:i)=' '
+ enddo
+
+ n1=len_trim(psfx)
+ n2=len_trim(c2)
+ if(iv2.eq.1) msg='CQ '//psfx(:n1)//'/'//c2(:n2)//' '//grid
+ if(iv2.eq.2) msg='QRZ '//psfx(:n1)//'/'//c2(:n2)//' '//grid
+ if(iv2.eq.3) msg='DE '//psfx(:n1)//'/'//c2(:n2)//' '//grid
+ if(iv2.eq.4) msg='CQ '//c2(:n2)//'/'//psfx(:n1)//' '//grid
+ if(iv2.eq.5) msg='QRZ '//c2(:n2)//'/'//psfx(:n1)//' '//grid
+ if(iv2.eq.6) msg='DE '//c2(:n2)//'/'//psfx(:n1)//' '//grid
+ if(iv2.eq.7) msg='DE '//c2(:n2)//' '//grid
+ go to 100
+ else
+
+ endif
+
+ grid6=grid//'ma'
+ call grid2k(grid6,k)
+ if(k.ge.1 .and. k.le.450) call getpfx2(k,c1)
+ if(k.ge.451 .and. k.le.900) call getpfx2(k,c2)
+
+ i=index(c1,char(0))
+ if(i.ge.3) c1=c1(1:i-1)//' '
+ i=index(c2,char(0))
+ if(i.ge.3) c2=c2(1:i-1)//' '
+
+ msg=' '
+ j=0
+ if(cqnnn) then
+ msg=c1//' '
+ j=7 !### ??? ###
+ go to 10
+ endif
+
+ do i=1,12
+ j=j+1
+ msg(j:j)=c1(i:i)
+ if(c1(i:i).eq.' ') go to 10
+ enddo
+ j=j+1
+ msg(j:j)=' '
+
+10 do i=1,12
+ if(j.le.21) j=j+1
+ msg(j:j)=c2(i:i)
+ if(c2(i:i).eq.' ') go to 20
+ enddo
+ if(j.le.21) j=j+1
+ msg(j:j)=' '
+
+20 if(k.eq.0) then
+ do i=1,4
+ if(j.le.21) j=j+1
+ msg(j:j)=grid(i:i)
+ enddo
+ if(j.le.21) j=j+1
+ msg(j:j)=' '
+ endif
+
+100 continue
+ if(msg(1:6).eq.'CQ9DX ') msg(3:3)=' '
+
+ return
+end subroutine unpackmsg
diff --git a/lib/unpacktext.f90 b/lib/unpacktext.f90
new file mode 100644
index 00000000..62451f97
--- /dev/null
+++ b/lib/unpacktext.f90
@@ -0,0 +1,35 @@
+subroutine unpacktext(nc1,nc2,nc3,msg)
+
+ character*22 msg
+ character*44 c
+ data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/
+
+ nc3=iand(nc3,32767) !Remove the "plain text" bit
+ if(iand(nc1,1).ne.0) nc3=nc3+32768
+ nc1=nc1/2
+ if(iand(nc2,1).ne.0) nc3=nc3+65536
+ nc2=nc2/2
+
+ do i=5,1,-1
+ j=mod(nc1,42)+1
+ msg(i:i)=c(j:j)
+ nc1=nc1/42
+ enddo
+
+ do i=10,6,-1
+ j=mod(nc2,42)+1
+ msg(i:i)=c(j:j)
+ nc2=nc2/42
+ enddo
+
+ do i=13,11,-1
+ j=mod(nc3,42)+1
+ msg(i:i)=c(j:j)
+ nc3=nc3/42
+ enddo
+ msg(14:22) = ' '
+
+ return
+end subroutine unpacktext
+
+
diff --git a/lib/vit216.c b/lib/vit216.c
new file mode 100644
index 00000000..38984d2f
--- /dev/null
+++ b/lib/vit216.c
@@ -0,0 +1,219 @@
+/* Viterbi decoder for arbitrary convolutional code
+ * viterbi27 and viterbi37 for the r=1/2 and r=1/3 K=7 codes are faster
+ * Copyright 1999 Phil Karn, KA9Q
+ * May be used under the terms of the GNU Public License
+ */
+
+/* Select code here */
+
+#define V216
+
+
+#ifdef V216
+#define K 16 /* Constraint length */
+#define N 2 /* Number of symbols per data bit */
+#define Polys Poly216 /* Select polynomials here */
+#endif
+
+/* Rate 1/2 codes */
+unsigned int Poly216[] = {0126723, 0152711}; /* k = 16 */
+
+#include <memory.h>
+#define NULL ((void *)0)
+
+#define LONGBITS 32
+#define LOGLONGBITS 5
+
+#undef max
+#define max(x,y) ((x) > (y) ? (x) : (y))
+#define D (1 << max(0,K-LOGLONGBITS-1))
+#define MAXNBITS 200 /* Maximum frame size (user bits) */
+
+extern unsigned char Partab[]; /* Parity lookup table */
+
+int Syms[1 << K];
+int VDInit = 0;
+
+int parity(int x)
+{
+ x ^= (x >> 16);
+ x ^= (x >> 8);
+ return Partab[x & 0xff];
+}
+
+// Wrapper for calling "encode" from Fortran:
+//void __stdcall ENCODE(
+void enc216_(
+unsigned char data[], // User data, 8 bits per byte
+int *nbits, // Number of user bits
+unsigned char symbols[], // Encoded one-bit symbols, 8 per byte
+int *nsymbols, // Number of symbols
+int *kk, // K
+int *nn) // N
+{
+ int nbytes;
+ nbytes=(*nbits+7)/8; // Always encode multiple of 8 information bits
+ enc216(symbols,data,nbytes,0,0); // Do the encoding
+ *nsymbols=(*nbits+K-1)*N; // Return number of encoded symbols
+ *kk=K;
+ *nn=N;
+}
+
+/* Convolutionally encode data into binary symbols */
+ enc216(unsigned char symbols[], unsigned char data[],
+ unsigned int nbytes, unsigned int startstate,
+ unsigned int endstate)
+{
+ int i,j,k,n=-1;
+ unsigned int encstate = startstate;
+
+ for(k=0; k<nbytes; k++) {
+ for(i=7;i>=0;i--){
+ encstate = (encstate + encstate) + ((data[k] >> i) & 1);
+ for(j=0;j<N;j++) {
+ n=n+1;
+ symbols[n] = parity(encstate & Polys[j]);
+ }
+ }
+ }
+ // Flush out with zero tail. (No need, if tail-biting code.)
+ for(i=0; i<K-1;i++){
+ encstate = (encstate << 1) | ((endstate >> i) & 1);
+ for(j=0;j<N;j++) {
+ n=n+1;
+ symbols[n] = parity(encstate & Polys[j]);
+ }
+ }
+ return 0;
+}
+
+// Wrapper for calling "viterbi" from Fortran:
+//void __stdcall VITERBI(
+void vit216_(
+unsigned char symbols[], /* Raw deinterleaved input symbols */
+unsigned int *Nbits, /* Number of decoded information bits */
+int mettab[2][256], /* Metric table, [sent sym][rx symbol] */
+unsigned char ddec[], /* Decoded output data */
+long *Metric /* Final path metric (bigger is better) */
+){
+ long metric;
+ vit216(&metric,ddec,symbols,*Nbits,mettab,0,0);
+ *Metric=metric;
+}
+
+/* Viterbi decoder */
+int vit216(
+long *metric, /* Final path metric (returned value) */
+unsigned char *data, /* Decoded output data */
+unsigned char *symbols, /* Raw deinterleaved input symbols */
+unsigned int nbits, /* Number of output bits */
+int mettab[2][256], /* Metric table, [sent sym][rx symbol] */
+unsigned int startstate, /* Encoder starting state */
+unsigned int endstate /* Encoder ending state */
+){
+ int bitcnt = -(K-1);
+ long m0,m1;
+ int i,j,sym,ipp;
+ int mets[1 << N];
+ unsigned long paths[(MAXNBITS+K-1)*D];
+ unsigned long *pp,mask;
+ long cmetric[1 << (K-1)],nmetric[1 << (K-1)];
+
+ memset(paths,0,sizeof(paths));
+
+ // Initialize on first time through:
+ if(!VDInit){
+ for(i=0;i<(1<<K);i++){
+ sym = 0;
+ for(j=0;j<N;j++)
+ sym = (sym << 1) + parity(i & Polys[j]);
+ Syms[i] = sym;
+ }
+ VDInit++;
+ }
+
+ // Keep only lower K-1 bits of specified startstate and endstate
+ startstate &= ~((1<<(K-1)) - 1);
+ endstate &= ~((1<<(K-1)) - 1);
+
+ /* Initialize starting metrics */
+ for(i=0;i< 1<<(K-1);i++)
+ cmetric[i] = -999999;
+ cmetric[startstate] = 0;
+
+ pp = paths;
+ ipp=0;
+ for(;;){ /* For each data bit */
+ /* Read input symbols and compute branch metrics */
+ for(i=0;i< 1<<N;i++){
+ mets[i] = 0;
+ for(j=0;j<N;j++){
+ mets[i] += mettab[(i >> (N-j-1)) & 1][symbols[j]];
+ }
+ }
+ symbols += N;
+ /* Run the add-compare-select operations */
+ mask = 1;
+ for(i=0;i< 1 << (K-1);i+=2){
+ int b1,b2;
+
+ b1 = mets[Syms[i]];
+ nmetric[i] = m0 = cmetric[i/2] + b1;
+ b2 = mets[Syms[i+1]];
+ b1 -= b2;
+ m1 = cmetric[(i/2) + (1<<(K-2))] + b2;
+
+ if(m1 > m0){
+ nmetric[i] = m1;
+ *pp |= mask;
+ }
+
+ m0 -= b1;
+ nmetric[i+1] = m0;
+ m1 += b1;
+
+ if(m1 > m0){
+ nmetric[i+1] = m1;
+ *pp |= mask << 1;
+ }
+
+ mask <<= 2;
+ if(mask == 0){
+ mask = 1;
+ pp++;
+ ipp++;
+ }
+ }
+ if(mask != 1){
+ pp++;
+ ipp++;
+ }
+ if(++bitcnt == nbits){
+ *metric = nmetric[endstate];
+ break;
+ }
+ memcpy(cmetric,nmetric,sizeof(cmetric));
+ }
+
+ /* Chain back from terminal state to produce decoded data */
+ if(data == NULL)
+ return 0;/* Discard output */
+ memset(data,0,(nbits+7)/8); /* round up in case nbits % 8 != 0 */
+
+ for(i=nbits-1;i >= 0;i--){
+ // int a0,a1;
+ pp -= D;
+ ipp -= D;
+ m0=endstate >> LOGLONGBITS;
+ m1=1L << (endstate & (LONGBITS-1));
+ if(pp[m0] & m1) {
+ // a0=nmetric[endstate];
+ endstate |= (1 << (K-1));
+ // a1=nmetric[endstate];
+ data[i>>3] |= 0x80 >> (i&7);
+ // printf("B %d %d %d %d\n",*metric,i,a0,a1);
+ }
+ endstate >>= 1;
+ }
+ return 0;
+}
diff --git a/lib/wrapkarn.c b/lib/wrapkarn.c
new file mode 100644
index 00000000..1b1a6311
--- /dev/null
+++ b/lib/wrapkarn.c
@@ -0,0 +1,70 @@
+#include <math.h>
+#include <stdio.h>
+#include <float.h>
+#include <limits.h>
+#include <stdlib.h>
+#include "rs.h"
+
+static void *rs;
+static int first=1;
+
+void rs_encode_(int *dgen, int *sent)
+// Encode JT65 data dgen[12], producing sent[63].
+{
+ int dat1[12];
+ int b[51];
+ int i;
+
+ if(first) {
+ // Initialize the JT65 codec
+ rs=init_rs_int(6,0x43,3,1,51,0);
+ first=0;
+ }
+
+ // Reverse data order for the Karn codec.
+ for(i=0; i<12; i++) {
+ dat1[i]=dgen[11-i];
+ }
+ // Compute the parity symbols
+ encode_rs_int(rs,dat1,b);
+
+ // Move parity symbols and data into sent[] array, in reverse order.
+ for (i = 0; i < 51; i++) sent[50-i] = b[i];
+ for (i = 0; i < 12; i++) sent[i+51] = dat1[11-i];
+}
+
+void rs_decode_(int *recd0, int *era0, int *numera0, int *decoded, int *nerr)
+// Decode JT65 received data recd0[63], producing decoded[12].
+// Erasures are indicated in era0[numera]. The number of corrected
+// errors is *nerr. If the data are uncorrectable, *nerr=-1 is returned.
+{
+ int numera;
+ int i;
+ int era_pos[50];
+ int recd[63];
+
+ if(first) {
+ rs=init_rs_int(6,0x43,3,1,51,0);
+ first=0;
+ }
+
+ numera=*numera0;
+ for(i=0; i<12; i++) recd[i]=recd0[62-i];
+ for(i=0; i<51; i++) recd[12+i]=recd0[50-i];
+ if(numera)
+ for(i=0; i<numera; i++) era_pos[i]=era0[i];
+ *nerr=decode_rs_int(rs,recd,era_pos,numera);
+ for(i=0; i<12; i++) decoded[i]=recd[11-i];
+}
+
+
+void rs_encode__(int *dgen, int *sent)
+{
+ rs_encode_(dgen, sent);
+}
+
+void rs_decode__(int *recd0, int *era0, int *numera0, int *decoded, int *nerr)
+{
+ rs_decode_(recd0, era0, numera0, decoded, nerr);
+}
+
diff --git a/lib/wsjt24.f90 b/lib/wsjt24.f90
new file mode 100644
index 00000000..574f1dd9
--- /dev/null
+++ b/lib/wsjt24.f90
@@ -0,0 +1,181 @@
+subroutine wsjt24(dat,npts,cfile6,NClearAve,MinSigdB, &
+ DFTolerance,NFreeze,mode,mode4,Nseg,MouseDF,NAgain, &
+ idf,lumsg,lcum,nspecial,ndf,NSyncOK,ccfblue,ccfred,ndiag)
+
+! Orchestrates the process of decoding JT4 messages, using data that
+! have been 2x downsampled.
+! No message averaging and no deep search, at present.
+
+ parameter (MAXAVE=120)
+ real dat(npts) !Raw data
+ real*4 ccfblue(-5:540) !CCF in time
+ real*4 ccfred(-224:224) !CCF in frequency
+ integer DFTolerance
+ logical first
+ logical lcum
+ character decoded*22,cfile6*6,special*5,cooo*3
+ character*22 avemsg1,avemsg2,deepmsg
+ character*77 line,ave1,ave2
+ character*1 csync,c1
+ character*12 mycall
+ character*12 hiscall
+ character*6 hisgrid
+ character submode*1
+ real*4 ccfbluesum(-5:540),ccfredsum(-224:224)
+ common/ave/ppsave(207,7,MAXAVE),nflag(MAXAVE),nsave,iseg(MAXAVE)
+ data first/.true./,ns10/0/,ns20/0/
+ save
+
+ if(first) then
+ nsave=0
+ first=.false.
+ ave1=' '
+ ave2=' '
+ ccfblue=0.
+ ccfred=0.
+ if(nspecial.eq.999) go to 900 !Silence compiler warning
+ endif
+
+ ndepth=3 !###
+ naggressive=0
+ if(ndepth.ge.2) naggressive=1
+ nq1=3
+ nq2=6
+ if(naggressive.eq.1) nq1=1
+
+ if(NClearAve.ne.0) then
+ nsave=0 !Clear the averaging accumulators
+ ns10=0
+ ns20=0
+ ave1=' '
+ ave2=' '
+ endif
+ if(MinSigdB.eq.99 .or. MinSigdB.eq.-99) then
+ ns10=0 !For Include/Exclude ?
+ ns20=0
+ endif
+
+! Attempt to synchronize: look for sync pattern, get DF and DT.
+ call sync24(dat,npts,DFTolerance,NFreeze,MouseDF,mode, &
+ mode4,dtx,dfx,snrx,snrsync,ccfblue,ccfred,flip,width)
+
+ csync=' '
+ decoded=' '
+ deepmsg=' '
+ special=' '
+ cooo=' '
+ ncount=-1 !Flag for RS decode of current record
+ ncount1=-1 !Flag for RS Decode of ave1
+ ncount2=-1 !Flag for RS Decode of ave2
+ NSyncOK=0
+ nqual1=0
+ nqual2=0
+
+ if(nsave.lt.MAXAVE .and. (NAgain.eq.0 .or. NClearAve.eq.1)) nsave=nsave+1
+ if(nsave.le.0) go to 900 !Prevent bounds error
+
+ nflag(nsave)=0 !Clear the "good sync" flag
+ iseg(nsave)=Nseg !Set the RX segment to 1 or 2
+ nsync=nint(snrsync-3.0)
+ nsnr=nint(snrx)
+ if(nsnr.lt.-30 .or. nsync.lt.0) nsync=0
+ nsnrlim=-33
+ if(nsync.lt.MinSigdB .or. nsnr.lt.nsnrlim) go to 200
+
+! If we get here, we have achieved sync!
+ NSyncOK=1
+ nflag(nsave)=1 !Mark this RX file as good
+ csync='*'
+ if(flip.lt.0.0) then
+ csync='#'
+ cooo='O ?'
+ endif
+
+ call decode24(dat,npts,dtx,dfx,flip,mode,mode4,decoded, &
+ ncount,deepmsg,qual,submode)
+
+200 kvqual=0
+ if(ncount.ge.0) kvqual=1
+ nqual=qual
+ if(ndiag.eq.0 .and. nqual.gt.10) nqual=10
+ if(nqual.ge.nq1 .and.kvqual.eq.0) decoded=deepmsg
+
+ ndf=nint(dfx)
+ if(flip.lt.0.0 .and. (kvqual.eq.1 .or. nqual.ge.nq2)) cooo='OOO'
+ if(kvqual.eq.0.and.nqual.ge.nq1.and.nqual.lt.nq2) cooo(2:3)=' ?'
+ if(decoded.eq.' ') cooo=' '
+ do i=1,22
+ c1=decoded(i:i)
+ if(c1.ge.'a' .and. c1.le.'z') decoded(i:i)=char(ichar(c1)-32)
+ enddo
+ jdf=ndf+idf
+
+! call cs_lock('wsjt24')
+ write(line,1010) cfile6,nsync,nsnr,dtx-1.0,jdf,nint(width), &
+ csync,special,decoded(1:19),cooo,kvqual,nqual,submode
+1010 format(a6,i3,i5,f5.1,i5,i3,1x,a1,1x,a5,a19,1x,a3,i3,i5,1x,a1)
+
+! Blank all end-of-line stuff if no decode
+ if(line(31:40).eq.' ') line=line(:30)
+
+ if(lcum) write(21,1011) line
+
+! Write decoded msg unless this is an "Exclude" request:
+ if(MinSigdB.lt.99) write(*,1011) line
+1011 format(a77)
+
+ if(nsave.ge.1) call avemsg4(1,mode4,ndepth, &
+ avemsg1,nused1,nq1,nq2,neme,mycall,hiscall,hisgrid,qual1, &
+ ns1,ncount1)
+ if(nsave.ge.1) call avemsg4(2,mode4,ndepth, &
+ avemsg2,nused2,nq1,nq2,neme,mycall,hiscall,hisgrid,qual2, &
+ ns2,ncount2)
+ nqual1=qual1
+ nqual2=qual2
+ if(ndiag.eq.0 .and. nqual1.gt.10) nqual1=10
+ if(ndiag.eq.0 .and. nqual2.gt.10) nqual2=10
+ nc1=0
+ nc2=0
+ if(ncount1.ge.0) nc1=1
+ if(ncount2.ge.0) nc2=1
+
+! Write the average line
+ if(ns1.ge.1) then
+ if(ns1.lt.10) write(ave1,1021) cfile6,1,nused1,ns1,avemsg1,nc1,nqual1
+1021 format(a6,i3,i4,'/',i1,20x,a19,i7,i5)
+ if(ns1.ge.10 .and. nsave.le.99) write(ave1,1022) cfile6, &
+ 1,nused1,ns1,avemsg1,nc1,nqual1
+1022 format(a6,i3,i4,'/',i2,19x,a19,i7,i5)
+ if(ns1.ge.100) write(ave1,1023) cfile6,1,nused1,ns1, &
+ avemsg1,nc1,nqual1
+1023 format(a6,i3,i4,'/',i3,18x,a19,i7,i5)
+ if(lcum .and. (avemsg1.ne.' ')) &
+ write(21,1011) ave1
+ ns10=ns1
+ endif
+
+! If Monitor segment #2 is available, write that line also
+ if(ns2.ge.1) then
+ if(ns2.lt.10) write(ave2,1021) cfile6,2,nused2,ns2,avemsg2,nc2,nqual2
+ if(ns2.ge.10 .and. nsave.le.99) write(ave2,1022) cfile6, &
+ 2,nused2,ns2,avemsg2,nc2,nqual2
+ if(ns2.ge.100) write(ave2,1023) cfile6,2,nused2,ns2,avemsg2,nc2,nqual2
+ if(lcum .and. (avemsg2.ne.' ')) &
+ write(21,1011) ave2
+ ns20=ns2
+ endif
+
+ if(ave1(31:40).eq.' ') ave1=ave1(:30)
+ if(ave2(31:40).eq.' ') ave2=ave2(:30)
+ write(12,1011) ave1
+ write(12,1011) ave2
+ call flush(12)
+! call cs_unlock
+
+900 continue
+
+ ccfbluesum=ccfbluesum + ccfblue
+ ccfredsum=ccfredsum + ccfred
+
+ return
+end subroutine wsjt24
diff --git a/lib/wsjt24d.f90 b/lib/wsjt24d.f90
new file mode 100644
index 00000000..005e809f
--- /dev/null
+++ b/lib/wsjt24d.f90
@@ -0,0 +1,43 @@
+program wsjt24d
+
+ real*4 dat(60*11025/2)
+ character*6 cfile6
+ character*12 arg
+ real ccfblue(-5:540) !X-cor function in JT65 mode (blue line)
+ real ccfred(450) !Average spectrum of the whole file
+ integer dftolerance
+
+ nargs=iargc()
+ if(nargs.ne.2) then
+ print*,'Usage: wspr24d ifile1 ifile2'
+ go to 999
+ endif
+ call getarg(1,arg)
+ read(arg,*) ifile1
+ call getarg(2,arg)
+ read(arg,*) ifile2
+
+ open(23,file='CALL3.TXT',status='old')
+ open(50,file='vk7mo.dat',form='unformatted',status='old')
+
+ do ifile=1,ifile2
+ read(50,end=999) jz,cfile6,NClearAve,MinSigdB,DFTolerance,NFreeze, &
+ mode,mode4,Nseg,MouseDF2,NAgain,idf,lumsg,lcum,nspecial,ndf, &
+ NSyncOK,dat(1:jz)
+ if(ifile.lt.ifile1) cycle
+
+! write(*,3000) ifile,cfile6,jz,mode,mode4,idf
+!3000 format(i3,2x,a6,i10,3i5)
+
+ dftolerance=100
+ nfreeze=1
+ neme=0
+
+! call wsjt24(dat(4097),jz-4096,cfile6,NClearAve,MinSigdB,DFTolerance, &
+ call wsjt24(dat,jz,cfile6,NClearAve,MinSigdB,DFTolerance, &
+ NFreeze,mode,mode4,Nseg,MouseDF2,NAgain,idf,lumsg,lcum,nspecial, &
+ ndf,NSyncOK,ccfblue,ccfred,ndiag)
+ if(ifile.ge.ifile2) exit
+ enddo
+
+999 end program wsjt24d
diff --git a/lib/xcor24.f90 b/lib/xcor24.f90
new file mode 100644
index 00000000..b76093b2
--- /dev/null
+++ b/lib/xcor24.f90
@@ -0,0 +1,94 @@
+subroutine xcor24(s2,ipk,nsteps,nsym,lag1,lag2,mode4,ccf,ccf0,lagpk,flip)
+
+! Computes ccf of a row of s2 and the pseudo-random array pr2. Returns
+! peak of the CCF and the lag at which peak occurs. For JT65, the
+! CCF peak may be either positive or negative, with negative implying
+! the "OOO" message.
+
+ parameter (NHMAX=1260) !Max length of power spectra
+ parameter (NSMAX=525) !Max number of half-symbol steps
+ real s2(NHMAX,NSMAX) !2d spectrum, stepped by half-symbols
+ real a(NSMAX)
+ real ccf(-5:540)
+ integer npr2(207)
+ real pr2(207)
+ logical first
+ data lagmin/0/ !Silence g77 warning
+ data first/.true./
+ data npr2/ &
+ 0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0, &
+ 0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,0,0, &
+ 1,0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,1,0,0,0,1,1,1,1,0,1,1,0,0,1, &
+ 0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1, &
+ 0,1,1,1,0,0,1,0,1,1,0,1,1,1,1,0,0,0,0,1,1,0,1,1,0,0,0,1,1,1, &
+ 0,1,1,1,0,1,1,1,0,0,1,0,0,0,1,1,0,1,1,0,0,1,0,0,0,1,1,1,1,1, &
+ 1,0,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,1,0,1/
+ save
+
+ if(first) then
+ do i=1,207
+ pr2(i)=2*npr2(i)-1
+ enddo
+ first=.false.
+ endif
+
+ do j=1,nsteps
+ n=2*mode4
+ if(mode4.eq.1) then
+ a(j)=max(s2(ipk+n,j),s2(ipk+3*n,j)) - max(s2(ipk ,j),s2(ipk+2*n,j))
+ else
+ kz=mode4/2
+ ss0=0.
+ ss1=0.
+ ss2=0.
+ ss3=0.
+ wsum=0.
+ do k=-kz+1,kz-1
+ w=float(kz-iabs(k))/mode4
+ wsum=wsum+w
+ if(ipk+k.lt.1 .or. ipk+3*n+k.gt.1260) then
+ print*,'xcor24:',ipk,n,k
+ else
+ ss0=ss0 + w*s2(ipk +k,j)
+ ss1=ss1 + w*s2(ipk+ n+k,j)
+ ss2=ss2 + w*s2(ipk+2*n+k,j)
+ ss3=ss3 + w*s2(ipk+3*n+k,j)
+ endif
+ enddo
+ a(j)=(max(ss1,ss3) - max(ss0,ss2))/sqrt(wsum)
+ endif
+ enddo
+
+ ccfmax=0.
+ ccfmin=0.
+ do lag=lag1,lag2
+ x=0.
+ do i=1,nsym
+ j=2*i-1+lag
+ if(j.ge.1 .and. j.le.nsteps) x=x+a(j)*pr2(i)
+ enddo
+ ccf(lag)=2*x !The 2 is for plotting scale
+ if(ccf(lag).gt.ccfmax) then
+ ccfmax=ccf(lag)
+ lagpk=lag
+ endif
+
+ if(ccf(lag).lt.ccfmin) then
+ ccfmin=ccf(lag)
+ lagmin=lag
+ endif
+ enddo
+
+ ccf0=ccfmax
+ flip=1.0
+ if(-ccfmin.gt.ccfmax) then
+ do lag=lag1,lag2
+ ccf(lag)=-ccf(lag)
+ enddo
+ lagpk=lagmin
+ ccf0=-ccfmin
+ flip=-1.0
+ endif
+
+ return
+end subroutine xcor24
diff --git a/lib/zplot9.f90 b/lib/zplot9.f90
new file mode 100644
index 00000000..6c56c9fc
--- /dev/null
+++ b/lib/zplot9.f90
@@ -0,0 +1,31 @@
+subroutine zplot9(s,freq,drift)
+
+ real s(0:8,85)
+ character*1 line(85),mark(0:6)
+ data mark/' ',' ','.','-','+','X','$'/
+ include 'jt9sync.f90'
+
+ write(32,1000) freq,drift
+1000 format('Freq:',f7.1,' Drift:',f5.1,' ',60('-'))
+ do j=8,0,-1
+ do i=1,85
+ n=(s(j,i))
+ if(n.lt.0) n=0
+ if(n.gt.6) n=6
+ line(i)=mark(n)
+ enddo
+ write(32,1010) j,line
+1010 format(i1,1x,85a1)
+ enddo
+ do i=1,85
+ line(i)=' '
+ if(isync(i).eq.1) line(i)='@'
+ enddo
+ write(32,1015)
+1015 format(87('-'))
+ write(32,1020) line
+1020 format(2x,85a1)
+ call flush(32)
+
+ return
+end subroutine zplot9