diff options
Diffstat (limited to 'map65/libm65')
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/CMakeLists.txt | 296 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/Makefile | 260 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/Makefile.0 | 228 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/Makefile.MinGW | 210 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/Makefile.jtsdk | 258 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/Makefile.linux | 192 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/afc65b.f90 | 140 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/astro.f90 | 210 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/astro0.f90 | 162 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/astrosub.f90 | 52 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/averms.f90 | 40 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/badmsg.f90 | 92 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ccf2.f90 | 90 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ccf65.f90 | 256 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/cgen65.f90 | 198 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/chkhist.f90 | 46 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/chkmsg.f90 | 62 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/coord.f90 | 80 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/cutil.c | 186 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/dcoord.f90 | 80 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/decode0.f90 | 142 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/decode1a.f90 | 290 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/decode65b.f90 | 96 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/decode_rs.c | 536 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/deep65.f90 | 340 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/deg2grid.f90 | 60 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/demod64a.f90 | 154 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/display.f90 | 360 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/dot.f90 | 22 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/dpol.f90 | 82 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/encode65.f90 | 28 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/encode_rs.c | 94 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/extract.f90 | 272 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/f77_wisdom.f | 90 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/fchisq.f90 | 154 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/fchisq0.f90 | 46 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/fftw3.f | 128 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/fftw3.f90 | 128 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/fil6521.f90 | 88 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/filbig.f90 | 264 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/fmtmsg.f90 | 42 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/four2a.f90 | 230 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ftninit.f90 | 62 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ftnquit.f90 | 16 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ftrsd2.c | 426 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/gen65.f90 | 198 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/gen_q65_cwave.f90 | 104 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/gen_q65_wave.f90 | 108 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/geocentric.f90 | 34 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/getdphi.f90 | 36 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/getpfx1.f90 | 192 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/getpfx2.f90 | 48 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/gran.c | 56 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/graycode.f90 | 20 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/graycode65.f90 | 18 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/grid2deg.f90 | 76 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/grid2k.f90 | 24 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/igray.c | 44 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/indexx.f90 | 182 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/init_rs.c | 240 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/int.h | 108 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/interleave63.f90 | 50 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ipcomm.cpp | 68 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/iqcal.f90 | 60 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/iqfix.f90 | 56 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/jt65code.f90 | 94 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/k2grid.f90 | 24 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/lorentzian.f90 | 204 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/m65.f90 | 390 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/m65a.f90 | 214 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/map65a.f90 | 1058 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/mapsim.f90 | 481 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/moon2.f90 | 326 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/moondop.f90 | 144 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/msgs.txt | 120 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/nchar.f90 | 46 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/njunk.f90 | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/noisegen.f90 | 26 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/packjt.f90 | 1992 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/pfx.f90 | 100 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/pfxdump.f90 | 26 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/polfit.f90 | 174 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ptt.c | 86 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ptt_unix.c | 810 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/q65b.f90 | 410 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/q65b_for_Linux.f90 | 410 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/recvpkt.f90 | 146 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/rfile3a.f90 | 28 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/rs.h | 70 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/rs2.h | 32 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/s3avg.f90 | 120 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/sec_midn.f90 | 22 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/set.f90 | 62 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/setup65.f90 | 192 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/shell.f90 | 54 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/sleep.h | 64 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/sleep_msec.f90 | 8 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/smo.f90 | 38 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/sort.f90 | 12 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/ssort.f | 574 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/sun.f90 | 176 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/symspec.f90 | 448 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/synctest.f90 | 114 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/synctst.f90 | 168 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/synctst2.f90 | 182 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/tastro.f90 | 70 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/timeval.h | 152 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/timf2.f90 | 430 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/tm2.f90 | 28 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/tmoonsub.c | 1028 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/toxyz.f90 | 50 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/trimlist.f90 | 56 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/twkfreq.f90 | 52 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/twkfreq_xy.f90 | 58 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/txpol.f90 | 66 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/usleep.c | 14 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/wavhdr.f90 | 220 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/wideband_sync.f90 | 562 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/wrapkarn.c | 140 | ||||
| -rw-r--r--[-rwxr-xr-x] | map65/libm65/zplot.f90 | 68 |
120 files changed, 10830 insertions, 10821 deletions
diff --git a/map65/libm65/CMakeLists.txt b/map65/libm65/CMakeLists.txt index 8c57df5d..fe5ee170 100755..100644 --- a/map65/libm65/CMakeLists.txt +++ b/map65/libm65/CMakeLists.txt @@ -1,148 +1,148 @@ -set (libm65_FSRCS
-# Modules come first:
- wideband_sync.f90
-
-# Non-module Fortran routines:
- afc65b.f90
- astro.f90
- astro0.f90
- astrosub.f90
- averms.f90
- badmsg.f90
- ccf2.f90
- ccf65.f90
- cgen65.f90
- chkhist.f90
- chkmsg.f90
- coord.f90
- dcoord.f90
- decode0.f90
- decode1a.f90
- decode65b.f90
- deep65.f90
- deg2grid.f90
- demod64a.f90
- display.f90
- dot.f90
- dpol.f90
- encode65.f90
- extract.f90
- fchisq.f90
- fchisq0.f90
- fil6521.f90
- filbig.f90
- fmtmsg.f90
- four2a.f90
- ftninit.f90
- ftnquit.f90
- q65b.f90
- gen65.f90
- gen_q65_cwave.f90
- gen_q65_wave.f90
- geocentric.f90
- getdphi.f90
- getpfx1.f90
- getpfx2.f90
- graycode.f90
- graycode65.f90
- grid2deg.f90
- grid2k.f90
- indexx.f90
- interleave63.f90
- iqcal.f90
- iqfix.f90
- jt65code.f90
- k2grid.f90
- lorentzian.f90
- map65a.f90
- moon2.f90
- moondop.f90
- nchar.f90
- noisegen.f90
- packjt.f90
- pfxdump.f90
- polfit.f90
- recvpkt.f90
- rfile3a.f90
- s3avg.f90
- sec_midn.f90
- set.f90
- setup65.f90
- shell.f90
- sleep_msec.f90
- smo.f90
- sun.f90
- symspec.f90
-# timer.f90
- timf2.f90
- tm2.f90
- toxyz.f90
- trimlist.f90
- twkfreq.f90
- twkfreq_xy.f90
- txpol.f90
- wavhdr.f90
-
- f77_wisdom.f
- )
-
-set (libm65_ka9q_CSRCS
- decode_rs.c
- encode_rs.c
- init_rs.c
-)
-set_source_files_properties (${libm65_ka9q_CSRCS} PROPERTIES COMPILE_FLAGS -Wno-sign-compare)
-
-set (libm65_CSRCS
- ${libm65_ka9q_CSRCS}
- ftrsd2.c
-# gran.c
- igray.c
- tmoonsub.c
- usleep.c
- wrapkarn.c
-)
-
-if (WIN32)
- set (libm65_CSRCS ${libm65_CSRCS} ptt.c)
-else ()
- set (libm65_CSRCS ${libm65_CSRCS} ptt_unix.c)
-endif ()
-
-set (libm65_CXXSRCS
- ipcomm.cpp
- )
-
-add_definitions (-DBIGSYM=1)
-set_source_files_properties (sec_midn.f90 PROPERTIES COMPILE_FLAGS -fno-second-underscore)
-
-set (libm65_C_and_CXXSRCS
- ${libm65_CSRCS}
- ${libm65_CXXSRCS}
- )
-set_property (SOURCE ${libm65_C_and_CXXSRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -include wsjtx_config.h")
-set_property (SOURCE ${libm65_C_and_CXXSRCS} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_BINARY_DIR}/wsjtx_config.h)
-
-
-#
-# build our targets
-#
-add_library (m65impl STATIC ${libm65_FSRCS} ${libm65_CSRCS} ${libm65_CXXSRCS})
-target_link_libraries (m65impl wsjt_fort wsjt_cxx Qt5::Core)
-
-add_executable (m65 m65.f90 m65a.f90)
-target_link_libraries (m65 m65impl ${FFTW3_LIBRARIES})
-
-add_executable (mapsim mapsim.f90)
-target_link_libraries (mapsim m65impl ${FFTW3_LIBRARIES})
-
-#add_executable (synctest synctest.f90)
-#target_link_libraries (synctest m65impl ${FFTW3_LIBRARIES})
-
-if (WIN32)
- install (
- TARGETS m65 mapsim
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
- BUNDLE DESTINATION . COMPONENT runtime
- )
-endif ()
+set (libm65_FSRCS +# Modules come first: + wideband_sync.f90 + +# Non-module Fortran routines: + afc65b.f90 + astro.f90 + astro0.f90 + astrosub.f90 + averms.f90 + badmsg.f90 + ccf2.f90 + ccf65.f90 + cgen65.f90 + chkhist.f90 + chkmsg.f90 + coord.f90 + dcoord.f90 + decode0.f90 + decode1a.f90 + decode65b.f90 + deep65.f90 + deg2grid.f90 + demod64a.f90 + display.f90 + dot.f90 + dpol.f90 + encode65.f90 + extract.f90 + fchisq.f90 + fchisq0.f90 + fil6521.f90 + filbig.f90 + fmtmsg.f90 + four2a.f90 + ftninit.f90 + ftnquit.f90 + q65b.f90 + gen65.f90 + gen_q65_cwave.f90 + gen_q65_wave.f90 + geocentric.f90 + getdphi.f90 + getpfx1.f90 + getpfx2.f90 + graycode.f90 + graycode65.f90 + grid2deg.f90 + grid2k.f90 + indexx.f90 + interleave63.f90 + iqcal.f90 + iqfix.f90 + jt65code.f90 + k2grid.f90 + lorentzian.f90 + map65a.f90 + moon2.f90 + moondop.f90 + nchar.f90 + noisegen.f90 + packjt.f90 + pfxdump.f90 + polfit.f90 + recvpkt.f90 + rfile3a.f90 + s3avg.f90 + sec_midn.f90 + set.f90 + setup65.f90 + shell.f90 + sleep_msec.f90 + smo.f90 + sun.f90 + symspec.f90 +# timer.f90 + timf2.f90 + tm2.f90 + toxyz.f90 + trimlist.f90 + twkfreq.f90 + twkfreq_xy.f90 + txpol.f90 + wavhdr.f90 + + f77_wisdom.f + ) + +set (libm65_ka9q_CSRCS + decode_rs.c + encode_rs.c + init_rs.c +) +set_source_files_properties (${libm65_ka9q_CSRCS} PROPERTIES COMPILE_FLAGS -Wno-sign-compare) + +set (libm65_CSRCS + ${libm65_ka9q_CSRCS} + ftrsd2.c +# gran.c + igray.c + tmoonsub.c + usleep.c + wrapkarn.c +) + +if (WIN32) + set (libm65_CSRCS ${libm65_CSRCS} ptt.c) +else () + set (libm65_CSRCS ${libm65_CSRCS} ptt_unix.c) +endif () + +set (libm65_CXXSRCS + ipcomm.cpp + ) + +add_definitions (-DBIGSYM=1) +set_source_files_properties (sec_midn.f90 PROPERTIES COMPILE_FLAGS -fno-second-underscore) + +set (libm65_C_and_CXXSRCS + ${libm65_CSRCS} + ${libm65_CXXSRCS} + ) +set_property (SOURCE ${libm65_C_and_CXXSRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -include wsjtx_config.h") +set_property (SOURCE ${libm65_C_and_CXXSRCS} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_BINARY_DIR}/wsjtx_config.h) + + +# +# build our targets +# +add_library (m65impl STATIC ${libm65_FSRCS} ${libm65_CSRCS} ${libm65_CXXSRCS}) +target_link_libraries (m65impl wsjt_fort wsjt_cxx Qt5::Core) + +add_executable (m65 m65.f90 m65a.f90) +target_link_libraries (m65 m65impl ${FFTW3_LIBRARIES}) + +add_executable (mapsim mapsim.f90) +target_link_libraries (mapsim m65impl ${FFTW3_LIBRARIES}) + +#add_executable (synctest synctest.f90) +#target_link_libraries (synctest m65impl ${FFTW3_LIBRARIES}) + +if (WIN32) + install ( + TARGETS m65 mapsim + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime + BUNDLE DESTINATION . COMPONENT runtime + ) +endif () diff --git a/map65/libm65/Makefile b/map65/libm65/Makefile index 3ed5b9e9..810f09e1 100755..100644 --- a/map65/libm65/Makefile +++ b/map65/libm65/Makefile @@ -1,130 +1,130 @@ -# Makefile for MinGW on Windows
-CC = c:/JTSDK/Qt55/Tools/mingw492_32/bin/gcc
-FC = c:/JTSDK/Qt55/Tools/mingw492_32/bin/gfortran
-CXX = c:/JTSDK/Qt55/Tools/mingw492_32/bin/g++
-
-FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion -Wno-precision-loss \
- -fno-second-underscore -fbacktrace \
- -ffpe-summary=none
-# -ffpe-trap=invalid,zero,overflow,underflow,denormal
-CFLAGS = -I. -fbounds-check
-
-# 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: packjt.o wavhdr.o libm65.a m65.exe mapsim.exe libastro.a
-
-OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \
- decode1a.o sort.o filbig.o fil6521.o afc65b.o \
- twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \
- extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \
- interleave63.o encode65.o igray.o set.o shell.o qra64_subs.o \
- grid2k.o getpfx2.o q65b.o qra64c.o twkfreq_xy.o qra64zap.o \
- deg2grid.o getpfx1.o k2grid.o ftrsd2.o graycode65.o \
- wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \
- four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o sync64.o spec64.o \
- astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \
- geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \
- gen65.o chkmsg.o ptt.o astrosub.o astro0.o recvpkt.o symspec.o \
- iqcal.o iqfix.o timf2.o s3avg.o packjt.o badmsg.o fmtmsg.o \
- qracodes.o qra64.o smo.o averms.o lorentzian.o npfwht.o pdmath.o \
- qra13_64_64_irr_e.o fchisq0.o gen_q65_wave.o wavhdr.o
-
-packjt.o: packjt.f90
- $(FC) -c packjt.f90
-
-libm65.a: $(OBJS1)
- ar cr libm65.a $(OBJS1)
- ranlib libm65.a
-
-qra64_subs.o: ./qra64/qra64_subs.c
- gcc -c -O2 -o qra64_subs.o ./qra64/qra64_subs.c
-
-qracodes.o: qracodes/qracodes.c
- gcc -c -O2 -o qracodes.o qracodes/qracodes.c
-
-qra64.o: qra64/qra64.c
- gcc -c -O2 -o qra64.o qra64/qra64.c
-
-qra13_64_64_irr_e.o: qracodes/qra13_64_64_irr_e.c
- gcc -c -O2 -o qra13_64_64_irr_e.o \
- qracodes/qra13_64_64_irr_e.c
-
-npfwht.o: qracodes/npfwht.c
- gcc -c -O2 -o npfwht.o qracodes/npfwht.c
-
-pdmath.o: qracodes/pdmath.c
- gcc -c -O2 -o pdmath.o qracodes/pdmath.c
-
-OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \
- timer.o ipcomm.o sec_midn.o usleep.o
-# cutil.o
-
-LIBS3 = -L'C:/JTSDK/Qt55/5.5/mingw492_32/lib' -lQt5Core
-
-m65.exe: $(OBJS3) libm65.a
- $(CXX) -o m65.exe $(OBJS3) $(LIBS3) libm65.a ../libfftw3f_win.a \
- -lgfortran
-# cp m65.exe ../../map65_install
- cp m65.exe /c/MAP65_2.9
-
-OBJS7 = astrosub.o astro0.o astro.o tm2.o grid2deg.o sun.o moondop.o \
- coord.o dot.o moon2.o tmoonsub.o toxyz.o geocentric.o \
- dcoord.o
-
-libastro.a: $(OBJS7)
- ar cr libastro.a $(OBJS7)
- ranlib libastro.a
-
-OBJS6 = mapsim.o cgen65.o noisegen.o gran.o
-mapsim.exe: $(OBJS6) libm65.a
- $(FC) -o mapsim.exe $(OBJS6) libm65.a
-
-INCPATH = -I'C:/JTSDK/Qt55/5.5/mingw492_32/include/QtCore' \
- -I'C:/JTSDK/Qt55/5.5/mingw492_32/include'
-
-ipcomm.o: ipcomm.cpp
- $(CXX) -c $(INCPATH) ipcomm.cpp
-
-#m65a.o: m65a.f90
-# $(FC) -c -fno-second-underscore -cpp m65a.f90
-
-sec_midn.o: sec_midn.f90
- $(FC) -c -fno-second-underscore sec_midn.f90
-
-#symspec.o: ../symspec.f90
-# $(FC) -c $(FFLAGS) -o symspec.o ../symspec.f90
-
-OBJS4 = tastro.o astro0.o libm65.a
-tastro.exe: $(OBJS4)
- $(FC) $(FFLAGS) -o tastro.exe $(OBJS4) libm65.a
-
-OBJS5 = t1.o timer.o libm65.a
-t1.exe: $(OBJS5)
- $(FC) $(FFLAGS) -o t1.exe $(OBJS5) libm65.a
-
-#astro0.o: ../astro0.f90
-# $(FC) -c $(FFLAGS) -o astro0.o ../astro0.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 *.mod libm65.a m65.exe
+# Makefile for MinGW on Windows +CC = c:/JTSDK/Qt55/Tools/mingw492_32/bin/gcc +FC = c:/JTSDK/Qt55/Tools/mingw492_32/bin/gfortran +CXX = c:/JTSDK/Qt55/Tools/mingw492_32/bin/g++ + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion -Wno-precision-loss \ + -fno-second-underscore -fbacktrace \ + -ffpe-summary=none +# -ffpe-trap=invalid,zero,overflow,underflow,denormal +CFLAGS = -I. -fbounds-check + +# 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: packjt.o wavhdr.o libm65.a m65.exe mapsim.exe libastro.a + +OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \ + decode1a.o sort.o filbig.o fil6521.o afc65b.o \ + twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \ + extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \ + interleave63.o encode65.o igray.o set.o shell.o qra64_subs.o \ + grid2k.o getpfx2.o q65b.o qra64c.o twkfreq_xy.o qra64zap.o \ + deg2grid.o getpfx1.o k2grid.o ftrsd2.o graycode65.o \ + wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \ + four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o sync64.o spec64.o \ + astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \ + geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \ + gen65.o chkmsg.o ptt.o astrosub.o astro0.o recvpkt.o symspec.o \ + iqcal.o iqfix.o timf2.o s3avg.o packjt.o badmsg.o fmtmsg.o \ + qracodes.o qra64.o smo.o averms.o lorentzian.o npfwht.o pdmath.o \ + qra13_64_64_irr_e.o fchisq0.o gen_q65_wave.o wavhdr.o + +packjt.o: packjt.f90 + $(FC) -c packjt.f90 + +libm65.a: $(OBJS1) + ar cr libm65.a $(OBJS1) + ranlib libm65.a + +qra64_subs.o: ./qra64/qra64_subs.c + gcc -c -O2 -o qra64_subs.o ./qra64/qra64_subs.c + +qracodes.o: qracodes/qracodes.c + gcc -c -O2 -o qracodes.o qracodes/qracodes.c + +qra64.o: qra64/qra64.c + gcc -c -O2 -o qra64.o qra64/qra64.c + +qra13_64_64_irr_e.o: qracodes/qra13_64_64_irr_e.c + gcc -c -O2 -o qra13_64_64_irr_e.o \ + qracodes/qra13_64_64_irr_e.c + +npfwht.o: qracodes/npfwht.c + gcc -c -O2 -o npfwht.o qracodes/npfwht.c + +pdmath.o: qracodes/pdmath.c + gcc -c -O2 -o pdmath.o qracodes/pdmath.c + +OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \ + timer.o ipcomm.o sec_midn.o usleep.o +# cutil.o + +LIBS3 = -L'C:/JTSDK/Qt55/5.5/mingw492_32/lib' -lQt5Core + +m65.exe: $(OBJS3) libm65.a + $(CXX) -o m65.exe $(OBJS3) $(LIBS3) libm65.a ../libfftw3f_win.a \ + -lgfortran +# cp m65.exe ../../map65_install + cp m65.exe /c/MAP65_2.9 + +OBJS7 = astrosub.o astro0.o astro.o tm2.o grid2deg.o sun.o moondop.o \ + coord.o dot.o moon2.o tmoonsub.o toxyz.o geocentric.o \ + dcoord.o + +libastro.a: $(OBJS7) + ar cr libastro.a $(OBJS7) + ranlib libastro.a + +OBJS6 = mapsim.o cgen65.o noisegen.o gran.o +mapsim.exe: $(OBJS6) libm65.a + $(FC) -o mapsim.exe $(OBJS6) libm65.a + +INCPATH = -I'C:/JTSDK/Qt55/5.5/mingw492_32/include/QtCore' \ + -I'C:/JTSDK/Qt55/5.5/mingw492_32/include' + +ipcomm.o: ipcomm.cpp + $(CXX) -c $(INCPATH) ipcomm.cpp + +#m65a.o: m65a.f90 +# $(FC) -c -fno-second-underscore -cpp m65a.f90 + +sec_midn.o: sec_midn.f90 + $(FC) -c -fno-second-underscore sec_midn.f90 + +#symspec.o: ../symspec.f90 +# $(FC) -c $(FFLAGS) -o symspec.o ../symspec.f90 + +OBJS4 = tastro.o astro0.o libm65.a +tastro.exe: $(OBJS4) + $(FC) $(FFLAGS) -o tastro.exe $(OBJS4) libm65.a + +OBJS5 = t1.o timer.o libm65.a +t1.exe: $(OBJS5) + $(FC) $(FFLAGS) -o t1.exe $(OBJS5) libm65.a + +#astro0.o: ../astro0.f90 +# $(FC) -c $(FFLAGS) -o astro0.o ../astro0.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 *.mod libm65.a m65.exe diff --git a/map65/libm65/Makefile.0 b/map65/libm65/Makefile.0 index 941f57c2..7ff2357f 100755..100644 --- a/map65/libm65/Makefile.0 +++ b/map65/libm65/Makefile.0 @@ -1,114 +1,114 @@ -# Makefile for Linux
-CC = gcc
-FC = gfortran
-CXX = g++
-
-FFLAGS = -O2 -fbounds-check -Wall -Wno-precision-loss -fno-second-underscore
-# For ptt_unix:
-CFLAGS = -I. -fbounds-check -DHAVE_STDLIB_H=1 -DHAVE_STDIO_H=1 \
- -DHAVE_FCNTL_H=1 -DHAVE_SYS_IOCTL_H=1
-
-# 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: packjt.o libm65.a m65 mapsim libastro.a
-
-OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \
- decode1a.o sort.o filbig.o fil6521.o afc65b.o \
- twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \
- extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \
- interleave63.o encode65.o igray.o set.o shell.o qra64_subs.o \
- grid2k.o getpfx2.o qra64b.o qra64c.o twkfreq_xy.o qra64zap.o \
- deg2grid.o getpfx1.o k2grid.o ftrsd2.o graycode65.o \
- wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \
- four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o sync64.o spec64.o \
- astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \
- geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \
- gen65.o chkmsg.o astrosub.o astro0.o recvpkt.o symspec.o \
- iqcal.o iqfix.o timf2.o s3avg.o packjt.o badmsg.o fmtmsg.o \
- qracodes.o qra64.o smo.o averms.o lorentzian.o npfwht.o pdmath.o \
- qra13_64_64_irr_e.o fchisq0.o genqra64a.o ptt_unix.o
-
-packjt.o: packjt.f90
- $(FC) -c packjt.f90
-
-libm65.a: $(OBJS1)
- ar cr libm65.a $(OBJS1)
- ranlib libm65.a
-
-qra64_subs.o: ./qra64/qra64_subs.c
- gcc -c -O2 -o qra64_subs.o ./qra64/qra64_subs.c
-
-qracodes.o: ./qracodes/qracodes.c
- gcc -c -O2 -o qracodes.o ./qracodes/qracodes.c
-
-qra64.o: ./qra64/qra64.c
- gcc -c -O2 -o qra64.o ./qra64/qra64.c
-
-qra13_64_64_irr_e.o: ./qracodes/qra13_64_64_irr_e.c
- gcc -c -O2 -o qra13_64_64_irr_e.o ./qracodes/qra13_64_64_irr_e.c
-
-npfwht.o: ./qracodes/npfwht.c
- gcc -c -O2 -o npfwht.o ./qracodes/npfwht.c
-
-pdmath.o: ./qracodes/pdmath.c
- gcc -c -O2 -o pdmath.o ./qracodes/pdmath.c
-
-OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \
- timer.o ipcomm.o sec_midn.o usleep.o
-
-m65: $(OBJS3) libm65.a
- $(CXX) -o m65 $(OBJS3) libm65.a -lfftw3f -lQt5Core -lfftw3f -lgfortran
- cp m65 ../../map65_install
-
-OBJS7 = astrosub.o astro0.o astro.o tm2.o grid2deg.o sun.o moondop.o \
- coord.o dot.o moon2.o tmoonsub.o toxyz.o geocentric.o \
- dcoord.o
-
-libastro.a: $(OBJS7)
- ar cr libastro.a $(OBJS7)
- ranlib libastro.a
-
-OBJS6 = mapsim.o cgen65.o noisegen.o gran.o
-mapsim: $(OBJS6) libm65.a
- $(FC) -o mapsim $(OBJS6) libm65.a
-
-INCPATH = -I. -I'/usr/include/x86_64-linux-gnu/qt5' \
- -I'/usr/include/x86_64-linux-gnu/qt5/QtCore'
-
-ipcomm.o: ipcomm.cpp
- $(CXX) -c $(INCPATH) -fPIC ipcomm.cpp
-
-sec_midn.o: sec_midn.f90
- $(FC) -c -fno-second-underscore sec_midn.f90
-
-OBJS4 = tastro.o astro0.o libm65.a
-tastro: $(OBJS4)
- $(FC) $(FFLAGS) -o tastro $(OBJS4) libm65.a
-
-OBJS5 = t1.o timer.o libm65.a
-t1: $(OBJS5)
- $(FC) $(FFLAGS) -o t1 $(OBJS5) libm65.a
-
-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 *.mod libm65.a m65
+# Makefile for Linux +CC = gcc +FC = gfortran +CXX = g++ + +FFLAGS = -O2 -fbounds-check -Wall -Wno-precision-loss -fno-second-underscore +# For ptt_unix: +CFLAGS = -I. -fbounds-check -DHAVE_STDLIB_H=1 -DHAVE_STDIO_H=1 \ + -DHAVE_FCNTL_H=1 -DHAVE_SYS_IOCTL_H=1 + +# 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: packjt.o libm65.a m65 mapsim libastro.a + +OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \ + decode1a.o sort.o filbig.o fil6521.o afc65b.o \ + twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \ + extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \ + interleave63.o encode65.o igray.o set.o shell.o qra64_subs.o \ + grid2k.o getpfx2.o qra64b.o qra64c.o twkfreq_xy.o qra64zap.o \ + deg2grid.o getpfx1.o k2grid.o ftrsd2.o graycode65.o \ + wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \ + four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o sync64.o spec64.o \ + astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \ + geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \ + gen65.o chkmsg.o astrosub.o astro0.o recvpkt.o symspec.o \ + iqcal.o iqfix.o timf2.o s3avg.o packjt.o badmsg.o fmtmsg.o \ + qracodes.o qra64.o smo.o averms.o lorentzian.o npfwht.o pdmath.o \ + qra13_64_64_irr_e.o fchisq0.o genqra64a.o ptt_unix.o + +packjt.o: packjt.f90 + $(FC) -c packjt.f90 + +libm65.a: $(OBJS1) + ar cr libm65.a $(OBJS1) + ranlib libm65.a + +qra64_subs.o: ./qra64/qra64_subs.c + gcc -c -O2 -o qra64_subs.o ./qra64/qra64_subs.c + +qracodes.o: ./qracodes/qracodes.c + gcc -c -O2 -o qracodes.o ./qracodes/qracodes.c + +qra64.o: ./qra64/qra64.c + gcc -c -O2 -o qra64.o ./qra64/qra64.c + +qra13_64_64_irr_e.o: ./qracodes/qra13_64_64_irr_e.c + gcc -c -O2 -o qra13_64_64_irr_e.o ./qracodes/qra13_64_64_irr_e.c + +npfwht.o: ./qracodes/npfwht.c + gcc -c -O2 -o npfwht.o ./qracodes/npfwht.c + +pdmath.o: ./qracodes/pdmath.c + gcc -c -O2 -o pdmath.o ./qracodes/pdmath.c + +OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \ + timer.o ipcomm.o sec_midn.o usleep.o + +m65: $(OBJS3) libm65.a + $(CXX) -o m65 $(OBJS3) libm65.a -lfftw3f -lQt5Core -lfftw3f -lgfortran + cp m65 ../../map65_install + +OBJS7 = astrosub.o astro0.o astro.o tm2.o grid2deg.o sun.o moondop.o \ + coord.o dot.o moon2.o tmoonsub.o toxyz.o geocentric.o \ + dcoord.o + +libastro.a: $(OBJS7) + ar cr libastro.a $(OBJS7) + ranlib libastro.a + +OBJS6 = mapsim.o cgen65.o noisegen.o gran.o +mapsim: $(OBJS6) libm65.a + $(FC) -o mapsim $(OBJS6) libm65.a + +INCPATH = -I. -I'/usr/include/x86_64-linux-gnu/qt5' \ + -I'/usr/include/x86_64-linux-gnu/qt5/QtCore' + +ipcomm.o: ipcomm.cpp + $(CXX) -c $(INCPATH) -fPIC ipcomm.cpp + +sec_midn.o: sec_midn.f90 + $(FC) -c -fno-second-underscore sec_midn.f90 + +OBJS4 = tastro.o astro0.o libm65.a +tastro: $(OBJS4) + $(FC) $(FFLAGS) -o tastro $(OBJS4) libm65.a + +OBJS5 = t1.o timer.o libm65.a +t1: $(OBJS5) + $(FC) $(FFLAGS) -o t1 $(OBJS5) libm65.a + +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 *.mod libm65.a m65 diff --git a/map65/libm65/Makefile.MinGW b/map65/libm65/Makefile.MinGW index 1732e501..52b0ace0 100755..100644 --- a/map65/libm65/Makefile.MinGW +++ b/map65/libm65/Makefile.MinGW @@ -1,105 +1,105 @@ -# Makefile for MinGW on Windows
-CC = gcc
-FC = g95
-CXX = c:/wsjt-env/Qt5/Tools/mingw48_32/bin/g++
-
-FFLAGS = -O2 -fbounds-check -Wall -Wno-precision-loss -fno-second-underscore
-CFLAGS = -I. -fbounds-check
-
-# 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: libm65.a m65.exe JT65code.exe mapsim.exe libastro.a
-
-OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \
- decode1a.o sort.o filbig.o fil6521.o afc65b.o \
- twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \
- extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \
- interleave63.o unpackmsg.o encode65.o igray.o set.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 \
- wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \
- four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o \
- astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \
- geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \
- gen65.o chkmsg.o ptt.o astrosub.o astro0.o recvpkt.o symspec.o \
- iqcal.o iqfix.o timf2.o s3avg.o
-
-libm65.a: $(OBJS1)
- ar cr libm65.a $(OBJS1)
- ranlib libm65.a
-
-OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \
- timer.o ipcomm.o sec_midn.o cutil.o
-
-LIBS3 = -L'C:/wsjt-env/Qt5/5.2.1/mingw48_32/lib' -lQt5Core
-
-m65.exe: $(OBJS3) libm65.a
- $(CXX) -o m65.exe $(OBJS3) $(LIBS3) libm65.a ../libfftw3f_win.a \
- c:/MinGW/lib/libf95.a
- cp m65.exe ../../map65_install
-
-OBJS2 = JT65code.o
-JT65code.exe: $(OBJS2) libm65.a
- $(FC) -o JT65code.exe $(OBJS2) libm65.a
-
-OBJS7 = astrosub.o astro0.o astro.o tm2.o grid2deg.o sun.o moondop.o \
- coord.o dot.o moon2.o tmoonsub.o toxyz.o geocentric.o \
- dcoord.o
-
-libastro.a: $(OBJS7)
- ar cr libastro.a $(OBJS7)
- ranlib libastro.a
-
-OBJS6 = mapsim.o cgen65.o noisegen.o gran.o
-mapsim.exe: $(OBJS6) libm65.a
- $(FC) -o mapsim.exe $(OBJS6) libm65.a
-
-INCPATH = -I'C:/wsjt-env/Qt5/5.2.1/mingw48_32/include/QtCore' \
- -I'C:/wsjt-env/Qt5/5.2.1/mingw48_32/include'
-
-ipcomm.o: ipcomm.cpp
- $(CXX) -c $(INCPATH) ipcomm.cpp
-
-#m65a.o: m65a.f90
-# $(FC) -c -fno-second-underscore -cpp m65a.f90
-
-sec_midn.o: sec_midn.f90
- $(FC) -c -fno-second-underscore sec_midn.f90
-
-#symspec.o: ../symspec.f90
-# $(FC) -c $(FFLAGS) -o symspec.o ../symspec.f90
-
-OBJS4 = tastro.o astro0.o libm65.a
-tastro.exe: $(OBJS4)
- $(FC) $(FFLAGS) -o tastro.exe $(OBJS4) libm65.a
-
-OBJS5 = t1.o timer.o libm65.a
-t1.exe: $(OBJS5)
- $(FC) $(FFLAGS) -o t1.exe $(OBJS5) libm65.a
-
-#astro0.o: ../astro0.f90
-# $(FC) -c $(FFLAGS) -o astro0.o ../astro0.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 libm65.a m65.exe jt65code.exe
+# Makefile for MinGW on Windows +CC = gcc +FC = g95 +CXX = c:/wsjt-env/Qt5/Tools/mingw48_32/bin/g++ + +FFLAGS = -O2 -fbounds-check -Wall -Wno-precision-loss -fno-second-underscore +CFLAGS = -I. -fbounds-check + +# 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: libm65.a m65.exe JT65code.exe mapsim.exe libastro.a + +OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \ + decode1a.o sort.o filbig.o fil6521.o afc65b.o \ + twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \ + extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \ + interleave63.o unpackmsg.o encode65.o igray.o set.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 \ + wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \ + four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o \ + astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \ + geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \ + gen65.o chkmsg.o ptt.o astrosub.o astro0.o recvpkt.o symspec.o \ + iqcal.o iqfix.o timf2.o s3avg.o + +libm65.a: $(OBJS1) + ar cr libm65.a $(OBJS1) + ranlib libm65.a + +OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \ + timer.o ipcomm.o sec_midn.o cutil.o + +LIBS3 = -L'C:/wsjt-env/Qt5/5.2.1/mingw48_32/lib' -lQt5Core + +m65.exe: $(OBJS3) libm65.a + $(CXX) -o m65.exe $(OBJS3) $(LIBS3) libm65.a ../libfftw3f_win.a \ + c:/MinGW/lib/libf95.a + cp m65.exe ../../map65_install + +OBJS2 = JT65code.o +JT65code.exe: $(OBJS2) libm65.a + $(FC) -o JT65code.exe $(OBJS2) libm65.a + +OBJS7 = astrosub.o astro0.o astro.o tm2.o grid2deg.o sun.o moondop.o \ + coord.o dot.o moon2.o tmoonsub.o toxyz.o geocentric.o \ + dcoord.o + +libastro.a: $(OBJS7) + ar cr libastro.a $(OBJS7) + ranlib libastro.a + +OBJS6 = mapsim.o cgen65.o noisegen.o gran.o +mapsim.exe: $(OBJS6) libm65.a + $(FC) -o mapsim.exe $(OBJS6) libm65.a + +INCPATH = -I'C:/wsjt-env/Qt5/5.2.1/mingw48_32/include/QtCore' \ + -I'C:/wsjt-env/Qt5/5.2.1/mingw48_32/include' + +ipcomm.o: ipcomm.cpp + $(CXX) -c $(INCPATH) ipcomm.cpp + +#m65a.o: m65a.f90 +# $(FC) -c -fno-second-underscore -cpp m65a.f90 + +sec_midn.o: sec_midn.f90 + $(FC) -c -fno-second-underscore sec_midn.f90 + +#symspec.o: ../symspec.f90 +# $(FC) -c $(FFLAGS) -o symspec.o ../symspec.f90 + +OBJS4 = tastro.o astro0.o libm65.a +tastro.exe: $(OBJS4) + $(FC) $(FFLAGS) -o tastro.exe $(OBJS4) libm65.a + +OBJS5 = t1.o timer.o libm65.a +t1.exe: $(OBJS5) + $(FC) $(FFLAGS) -o t1.exe $(OBJS5) libm65.a + +#astro0.o: ../astro0.f90 +# $(FC) -c $(FFLAGS) -o astro0.o ../astro0.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 libm65.a m65.exe jt65code.exe diff --git a/map65/libm65/Makefile.jtsdk b/map65/libm65/Makefile.jtsdk index 8839479e..77d97f59 100755..100644 --- a/map65/libm65/Makefile.jtsdk +++ b/map65/libm65/Makefile.jtsdk @@ -1,129 +1,129 @@ -# Makefile for MinGW on Windows
-CC = c:/JTSDK/Qt55/Tools/mingw492_32/bin/gcc
-FC = c:/JTSDK/Qt55/Tools/mingw492_32/bin/gfortran
-CXX = c:/JTSDK/Qt55/Tools/mingw492_32/bin/g++
-
-FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion -Wno-precision-loss \
- -fno-second-underscore -fbacktrace \
- -ffpe-summary=none
-# -ffpe-trap=invalid,zero,overflow,underflow,denormal
-CFLAGS = -I. -fbounds-check
-
-# 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: packjt.o wavhdr.o libm65.a m65.exe mapsim.exe libastro.a
-
-OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \
- decode1a.o sort.o filbig.o fil6521.o afc65b.o \
- twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \
- extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \
- interleave63.o encode65.o igray.o set.o shell.o qra64_subs.o \
- grid2k.o getpfx2.o q65b.o qra64c.o twkfreq_xy.o qra64zap.o \
- deg2grid.o getpfx1.o k2grid.o ftrsd2.o graycode65.o \
- wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \
- four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o sync64.o spec64.o \
- astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \
- geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \
- gen65.o chkmsg.o ptt.o astrosub.o astro0.o recvpkt.o symspec.o \
- iqcal.o iqfix.o timf2.o s3avg.o packjt.o badmsg.o fmtmsg.o \
- qracodes.o qra64.o smo.o averms.o lorentzian.o npfwht.o pdmath.o \
- qra13_64_64_irr_e.o fchisq0.o genqra64a.o wavhdr.o
-
-packjt.o: packjt.f90
- $(FC) -c packjt.f90
-
-libm65.a: $(OBJS1)
- ar cr libm65.a $(OBJS1)
- ranlib libm65.a
-
-qra64_subs.o: ./qra64/qra64_subs.c
- gcc -c -O2 -o qra64_subs.o ./qra64/qra64_subs.c
-
-qracodes.o: qracodes/qracodes.c
- gcc -c -O2 -o qracodes.o qracodes/qracodes.c
-
-qra64.o: qra64/qra64.c
- gcc -c -O2 -o qra64.o qra64/qra64.c
-
-qra13_64_64_irr_e.o: qracodes/qra13_64_64_irr_e.c
- gcc -c -O2 -o qra13_64_64_irr_e.o \
- qracodes/qra13_64_64_irr_e.c
-
-npfwht.o: qracodes/npfwht.c
- gcc -c -O2 -o npfwht.o qracodes/npfwht.c
-
-pdmath.o: qracodes/pdmath.c
- gcc -c -O2 -o pdmath.o qracodes/pdmath.c
-
-OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \
- timer.o ipcomm.o sec_midn.o usleep.o
-# cutil.o
-
-LIBS3 = -L'C:/JTSDK/Qt55/5.5/mingw492_32/lib' -lQt5Core
-
-m65.exe: $(OBJS3) libm65.a
- $(CXX) -o m65.exe $(OBJS3) $(LIBS3) libm65.a ../libfftw3f_win.a \
- -lgfortran
- cp m65.exe ../../map65_install
-
-OBJS7 = astrosub.o astro0.o astro.o tm2.o grid2deg.o sun.o moondop.o \
- coord.o dot.o moon2.o tmoonsub.o toxyz.o geocentric.o \
- dcoord.o
-
-libastro.a: $(OBJS7)
- ar cr libastro.a $(OBJS7)
- ranlib libastro.a
-
-OBJS6 = mapsim.o cgen65.o noisegen.o gran.o
-mapsim.exe: $(OBJS6) libm65.a
- $(FC) -o mapsim.exe $(OBJS6) libm65.a
-
-INCPATH = -I'C:/JTSDK/Qt55/5.5/mingw492_32/include/QtCore' \
- -I'C:/JTSDK/Qt55/5.5/mingw492_32/include'
-
-ipcomm.o: ipcomm.cpp
- $(CXX) -c $(INCPATH) ipcomm.cpp
-
-#m65a.o: m65a.f90
-# $(FC) -c -fno-second-underscore -cpp m65a.f90
-
-sec_midn.o: sec_midn.f90
- $(FC) -c -fno-second-underscore sec_midn.f90
-
-#symspec.o: ../symspec.f90
-# $(FC) -c $(FFLAGS) -o symspec.o ../symspec.f90
-
-OBJS4 = tastro.o astro0.o libm65.a
-tastro.exe: $(OBJS4)
- $(FC) $(FFLAGS) -o tastro.exe $(OBJS4) libm65.a
-
-OBJS5 = t1.o timer.o libm65.a
-t1.exe: $(OBJS5)
- $(FC) $(FFLAGS) -o t1.exe $(OBJS5) libm65.a
-
-#astro0.o: ../astro0.f90
-# $(FC) -c $(FFLAGS) -o astro0.o ../astro0.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 *.mod libm65.a m65.exe
+# Makefile for MinGW on Windows +CC = c:/JTSDK/Qt55/Tools/mingw492_32/bin/gcc +FC = c:/JTSDK/Qt55/Tools/mingw492_32/bin/gfortran +CXX = c:/JTSDK/Qt55/Tools/mingw492_32/bin/g++ + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion -Wno-precision-loss \ + -fno-second-underscore -fbacktrace \ + -ffpe-summary=none +# -ffpe-trap=invalid,zero,overflow,underflow,denormal +CFLAGS = -I. -fbounds-check + +# 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: packjt.o wavhdr.o libm65.a m65.exe mapsim.exe libastro.a + +OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \ + decode1a.o sort.o filbig.o fil6521.o afc65b.o \ + twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \ + extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \ + interleave63.o encode65.o igray.o set.o shell.o qra64_subs.o \ + grid2k.o getpfx2.o q65b.o qra64c.o twkfreq_xy.o qra64zap.o \ + deg2grid.o getpfx1.o k2grid.o ftrsd2.o graycode65.o \ + wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \ + four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o sync64.o spec64.o \ + astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \ + geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \ + gen65.o chkmsg.o ptt.o astrosub.o astro0.o recvpkt.o symspec.o \ + iqcal.o iqfix.o timf2.o s3avg.o packjt.o badmsg.o fmtmsg.o \ + qracodes.o qra64.o smo.o averms.o lorentzian.o npfwht.o pdmath.o \ + qra13_64_64_irr_e.o fchisq0.o genqra64a.o wavhdr.o + +packjt.o: packjt.f90 + $(FC) -c packjt.f90 + +libm65.a: $(OBJS1) + ar cr libm65.a $(OBJS1) + ranlib libm65.a + +qra64_subs.o: ./qra64/qra64_subs.c + gcc -c -O2 -o qra64_subs.o ./qra64/qra64_subs.c + +qracodes.o: qracodes/qracodes.c + gcc -c -O2 -o qracodes.o qracodes/qracodes.c + +qra64.o: qra64/qra64.c + gcc -c -O2 -o qra64.o qra64/qra64.c + +qra13_64_64_irr_e.o: qracodes/qra13_64_64_irr_e.c + gcc -c -O2 -o qra13_64_64_irr_e.o \ + qracodes/qra13_64_64_irr_e.c + +npfwht.o: qracodes/npfwht.c + gcc -c -O2 -o npfwht.o qracodes/npfwht.c + +pdmath.o: qracodes/pdmath.c + gcc -c -O2 -o pdmath.o qracodes/pdmath.c + +OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \ + timer.o ipcomm.o sec_midn.o usleep.o +# cutil.o + +LIBS3 = -L'C:/JTSDK/Qt55/5.5/mingw492_32/lib' -lQt5Core + +m65.exe: $(OBJS3) libm65.a + $(CXX) -o m65.exe $(OBJS3) $(LIBS3) libm65.a ../libfftw3f_win.a \ + -lgfortran + cp m65.exe ../../map65_install + +OBJS7 = astrosub.o astro0.o astro.o tm2.o grid2deg.o sun.o moondop.o \ + coord.o dot.o moon2.o tmoonsub.o toxyz.o geocentric.o \ + dcoord.o + +libastro.a: $(OBJS7) + ar cr libastro.a $(OBJS7) + ranlib libastro.a + +OBJS6 = mapsim.o cgen65.o noisegen.o gran.o +mapsim.exe: $(OBJS6) libm65.a + $(FC) -o mapsim.exe $(OBJS6) libm65.a + +INCPATH = -I'C:/JTSDK/Qt55/5.5/mingw492_32/include/QtCore' \ + -I'C:/JTSDK/Qt55/5.5/mingw492_32/include' + +ipcomm.o: ipcomm.cpp + $(CXX) -c $(INCPATH) ipcomm.cpp + +#m65a.o: m65a.f90 +# $(FC) -c -fno-second-underscore -cpp m65a.f90 + +sec_midn.o: sec_midn.f90 + $(FC) -c -fno-second-underscore sec_midn.f90 + +#symspec.o: ../symspec.f90 +# $(FC) -c $(FFLAGS) -o symspec.o ../symspec.f90 + +OBJS4 = tastro.o astro0.o libm65.a +tastro.exe: $(OBJS4) + $(FC) $(FFLAGS) -o tastro.exe $(OBJS4) libm65.a + +OBJS5 = t1.o timer.o libm65.a +t1.exe: $(OBJS5) + $(FC) $(FFLAGS) -o t1.exe $(OBJS5) libm65.a + +#astro0.o: ../astro0.f90 +# $(FC) -c $(FFLAGS) -o astro0.o ../astro0.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 *.mod libm65.a m65.exe diff --git a/map65/libm65/Makefile.linux b/map65/libm65/Makefile.linux index 73b6652d..4b96f215 100755..100644 --- a/map65/libm65/Makefile.linux +++ b/map65/libm65/Makefile.linux @@ -1,96 +1,96 @@ -CC = gcc
-FC = gfortran
-
-FFLAGS = -O2 -fbounds-check -Wall
-# For ptt_unix:
-CFLAGS = -I. -fbounds-check -DHAVE_STDLIB_H=1 -DHAVE_STDIO_H=1 \
- -DHAVE_FCNTL_H=1 -DHAVE_SYS_IOCTL_H=1
-
-# 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: libm65.a m65
-
-OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \
- decode1a.o sort.o filbig.o fil6521.o afc65b.o \
- twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \
- extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \
- interleave63.o unpackmsg.o encode65.o igray.o set.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 \
- wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \
- four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o \
- astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \
- geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \
- gen65.o chkmsg.o ptt_unix.o astrosub.o astro0.o recvpkt.o \
- symspec.o iqcal.o iqfix.o timf2.o s3avg.o
-
-libm65.a: $(OBJS1)
- ar cr libm65.a $(OBJS1)
- ranlib libm65.a
-
-OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \
- timer.o ipcomm.o sec_midn.o cutil.o
-
-m65: $(OBJS3) libm65.a
- g++ -o m65 $(OBJS3) libm65.a -lfftw3f -lQtCore -lfftw3f -lgfortran
-
-OBJS2 = m65a.o ipcomm.o sec_midn.o cutil.o decode0.o map65a.o \
- timer.o ftninit.o ftnquit.o
-LIBS2 = -lQtCore -lfftw3f -lgfortran
-
-m65a: $(OBJS2) libm65.a
- g++ -o m65a $(OBJS2) libm65.a -lQtCore -lfftw3f -lgfortran
-
-OBJS6 = t3.o ipcomm.o
-LIBS2 = -lQtCore -lgfortran
-
-t3: $(OBJS6)
- g++ -o t3 $(OBJS6) $(LIBS2)
-
-t3:
-
-INCPATH = -I. -I'/usr/include/qt4' -I'/usr/include/qt4/QtCore'
-
-ipcomm.o: ipcomm.cpp
- g++ -c $(INCPATH) ipcomm.cpp
-
-m65a.o: m65a.F90
- $(FC) -c -fno-second-underscore -DUNIX m65a.F90
-
-extract.o: extract.F
- $(FC) -c -fno-second-underscore -DUNIX extract.F
-
-sec_midn.o: sec_midn.f90
- $(FC) -c -fno-second-underscore sec_midn.f90
-
-OBJS4 = tastro.o astro0.o libm65.a
-tastro: $(OBJS4)
- $(FC) $(FFLAGS) -o tastro $(OBJS4) libm65.a
-
-OBJS5 = t1.o timer.o libm65.a
-t1: $(OBJS5)
- $(FC) $(FFLAGS) -o t1 $(OBJS5) libm65.a
-
-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 libm65.a m65 m65a
+CC = gcc +FC = gfortran + +FFLAGS = -O2 -fbounds-check -Wall +# For ptt_unix: +CFLAGS = -I. -fbounds-check -DHAVE_STDLIB_H=1 -DHAVE_STDIO_H=1 \ + -DHAVE_FCNTL_H=1 -DHAVE_SYS_IOCTL_H=1 + +# 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: libm65.a m65 + +OBJS1 = trimlist.o display.o getdphi.o pctile.o ccf65.o \ + decode1a.o sort.o filbig.o fil6521.o afc65b.o \ + twkfreq.o decode65b.o indexx.o ssort.o fchisq.o setup65.o \ + extract.o deep65.o ccf2.o demod64a.o chkhist.o graycode.o \ + interleave63.o unpackmsg.o encode65.o igray.o set.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 \ + wrapkarn.o nchar.o init_rs.o encode_rs.o decode_rs.o \ + four2a.o rfile3a.o grid2deg.o pfxdump.o dpol.o \ + astro.o tm2.o sun.o moondop.o coord.o tmoonsub.o \ + geocentric.o moon2.o toxyz.o dot.o dcoord.o f77_wisdom.o \ + gen65.o chkmsg.o ptt_unix.o astrosub.o astro0.o recvpkt.o \ + symspec.o iqcal.o iqfix.o timf2.o s3avg.o + +libm65.a: $(OBJS1) + ar cr libm65.a $(OBJS1) + ranlib libm65.a + +OBJS3 = m65.o m65a.o map65a.o symspec.o decode0.o ftninit.o ftnquit.o \ + timer.o ipcomm.o sec_midn.o cutil.o + +m65: $(OBJS3) libm65.a + g++ -o m65 $(OBJS3) libm65.a -lfftw3f -lQtCore -lfftw3f -lgfortran + +OBJS2 = m65a.o ipcomm.o sec_midn.o cutil.o decode0.o map65a.o \ + timer.o ftninit.o ftnquit.o +LIBS2 = -lQtCore -lfftw3f -lgfortran + +m65a: $(OBJS2) libm65.a + g++ -o m65a $(OBJS2) libm65.a -lQtCore -lfftw3f -lgfortran + +OBJS6 = t3.o ipcomm.o +LIBS2 = -lQtCore -lgfortran + +t3: $(OBJS6) + g++ -o t3 $(OBJS6) $(LIBS2) + +t3: + +INCPATH = -I. -I'/usr/include/qt4' -I'/usr/include/qt4/QtCore' + +ipcomm.o: ipcomm.cpp + g++ -c $(INCPATH) ipcomm.cpp + +m65a.o: m65a.F90 + $(FC) -c -fno-second-underscore -DUNIX m65a.F90 + +extract.o: extract.F + $(FC) -c -fno-second-underscore -DUNIX extract.F + +sec_midn.o: sec_midn.f90 + $(FC) -c -fno-second-underscore sec_midn.f90 + +OBJS4 = tastro.o astro0.o libm65.a +tastro: $(OBJS4) + $(FC) $(FFLAGS) -o tastro $(OBJS4) libm65.a + +OBJS5 = t1.o timer.o libm65.a +t1: $(OBJS5) + $(FC) $(FFLAGS) -o t1 $(OBJS5) libm65.a + +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 libm65.a m65 m65a diff --git a/map65/libm65/afc65b.f90 b/map65/libm65/afc65b.f90 index 8d5b2daa..53f61ea4 100755..100644 --- a/map65/libm65/afc65b.f90 +++ b/map65/libm65/afc65b.f90 @@ -1,70 +1,70 @@ -subroutine afc65b(cx,cy,npts,fsample,nflip,ipol,xpol,ndphi,a,ccfbest,dtbest)
-
- logical xpol
- complex cx(npts)
- complex cy(npts)
- real a(5),deltaa(5)
-
- a(1)=0.
- a(2)=0.
- a(3)=0.
- a(4)=45.0*(ipol-1.0)
- deltaa(1)=2.0
- deltaa(2)=2.0
- deltaa(3)=2.0
- deltaa(4)=22.5
- deltaa(5)=0.05
- nterms=3
- if(xpol) nterms=4
-
-! Don't fit polarization when solving for dphi
- if(ndphi.ne.0) nterms=3
-
-! Start the iteration
- chisqr=0.
- chisqr0=1.e6
- do iter=1,3 !One iteration is enough?
- do j=1,nterms
- chisq1=fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
- fn=0.
- delta=deltaa(j)
-10 a(j)=a(j)+delta
- chisq2=fchisq(cx,cy,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=fchisq(cx,cy,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=fchisq(cx,cy,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
-
- if(a(4).lt.0.0) a(4)=a(4)+180.0
- if(a(4).ge.180.0) a(4)=a(4)-180.0
- if(nint(a(4)).eq.180) a(4)=0.
- ipol=nint(a(4)/45.0) + 1
- if(ipol.gt.4) ipol=ipol-4
-
- return
-end subroutine afc65b
+subroutine afc65b(cx,cy,npts,fsample,nflip,ipol,xpol,ndphi,a,ccfbest,dtbest) + + logical xpol + complex cx(npts) + complex cy(npts) + real a(5),deltaa(5) + + a(1)=0. + a(2)=0. + a(3)=0. + a(4)=45.0*(ipol-1.0) + deltaa(1)=2.0 + deltaa(2)=2.0 + deltaa(3)=2.0 + deltaa(4)=22.5 + deltaa(5)=0.05 + nterms=3 + if(xpol) nterms=4 + +! Don't fit polarization when solving for dphi + if(ndphi.ne.0) nterms=3 + +! Start the iteration + chisqr=0. + chisqr0=1.e6 + do iter=1,3 !One iteration is enough? + do j=1,nterms + chisq1=fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax) + fn=0. + delta=deltaa(j) +10 a(j)=a(j)+delta + chisq2=fchisq(cx,cy,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=fchisq(cx,cy,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=fchisq(cx,cy,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 + + if(a(4).lt.0.0) a(4)=a(4)+180.0 + if(a(4).ge.180.0) a(4)=a(4)-180.0 + if(nint(a(4)).eq.180) a(4)=0. + ipol=nint(a(4)/45.0) + 1 + if(ipol.gt.4) ipol=ipol-4 + + return +end subroutine afc65b diff --git a/map65/libm65/astro.f90 b/map65/libm65/astro.f90 index 60452690..d34819cc 100755..100644 --- a/map65/libm65/astro.f90 +++ b/map65/libm65/astro.f90 @@ -1,105 +1,105 @@ -subroutine astro(nyear,month,nday,uth,nfreq,Mygrid,NStation,MoonDX, &
- AzSun,ElSun,AzMoon0,ElMoon0,ntsky,doppler00,doppler,dbMoon,RAMoon, &
- DecMoon,HA,Dgrd,sd,poloffset,xnr,day,lon,lat,LST)
-
-! Computes astronomical quantities for display and tracking.
-! NB: may want to smooth the Tsky map to 10 degrees or so.
-
- character*6 MyGrid,HisGrid
- real LST
- real lat,lon
- integer*2 nt144(180)
-
-! common/echo/xdop(2),techo,AzMoon,ElMoon,mjd
- real xdop(2)
-
- data rad/57.2957795/
- data nt144/ &
- 234, 246, 257, 267, 275, 280, 283, 286, 291, 298, &
- 305, 313, 322, 331, 341, 351, 361, 369, 376, 381, &
- 383, 382, 379, 374, 370, 366, 363, 361, 363, 368, &
- 376, 388, 401, 415, 428, 440, 453, 467, 487, 512, &
- 544, 579, 607, 618, 609, 588, 563, 539, 512, 482, &
- 450, 422, 398, 379, 363, 349, 334, 319, 302, 282, &
- 262, 242, 226, 213, 205, 200, 198, 197, 196, 197, &
- 200, 202, 204, 205, 204, 203, 202, 201, 203, 206, &
- 212, 218, 223, 227, 231, 236, 240, 243, 247, 257, &
- 276, 301, 324, 339, 346, 344, 339, 331, 323, 316, &
- 312, 310, 312, 317, 327, 341, 358, 375, 392, 407, &
- 422, 437, 451, 466, 480, 494, 511, 530, 552, 579, &
- 612, 653, 702, 768, 863,1008,1232,1557,1966,2385, &
- 2719,2924,3018,3038,2986,2836,2570,2213,1823,1461, &
- 1163, 939, 783, 677, 602, 543, 494, 452, 419, 392, &
- 373, 360, 353, 350, 350, 350, 350, 350, 350, 348, &
- 344, 337, 329, 319, 307, 295, 284, 276, 272, 272, &
- 273, 274, 274, 271, 266, 260, 252, 245, 238, 231/
- save
-
- call grid2deg(MyGrid,elon,lat)
- lon=-elon
- call sun(nyear,month,nday,uth,lon,lat,RASun,DecSun,LST,AzSun,ElSun,mjd,day)
-
- freq=nfreq*1.e6
- if(nfreq.eq.2) freq=1.8e6
- if(nfreq.eq.4) freq=3.5e6
-
- call MoonDop(nyear,month,nday,uth,lon,lat,RAMoon,DecMoon,LST,HA, &
- AzMoon,ElMoon,vr,dist)
-
-! Compute spatial polarization offset
- xx=sin(lat/rad)*cos(ElMoon/rad) - cos(lat/rad)*cos(AzMoon/rad)*sin(ElMoon/rad)
- yy=cos(lat/rad)*sin(AzMoon/rad)
- if(NStation.eq.1) poloffset1=rad*atan2(yy,xx)
- if(NStation.eq.2) poloffset2=rad*atan2(yy,xx)
-
- techo=2.0 * dist/2.99792458e5 !Echo delay time
- doppler=-freq*vr/2.99792458e5 !One-way Doppler
-
- call coord(0.,0.,-1.570796,1.161639,RAMoon/rad,DecMoon/rad,el,eb)
- longecl_half=nint(rad*el/2.0)
- if(longecl_half.lt.1 .or. longecl_half.gt.180) longecl_half=180
- t144=nt144(longecl_half)
- tsky=(t144-2.7)*(144.0/nfreq)**2.6 + 2.7 !Tsky for obs freq
-
- xdop(NStation)=doppler
- if(NStation.eq.2) then
- HisGrid=MyGrid
- go to 900
- endif
-
- doppler00=2.0*xdop(1)
- doppler=xdop(1)+xdop(2)
-! if(mode.eq.3) doppler=2.0*xdop(1)
- dBMoon=-40.0*log10(dist/356903.)
- sd=16.23*370152.0/dist
-
-! if(NStation.eq.1 .and. MoonDX.ne.0 .and.
-! + (mode.eq.2 .or. mode.eq.5)) then
- if(NStation.eq.1 .and. MoonDX.ne.0) then
- poloffset=mod(poloffset2-poloffset1+720.0,180.0)
- if(poloffset.gt.90.0) poloffset=poloffset-180.0
- x1=abs(cos(2*poloffset/rad))
- if(x1.lt.0.056234) x1=0.056234
- xnr=-20.0*log10(x1)
- if(HisGrid(1:1).lt.'A' .or. HisGrid(1:1).gt.'R') xnr=0
- endif
-
- tr=80.0 !Good preamp
- tskymin=13.0*(408.0/nfreq)**2.6 !Cold sky temperature
- tsysmin=tskymin+tr
- tsys=tsky+tr
- dgrd=-10.0*log10(tsys/tsysmin) + dbMoon
-900 AzMoon0=Azmoon
- ElMoon0=Elmoon
- ntsky=nint(tsky)
-
-! auxHA = 15.0*(LST-auxra) !HA in degrees
-! pi=3.14159265
-! pio2=0.5*pi
-! call coord(pi,pio2-lat/rad,0.0,lat/rad,auxha*pi/180.0,
-! + auxdec/rad,azaux,elaux)
-! AzAux=azaux*rad
-! ElAux=ElAux*rad
-
- return
-end subroutine astro
+subroutine astro(nyear,month,nday,uth,nfreq,Mygrid,NStation,MoonDX, & + AzSun,ElSun,AzMoon0,ElMoon0,ntsky,doppler00,doppler,dbMoon,RAMoon, & + DecMoon,HA,Dgrd,sd,poloffset,xnr,day,lon,lat,LST) + +! Computes astronomical quantities for display and tracking. +! NB: may want to smooth the Tsky map to 10 degrees or so. + + character*6 MyGrid,HisGrid + real LST + real lat,lon + integer*2 nt144(180) + +! common/echo/xdop(2),techo,AzMoon,ElMoon,mjd + real xdop(2) + + data rad/57.2957795/ + data nt144/ & + 234, 246, 257, 267, 275, 280, 283, 286, 291, 298, & + 305, 313, 322, 331, 341, 351, 361, 369, 376, 381, & + 383, 382, 379, 374, 370, 366, 363, 361, 363, 368, & + 376, 388, 401, 415, 428, 440, 453, 467, 487, 512, & + 544, 579, 607, 618, 609, 588, 563, 539, 512, 482, & + 450, 422, 398, 379, 363, 349, 334, 319, 302, 282, & + 262, 242, 226, 213, 205, 200, 198, 197, 196, 197, & + 200, 202, 204, 205, 204, 203, 202, 201, 203, 206, & + 212, 218, 223, 227, 231, 236, 240, 243, 247, 257, & + 276, 301, 324, 339, 346, 344, 339, 331, 323, 316, & + 312, 310, 312, 317, 327, 341, 358, 375, 392, 407, & + 422, 437, 451, 466, 480, 494, 511, 530, 552, 579, & + 612, 653, 702, 768, 863,1008,1232,1557,1966,2385, & + 2719,2924,3018,3038,2986,2836,2570,2213,1823,1461, & + 1163, 939, 783, 677, 602, 543, 494, 452, 419, 392, & + 373, 360, 353, 350, 350, 350, 350, 350, 350, 348, & + 344, 337, 329, 319, 307, 295, 284, 276, 272, 272, & + 273, 274, 274, 271, 266, 260, 252, 245, 238, 231/ + save + + call grid2deg(MyGrid,elon,lat) + lon=-elon + call sun(nyear,month,nday,uth,lon,lat,RASun,DecSun,LST,AzSun,ElSun,mjd,day) + + freq=nfreq*1.e6 + if(nfreq.eq.2) freq=1.8e6 + if(nfreq.eq.4) freq=3.5e6 + + call MoonDop(nyear,month,nday,uth,lon,lat,RAMoon,DecMoon,LST,HA, & + AzMoon,ElMoon,vr,dist) + +! Compute spatial polarization offset + xx=sin(lat/rad)*cos(ElMoon/rad) - cos(lat/rad)*cos(AzMoon/rad)*sin(ElMoon/rad) + yy=cos(lat/rad)*sin(AzMoon/rad) + if(NStation.eq.1) poloffset1=rad*atan2(yy,xx) + if(NStation.eq.2) poloffset2=rad*atan2(yy,xx) + + techo=2.0 * dist/2.99792458e5 !Echo delay time + doppler=-freq*vr/2.99792458e5 !One-way Doppler + + call coord(0.,0.,-1.570796,1.161639,RAMoon/rad,DecMoon/rad,el,eb) + longecl_half=nint(rad*el/2.0) + if(longecl_half.lt.1 .or. longecl_half.gt.180) longecl_half=180 + t144=nt144(longecl_half) + tsky=(t144-2.7)*(144.0/nfreq)**2.6 + 2.7 !Tsky for obs freq + + xdop(NStation)=doppler + if(NStation.eq.2) then + HisGrid=MyGrid + go to 900 + endif + + doppler00=2.0*xdop(1) + doppler=xdop(1)+xdop(2) +! if(mode.eq.3) doppler=2.0*xdop(1) + dBMoon=-40.0*log10(dist/356903.) + sd=16.23*370152.0/dist + +! if(NStation.eq.1 .and. MoonDX.ne.0 .and. +! + (mode.eq.2 .or. mode.eq.5)) then + if(NStation.eq.1 .and. MoonDX.ne.0) then + poloffset=mod(poloffset2-poloffset1+720.0,180.0) + if(poloffset.gt.90.0) poloffset=poloffset-180.0 + x1=abs(cos(2*poloffset/rad)) + if(x1.lt.0.056234) x1=0.056234 + xnr=-20.0*log10(x1) + if(HisGrid(1:1).lt.'A' .or. HisGrid(1:1).gt.'R') xnr=0 + endif + + tr=80.0 !Good preamp + tskymin=13.0*(408.0/nfreq)**2.6 !Cold sky temperature + tsysmin=tskymin+tr + tsys=tsky+tr + dgrd=-10.0*log10(tsys/tsysmin) + dbMoon +900 AzMoon0=Azmoon + ElMoon0=Elmoon + ntsky=nint(tsky) + +! auxHA = 15.0*(LST-auxra) !HA in degrees +! pi=3.14159265 +! pio2=0.5*pi +! call coord(pi,pio2-lat/rad,0.0,lat/rad,auxha*pi/180.0, +! + auxdec/rad,azaux,elaux) +! AzAux=azaux*rad +! ElAux=ElAux*rad + + return +end subroutine astro diff --git a/map65/libm65/astro0.f90 b/map65/libm65/astro0.f90 index ef37f7d2..ec234215 100755..100644 --- a/map65/libm65/astro0.f90 +++ b/map65/libm65/astro0.f90 @@ -1,81 +1,81 @@ -subroutine astro0(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, &
- AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, &
- dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, &
- width1,width2,w501,w502,xlst8)
-
- parameter (DEGS=57.2957795130823d0)
- character*6 mygrid,hisgrid
- real*8 AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8
- real*8 dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,xnr8,dfdt,dfdt0,dt
- real*8 sd8,poloffset8,day8,width1,width2,w501,w502,xlst8
- real*8 uth8
- data uth8z/0.d0/
- save
-
- uth=uth8
- call astro(nyear,month,nday,uth,nfreq,hisgrid,2,1, &
- AzSun,ElSun,AzMoon,ElMoon,ntsky,doppler00,doppler, &
- dbMoon,RAMoon,DecMoon,HA,Dgrd,sd,poloffset,xnr, &
- day,xlon2,xlat2,xlst)
- AzMoonB8=AzMoon
- ElMoonB8=ElMoon
- call astro(nyear,month,nday,uth,nfreq,mygrid,1,1, &
- AzSun,ElSun,AzMoon,ElMoon,ntsky,doppler00,doppler, &
- dbMoon,RAMoon,DecMoon,HA,Dgrd,sd,poloffset,xnr, &
- day,xlon1,xlat1,xlst)
-
- day8=day
- xlst8=xlst
- call tm2(day8,xlat1,xlon1,xl1,b1)
- call tm2(day8,xlat2,xlon2,xl2,b2)
- call tm2(day8+1.d0/1440.0,xlat1,xlon1,xl1a,b1a)
- call tm2(day8+1.d0/1440.0,xlat2,xlon2,xl2a,b2a)
- fghz=0.001*nfreq
- dldt1=DEGS*(xl1a-xl1)
- dbdt1=DEGS*(b1a-b1)
- dldt2=DEGS*(xl2a-xl2)
- dbdt2=DEGS*(b2a-b2)
- rate1=2.0*sqrt(dldt1**2 + dbdt1**2)
- width1=0.5*6741*fghz*rate1
- rate2=sqrt((dldt1+dldt2)**2 + (dbdt1+dbdt2)**2)
- width2=0.5*6741*fghz*rate2
-
- fbend=0.7
- a2=0.0045*log(fghz/fbend)/log(1.05)
- if(fghz.lt.fbend) a2=0.0
- f50=0.19 * (fghz/fbend)**a2
- if(f50.gt.1.0) f50=1.0
- w501=f50*width1
- w502=f50*width2
-
- AzSun8=AzSun
- ElSun8=ElSun
- AzMoon8=AzMoon
- ElMoon8=ElMoon
- dbMoon8=dbMoon
- RAMoon8=RAMoon/15.0
- DecMoon8=DecMoon
- HA8=HA
- Dgrd8=Dgrd
- sd8=sd
- poloffset8=poloffset
- xnr8=xnr
- ndop=nint(doppler)
- ndop00=nint(doppler00)
-
- if(uth8z.eq.0.d0) then
- uth8z=uth8-1.d0/3600.d0
- dopplerz=doppler
- doppler00z=doppler00
- endif
-
- dt=60.0*(uth8-uth8z)
- if(dt.le.0) dt=1.d0/60.d0
- dfdt=(doppler-dopplerz)/dt
- dfdt0=(doppler00-doppler00z)/dt
- uth8z=uth8
- dopplerz=doppler
- doppler00z=doppler00
-
- return
-end subroutine astro0
+subroutine astro0(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, & + AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & + dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, & + width1,width2,w501,w502,xlst8) + + parameter (DEGS=57.2957795130823d0) + character*6 mygrid,hisgrid + real*8 AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8 + real*8 dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,xnr8,dfdt,dfdt0,dt + real*8 sd8,poloffset8,day8,width1,width2,w501,w502,xlst8 + real*8 uth8 + data uth8z/0.d0/ + save + + uth=uth8 + call astro(nyear,month,nday,uth,nfreq,hisgrid,2,1, & + AzSun,ElSun,AzMoon,ElMoon,ntsky,doppler00,doppler, & + dbMoon,RAMoon,DecMoon,HA,Dgrd,sd,poloffset,xnr, & + day,xlon2,xlat2,xlst) + AzMoonB8=AzMoon + ElMoonB8=ElMoon + call astro(nyear,month,nday,uth,nfreq,mygrid,1,1, & + AzSun,ElSun,AzMoon,ElMoon,ntsky,doppler00,doppler, & + dbMoon,RAMoon,DecMoon,HA,Dgrd,sd,poloffset,xnr, & + day,xlon1,xlat1,xlst) + + day8=day + xlst8=xlst + call tm2(day8,xlat1,xlon1,xl1,b1) + call tm2(day8,xlat2,xlon2,xl2,b2) + call tm2(day8+1.d0/1440.0,xlat1,xlon1,xl1a,b1a) + call tm2(day8+1.d0/1440.0,xlat2,xlon2,xl2a,b2a) + fghz=0.001*nfreq + dldt1=DEGS*(xl1a-xl1) + dbdt1=DEGS*(b1a-b1) + dldt2=DEGS*(xl2a-xl2) + dbdt2=DEGS*(b2a-b2) + rate1=2.0*sqrt(dldt1**2 + dbdt1**2) + width1=0.5*6741*fghz*rate1 + rate2=sqrt((dldt1+dldt2)**2 + (dbdt1+dbdt2)**2) + width2=0.5*6741*fghz*rate2 + + fbend=0.7 + a2=0.0045*log(fghz/fbend)/log(1.05) + if(fghz.lt.fbend) a2=0.0 + f50=0.19 * (fghz/fbend)**a2 + if(f50.gt.1.0) f50=1.0 + w501=f50*width1 + w502=f50*width2 + + AzSun8=AzSun + ElSun8=ElSun + AzMoon8=AzMoon + ElMoon8=ElMoon + dbMoon8=dbMoon + RAMoon8=RAMoon/15.0 + DecMoon8=DecMoon + HA8=HA + Dgrd8=Dgrd + sd8=sd + poloffset8=poloffset + xnr8=xnr + ndop=nint(doppler) + ndop00=nint(doppler00) + + if(uth8z.eq.0.d0) then + uth8z=uth8-1.d0/3600.d0 + dopplerz=doppler + doppler00z=doppler00 + endif + + dt=60.0*(uth8-uth8z) + if(dt.le.0) dt=1.d0/60.d0 + dfdt=(doppler-dopplerz)/dt + dfdt0=(doppler00-doppler00z)/dt + uth8z=uth8 + dopplerz=doppler + doppler00z=doppler00 + + return +end subroutine astro0 diff --git a/map65/libm65/astrosub.f90 b/map65/libm65/astrosub.f90 index 5704df57..ce25a0d9 100755..100644 --- a/map65/libm65/astrosub.f90 +++ b/map65/libm65/astrosub.f90 @@ -1,26 +1,26 @@ -subroutine astrosub(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, &
- AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, &
- RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8)
-
- implicit real*8 (a-h,o-z)
- character*6 mygrid,hisgrid
-
- call astro0(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, &
- AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, &
- dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, &
- width1,width2,w501,w502,xlst8)
-
- return
-end subroutine astrosub
-
-subroutine astrosub00(nyear,month,nday,uth8,nfreq,mygrid,ndop00)
-
- implicit real*8 (a-h,o-z)
- character*6 mygrid
-
- call astrosub(nyear,month,nday,uth8,nfreq,mygrid,mygrid, &
- AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, &
- RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8)
-
- return
-end subroutine astrosub00
+subroutine astrosub(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, & + AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & + RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8) + + implicit real*8 (a-h,o-z) + character*6 mygrid,hisgrid + + call astro0(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, & + AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & + dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, & + width1,width2,w501,w502,xlst8) + + return +end subroutine astrosub + +subroutine astrosub00(nyear,month,nday,uth8,nfreq,mygrid,ndop00) + + implicit real*8 (a-h,o-z) + character*6 mygrid + + call astrosub(nyear,month,nday,uth8,nfreq,mygrid,mygrid, & + AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & + RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8) + + return +end subroutine astrosub00 diff --git a/map65/libm65/averms.f90 b/map65/libm65/averms.f90 index d4f41846..904004c8 100755..100644 --- a/map65/libm65/averms.f90 +++ b/map65/libm65/averms.f90 @@ -1,20 +1,20 @@ -subroutine averms(x,n,nskip,ave,rms)
- real x(n)
- integer ipk(1)
-
- ns=0
- s=0.
- sq=0.
- ipk=maxloc(x)
- do i=1,n
- if(abs(i-ipk(1)).gt.nskip) then
- s=s + x(i)
- sq=sq + x(i)**2
- ns=ns+1
- endif
- enddo
- ave=s/ns
- rms=sqrt(sq/ns - ave*ave)
-
- return
-end subroutine averms
+subroutine averms(x,n,nskip,ave,rms) + real x(n) + integer ipk(1) + + ns=0 + s=0. + sq=0. + ipk=maxloc(x) + do i=1,n + if(abs(i-ipk(1)).gt.nskip) then + s=s + x(i) + sq=sq + x(i)**2 + ns=ns+1 + endif + enddo + ave=s/ns + rms=sqrt(sq/ns - ave*ave) + + return +end subroutine averms diff --git a/map65/libm65/badmsg.f90 b/map65/libm65/badmsg.f90 index 1ebc1251..007da8a8 100755..100644 --- a/map65/libm65/badmsg.f90 +++ b/map65/libm65/badmsg.f90 @@ -1,46 +1,46 @@ -subroutine badmsg(irc,dat,nc1,nc2,ng2)
-
-! Get rid of a few QRA64 false decodes that cannot be correct messages.
-
- integer dat(12) !Decoded message (as 12 integers)
-
- ic1=ishft(dat(1),22) + ishft(dat(2),16) + ishft(dat(3),10)+ &
- ishft(dat(4),4) + iand(ishft(dat(5),-2),15)
-
-! Test for "......" or "CQ 000"
- if(ic1.eq.262177560 .or. ic1.eq.262177563) then
- irc=-1
- return
- endif
-
- ic2=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)
-
- ig=ishft(iand(dat(10),15),12) + ishft(dat(11),6) + dat(12)
-
-! Test for blank, -01 to -30, R-01 to R-30, RO, RRR, 73
- if(ig.ge.32401 .and. ig.le.32464) return
-
- if(ig.ge.14220 .and. ig.le.14229) return !-41 to -50
- if(ig.ge.14040 .and. ig.le.14049) return !-31 to -40
-
- if(ig.ge.13320 .and. ig.le.13329) return !+00 to +09
- if(ig.ge.13140 .and. ig.le.13149) return !+10 to +19
- if(ig.ge.12960 .and. ig.le.12969) return !+20 to +29
- if(ig.ge.12780 .and. ig.le.12789) return !+30 to +39
- if(ig.ge.12600 .and. ig.le.12609) return !+40 to +49
-
- if(ig.ge.12420 .and. ig.le.12429) return !R-41 to R-50
- if(ig.ge.12240 .and. ig.le.12249) return !R-31 to R-40
-
- if(ig.ge.11520 .and. ig.le.11529) return !R+00 to R+09
- if(ig.ge.11340 .and. ig.le.11349) return !R+10 to R+19
- if(ig.ge.11160 .and. ig.le.11169) return !R+20 to R+29
- if(ig.ge.10980 .and. ig.le.10989) return !R+30 to R+39
- if(ig.ge.10800 .and. ig.le.10809) return !R+40 to R+49
-
- if(ic1.eq.nc1 .and. ic2.eq.nc2 .and. ng2.ne.32401 .and. ig.ne.ng2) irc=-1
-
- return
-end subroutine badmsg
+subroutine badmsg(irc,dat,nc1,nc2,ng2) + +! Get rid of a few QRA64 false decodes that cannot be correct messages. + + integer dat(12) !Decoded message (as 12 integers) + + ic1=ishft(dat(1),22) + ishft(dat(2),16) + ishft(dat(3),10)+ & + ishft(dat(4),4) + iand(ishft(dat(5),-2),15) + +! Test for "......" or "CQ 000" + if(ic1.eq.262177560 .or. ic1.eq.262177563) then + irc=-1 + return + endif + + ic2=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) + + ig=ishft(iand(dat(10),15),12) + ishft(dat(11),6) + dat(12) + +! Test for blank, -01 to -30, R-01 to R-30, RO, RRR, 73 + if(ig.ge.32401 .and. ig.le.32464) return + + if(ig.ge.14220 .and. ig.le.14229) return !-41 to -50 + if(ig.ge.14040 .and. ig.le.14049) return !-31 to -40 + + if(ig.ge.13320 .and. ig.le.13329) return !+00 to +09 + if(ig.ge.13140 .and. ig.le.13149) return !+10 to +19 + if(ig.ge.12960 .and. ig.le.12969) return !+20 to +29 + if(ig.ge.12780 .and. ig.le.12789) return !+30 to +39 + if(ig.ge.12600 .and. ig.le.12609) return !+40 to +49 + + if(ig.ge.12420 .and. ig.le.12429) return !R-41 to R-50 + if(ig.ge.12240 .and. ig.le.12249) return !R-31 to R-40 + + if(ig.ge.11520 .and. ig.le.11529) return !R+00 to R+09 + if(ig.ge.11340 .and. ig.le.11349) return !R+10 to R+19 + if(ig.ge.11160 .and. ig.le.11169) return !R+20 to R+29 + if(ig.ge.10980 .and. ig.le.10989) return !R+30 to R+39 + if(ig.ge.10800 .and. ig.le.10809) return !R+40 to R+49 + + if(ic1.eq.nc1 .and. ic2.eq.nc2 .and. ng2.ne.32401 .and. ig.ne.ng2) irc=-1 + + return +end subroutine badmsg diff --git a/map65/libm65/ccf2.f90 b/map65/libm65/ccf2.f90 index 4b264f56..287e70ff 100755..100644 --- a/map65/libm65/ccf2.f90 +++ b/map65/libm65/ccf2.f90 @@ -1,45 +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
+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/map65/libm65/ccf65.f90 b/map65/libm65/ccf65.f90 index 64f9d9db..592fe95e 100755..100644 --- a/map65/libm65/ccf65.f90 +++ b/map65/libm65/ccf65.f90 @@ -1,128 +1,128 @@ -subroutine ccf65(ss,nhsym,ssmax,sync1,ipol1,jpz,dt1,flipk, &
- syncshort,snr2,ipol2,dt2)
-
- parameter (NFFT=512,NH=NFFT/2)
- real ss(4,322) !Input: half-symbol powers, 4 pol'ns
- 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,4)
- 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
- syncshort=0.
- snr2=0.
-
-! Look for JT65 sync pattern and shorthand square-wave pattern.
- ccfbest=0.
- ccfbest2=0.
- ipol1=1
- ipol2=1
- do ip=1,jpz !Do jpz polarizations
- do i=1,nhsym-1
-! s(i)=ss(ip,i)+ss(ip,i+1)
- s(i)=min(ssmax,ss(ip,i)+ss(ip,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,ip)=s(j)
- if(abs(ccf(lag,ip)).gt.ccfbest) then
- ccfbest=abs(ccf(lag,ip))
- lagpk=lag
- ipol1=ip
- flipk=1.0
- if(ccf(lag,ip).lt.0.0) flipk=-1.0
- endif
- enddo
-
-!### Not sure why this is ever true???
- if(sum(ccf).eq.0.0) return
-!###
- do lag=-11,54 !Check for best shorthand
- ccf2=s2(lag+28)
- if(ccf2.gt.ccfbest2) then
- ccfbest2=ccf2
- lagpk2=lag
- ipol2=ip
- endif
- enddo
-
- enddo
-
-! Find rms level on baseline of "ccfblue", for normalization.
- sumccf=0.
- do lag=-11,54
- if(abs(lag-lagpk).gt.1) sumccf=sumccf + ccf(lag,ipol1)
- enddo
- base=sumccf/50.0
- sq=0.
- do lag=-11,54
- if(abs(lag-lagpk).gt.1) sq=sq + (ccf(lag,ipol1)-base)**2
- enddo
- rms=sqrt(sq/49.0)
- sync1=-4.0
- if(rms.gt.0.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(ipol2,i)
- enddo
- call pctile(tmp1,nhsym,40,base)
- snr2=0.01
- if(base.gt.0.0) 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)
-
- return
-end subroutine ccf65
+subroutine ccf65(ss,nhsym,ssmax,sync1,ipol1,jpz,dt1,flipk, & + syncshort,snr2,ipol2,dt2) + + parameter (NFFT=512,NH=NFFT/2) + real ss(4,322) !Input: half-symbol powers, 4 pol'ns + 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,4) + 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 + syncshort=0. + snr2=0. + +! Look for JT65 sync pattern and shorthand square-wave pattern. + ccfbest=0. + ccfbest2=0. + ipol1=1 + ipol2=1 + do ip=1,jpz !Do jpz polarizations + do i=1,nhsym-1 +! s(i)=ss(ip,i)+ss(ip,i+1) + s(i)=min(ssmax,ss(ip,i)+ss(ip,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,ip)=s(j) + if(abs(ccf(lag,ip)).gt.ccfbest) then + ccfbest=abs(ccf(lag,ip)) + lagpk=lag + ipol1=ip + flipk=1.0 + if(ccf(lag,ip).lt.0.0) flipk=-1.0 + endif + enddo + +!### Not sure why this is ever true??? + if(sum(ccf).eq.0.0) return +!### + do lag=-11,54 !Check for best shorthand + ccf2=s2(lag+28) + if(ccf2.gt.ccfbest2) then + ccfbest2=ccf2 + lagpk2=lag + ipol2=ip + endif + enddo + + enddo + +! Find rms level on baseline of "ccfblue", for normalization. + sumccf=0. + do lag=-11,54 + if(abs(lag-lagpk).gt.1) sumccf=sumccf + ccf(lag,ipol1) + enddo + base=sumccf/50.0 + sq=0. + do lag=-11,54 + if(abs(lag-lagpk).gt.1) sq=sq + (ccf(lag,ipol1)-base)**2 + enddo + rms=sqrt(sq/49.0) + sync1=-4.0 + if(rms.gt.0.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(ipol2,i) + enddo + call pctile(tmp1,nhsym,40,base) + snr2=0.01 + if(base.gt.0.0) 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) + + return +end subroutine ccf65 diff --git a/map65/libm65/cgen65.f90 b/map65/libm65/cgen65.f90 index 2f653ffa..096e9790 100755..100644 --- a/map65/libm65/cgen65.f90 +++ b/map65/libm65/cgen65.f90 @@ -1,99 +1,99 @@ -subroutine cgen65(message,mode65,samfac,nsendingsh,msgsent,cwave,nwave)
-
-! Encodes a JT65 message into a wavefile.
-! Executes in 17 ms on opti-745.
-
- use packjt
-
- parameter (NMAX=60*96000) !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,twopi,samfac,tsymbol
- complex cwave(NMAX) !Generated complex wave file
- integer dgen(12)
- integer sent(63)
- logical first
- integer nprc(126)
- real pr(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/
- data twopi/6.283185307179586476d0/,first/.true./
- save
-
- if(first) then
- do i=1,126
- pr(i)=2*nprc(i)-1
- enddo
- first=.false.
- endif
-
- call chkmsg(message,cok,nspecial,flip) !See if it's a shorthand
- if(nspecial.eq.0) then
- call packmsg(message,dgen,itype) !Pack message into 72 bits
- nsendingsh=0
- if(iand(dgen(10),8).ne.0) nsendingsh=-1 !Plain text flag
-
- call rs_encode(dgen,sent)
- call interleave63(sent,1) !Apply interleaving
- call graycode(sent,63,1) !Apply Gray code
- nsym=126 !Symbols per transmission
- tsymbol=4096.d0/11025.d0 !Time per symbol
- else
- nsendingsh=1 !Flag for shorthand message
- nsym=32
- tsymbol=16384.d0/11025.d0
- endif
-
-! Set up necessary constants
- dt=1.d0/(samfac*96000.d0)
- f0=118*11025.d0/1024
- dfgen=mode65*11025.d0/4096.d0
- t=0.d0
- phi=0.d0
- k=0
- j0=0
- ndata=nsym*96000.d0*samfac*tsymbol
-
- do i=1,ndata
- t=t+dt
- j=int(t/tsymbol) + 1 !Symbol number, 1-126
- if(j.ne.j0) then
- f=f0
- if(nspecial.ne.0 .and. mod(j,2).eq.0) f=f0+10*nspecial*dfgen
- if(nspecial.eq.0 .and. flip*pr(j).lt.0.0) then
- k=k+1
- f=f0+(sent(k)+2)*dfgen
- endif
- dphi=twopi*dt*f
- j0=j
- endif
- phi=phi+dphi
- if(phi.gt.twopi) phi=phi-twopi
- xphi=phi
- cwave(i)=cmplx(cos(xphi),-sin(xphi))
- enddo
-
- cwave(ndata+1:)=0
- nwave=ndata + 48000
- call unpackmsg(dgen,msgsent)
- 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
-
- if(nsendingsh.eq.1) then
- if(nspecial.eq.2) msgsent='RO'
- if(nspecial.eq.3) msgsent='RRR'
- if(nspecial.eq.4) msgsent='73'
- endif
-
- return
-end subroutine cgen65
+subroutine cgen65(message,mode65,samfac,nsendingsh,msgsent,cwave,nwave) + +! Encodes a JT65 message into a wavefile. +! Executes in 17 ms on opti-745. + + use packjt + + parameter (NMAX=60*96000) !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,twopi,samfac,tsymbol + complex cwave(NMAX) !Generated complex wave file + integer dgen(12) + integer sent(63) + logical first + integer nprc(126) + real pr(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/ + data twopi/6.283185307179586476d0/,first/.true./ + save + + if(first) then + do i=1,126 + pr(i)=2*nprc(i)-1 + enddo + first=.false. + endif + + call chkmsg(message,cok,nspecial,flip) !See if it's a shorthand + if(nspecial.eq.0) then + call packmsg(message,dgen,itype) !Pack message into 72 bits + nsendingsh=0 + if(iand(dgen(10),8).ne.0) nsendingsh=-1 !Plain text flag + + call rs_encode(dgen,sent) + call interleave63(sent,1) !Apply interleaving + call graycode(sent,63,1) !Apply Gray code + nsym=126 !Symbols per transmission + tsymbol=4096.d0/11025.d0 !Time per symbol + else + nsendingsh=1 !Flag for shorthand message + nsym=32 + tsymbol=16384.d0/11025.d0 + endif + +! Set up necessary constants + dt=1.d0/(samfac*96000.d0) + f0=118*11025.d0/1024 + dfgen=mode65*11025.d0/4096.d0 + t=0.d0 + phi=0.d0 + k=0 + j0=0 + ndata=nsym*96000.d0*samfac*tsymbol + + do i=1,ndata + t=t+dt + j=int(t/tsymbol) + 1 !Symbol number, 1-126 + if(j.ne.j0) then + f=f0 + if(nspecial.ne.0 .and. mod(j,2).eq.0) f=f0+10*nspecial*dfgen + if(nspecial.eq.0 .and. flip*pr(j).lt.0.0) then + k=k+1 + f=f0+(sent(k)+2)*dfgen + endif + dphi=twopi*dt*f + j0=j + endif + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + cwave(i)=cmplx(cos(xphi),-sin(xphi)) + enddo + + cwave(ndata+1:)=0 + nwave=ndata + 48000 + call unpackmsg(dgen,msgsent) + 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 + + if(nsendingsh.eq.1) then + if(nspecial.eq.2) msgsent='RO' + if(nspecial.eq.3) msgsent='RRR' + if(nspecial.eq.4) msgsent='73' + endif + + return +end subroutine cgen65 diff --git a/map65/libm65/chkhist.f90 b/map65/libm65/chkhist.f90 index a8b272a6..c814c3ca 100755..100644 --- a/map65/libm65/chkhist.f90 +++ b/map65/libm65/chkhist.f90 @@ -1,23 +1,23 @@ -subroutine chkhist(mrsym,nmax,ipk)
-
- integer mrsym(63)
- integer hist(0:63)
-
- do i=0,63
- hist(i)=0
- enddo
- 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
+subroutine chkhist(mrsym,nmax,ipk) + + integer mrsym(63) + integer hist(0:63) + + do i=0,63 + hist(i)=0 + enddo + 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/map65/libm65/chkmsg.f90 b/map65/libm65/chkmsg.f90 index 798ee45f..457a8092 100755..100644 --- a/map65/libm65/chkmsg.f90 +++ b/map65/libm65/chkmsg.f90 @@ -1,31 +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:3).eq.'RO ') nspecial=2
- if(message(1:4).eq.'RRR ') nspecial=3
- if(message(1:3).eq.'73 ') nspecial=4
-
- return
-end subroutine chkmsg
+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:3).eq.'RO ') nspecial=2 + if(message(1:4).eq.'RRR ') nspecial=3 + if(message(1:3).eq.'73 ') nspecial=4 + + return +end subroutine chkmsg diff --git a/map65/libm65/coord.f90 b/map65/libm65/coord.f90 index 2ad8273c..8934b612 100755..100644 --- a/map65/libm65/coord.f90 +++ b/map65/libm65/coord.f90 @@ -1,40 +1,40 @@ -SUBROUTINE COORD(A0,B0,AP,BP,A1,B1,A2,B2)
-
-! Examples:
-! 1. From ha,dec to az,el:
-! call coord(pi,pio2-lat,0.,lat,ha,dec,az,el)
-! 2. From az,el to ha,dec:
-! call coord(pi,pio2-lat,0.,lat,az,el,ha,dec)
-! 3. From ra,dec to l,b
-! call coord(4.635594495,-0.504691042,3.355395488,0.478220215,
-! ra,dec,l,b)
-! 4. From l,b to ra,dec
-! call coord(1.705981071d0,-1.050357016d0,2.146800277d0,
-! 0.478220215d0,l,b,ra,dec)
-! 5. From ra,dec to ecliptic latitude (eb) and longitude (el):
-! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,ra,dec,el,eb)
-! 6. From ecliptic latitude (eb) and longitude (el) to ra,dec:
-! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,el,eb,ra,dec)
-
- SB0=sin(B0)
- CB0=cos(B0)
- SBP=sin(BP)
- CBP=cos(BP)
- SB1=sin(B1)
- CB1=cos(B1)
- SB2=SBP*SB1 + CBP*CB1*cos(AP-A1)
- CB2=SQRT(1.e0-SB2**2)
- B2=atan(SB2/CB2)
- SAA=sin(AP-A1)*CB1/CB2
- CAA=(SB1-SB2*SBP)/(CB2*CBP)
- CBB=SB0/CBP
- SBB=sin(AP-A0)*CB0
- SA2=SAA*CBB-CAA*SBB
- CA2=CAA*CBB+SAA*SBB
- TA2O2=0.0 !Shut up compiler warnings. -db
- IF(CA2.LE.0.e0) TA2O2=(1.e0-CA2)/SA2
- IF(CA2.GT.0.e0) TA2O2=SA2/(1.e0+CA2)
- A2=2.e0*atan(TA2O2)
- IF(A2.LT.0.e0) A2=A2+6.2831853
- RETURN
-END SUBROUTINE COORD
+SUBROUTINE COORD(A0,B0,AP,BP,A1,B1,A2,B2) + +! Examples: +! 1. From ha,dec to az,el: +! call coord(pi,pio2-lat,0.,lat,ha,dec,az,el) +! 2. From az,el to ha,dec: +! call coord(pi,pio2-lat,0.,lat,az,el,ha,dec) +! 3. From ra,dec to l,b +! call coord(4.635594495,-0.504691042,3.355395488,0.478220215, +! ra,dec,l,b) +! 4. From l,b to ra,dec +! call coord(1.705981071d0,-1.050357016d0,2.146800277d0, +! 0.478220215d0,l,b,ra,dec) +! 5. From ra,dec to ecliptic latitude (eb) and longitude (el): +! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,ra,dec,el,eb) +! 6. From ecliptic latitude (eb) and longitude (el) to ra,dec: +! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,el,eb,ra,dec) + + SB0=sin(B0) + CB0=cos(B0) + SBP=sin(BP) + CBP=cos(BP) + SB1=sin(B1) + CB1=cos(B1) + SB2=SBP*SB1 + CBP*CB1*cos(AP-A1) + CB2=SQRT(1.e0-SB2**2) + B2=atan(SB2/CB2) + SAA=sin(AP-A1)*CB1/CB2 + CAA=(SB1-SB2*SBP)/(CB2*CBP) + CBB=SB0/CBP + SBB=sin(AP-A0)*CB0 + SA2=SAA*CBB-CAA*SBB + CA2=CAA*CBB+SAA*SBB + TA2O2=0.0 !Shut up compiler warnings. -db + IF(CA2.LE.0.e0) TA2O2=(1.e0-CA2)/SA2 + IF(CA2.GT.0.e0) TA2O2=SA2/(1.e0+CA2) + A2=2.e0*atan(TA2O2) + IF(A2.LT.0.e0) A2=A2+6.2831853 + RETURN +END SUBROUTINE COORD diff --git a/map65/libm65/cutil.c b/map65/libm65/cutil.c index dda7d6ba..69a526b0 100755..100644 --- a/map65/libm65/cutil.c +++ b/map65/libm65/cutil.c @@ -1,93 +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);
-}
+#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/map65/libm65/dcoord.f90 b/map65/libm65/dcoord.f90 index 1669ebe2..5ef6877a 100755..100644 --- a/map65/libm65/dcoord.f90 +++ b/map65/libm65/dcoord.f90 @@ -1,40 +1,40 @@ -SUBROUTINE DCOORD(A0,B0,AP,BP,A1,B1,A2,B2)
-
- implicit real*8 (a-h,o-z)
-! Examples:
-! 1. From ha,dec to az,el:
-! call coord(pi,pio2-lat,0.,lat,ha,dec,az,el)
-! 2. From az,el to ha,dec:
-! call coord(pi,pio2-lat,0.,lat,az,el,ha,dec)
-! 3. From ra,dec to l,b
-! call coord(4.635594495,-0.504691042,3.355395488,0.478220215,
-! ra,dec,l,b)
-! 4. From l,b to ra,dec
-! call coord(1.705981071d0,-1.050357016d0,2.146800277d0,
-! 0.478220215d0,l,b,ra,dec)
-! 5. From ecliptic latitude (eb) and longitude (el) to ra, dec:
-! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,ra,dec,el,eb)
-
- SB0=sin(B0)
- CB0=cos(B0)
- SBP=sin(BP)
- CBP=cos(BP)
- SB1=sin(B1)
- CB1=cos(B1)
- SB2=SBP*SB1 + CBP*CB1*cos(AP-A1)
- CB2=SQRT(1.D0-SB2**2)
- B2=atan(SB2/CB2)
- SAA=sin(AP-A1)*CB1/CB2
- CAA=(SB1-SB2*SBP)/(CB2*CBP)
- CBB=SB0/CBP
- SBB=sin(AP-A0)*CB0
- SA2=SAA*CBB-CAA*SBB
- CA2=CAA*CBB+SAA*SBB
- TA2O2=0.0 !Shut up compiler warnings. -db
- IF(CA2.LE.0.D0) TA2O2=(1.D0-CA2)/SA2
- IF(CA2.GT.0.D0) TA2O2=SA2/(1.D0+CA2)
- A2=2.D0*atan(TA2O2)
- IF(A2.LT.0.D0) A2=A2+6.2831853071795864D0
-
- RETURN
-END SUBROUTINE DCOORD
+SUBROUTINE DCOORD(A0,B0,AP,BP,A1,B1,A2,B2) + + implicit real*8 (a-h,o-z) +! Examples: +! 1. From ha,dec to az,el: +! call coord(pi,pio2-lat,0.,lat,ha,dec,az,el) +! 2. From az,el to ha,dec: +! call coord(pi,pio2-lat,0.,lat,az,el,ha,dec) +! 3. From ra,dec to l,b +! call coord(4.635594495,-0.504691042,3.355395488,0.478220215, +! ra,dec,l,b) +! 4. From l,b to ra,dec +! call coord(1.705981071d0,-1.050357016d0,2.146800277d0, +! 0.478220215d0,l,b,ra,dec) +! 5. From ecliptic latitude (eb) and longitude (el) to ra, dec: +! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,ra,dec,el,eb) + + SB0=sin(B0) + CB0=cos(B0) + SBP=sin(BP) + CBP=cos(BP) + SB1=sin(B1) + CB1=cos(B1) + SB2=SBP*SB1 + CBP*CB1*cos(AP-A1) + CB2=SQRT(1.D0-SB2**2) + B2=atan(SB2/CB2) + SAA=sin(AP-A1)*CB1/CB2 + CAA=(SB1-SB2*SBP)/(CB2*CBP) + CBB=SB0/CBP + SBB=sin(AP-A0)*CB0 + SA2=SAA*CBB-CAA*SBB + CA2=CAA*CBB+SAA*SBB + TA2O2=0.0 !Shut up compiler warnings. -db + IF(CA2.LE.0.D0) TA2O2=(1.D0-CA2)/SA2 + IF(CA2.GT.0.D0) TA2O2=SA2/(1.D0+CA2) + A2=2.D0*atan(TA2O2) + IF(A2.LT.0.D0) A2=A2+6.2831853071795864D0 + + RETURN +END SUBROUTINE DCOORD diff --git a/map65/libm65/decode0.f90 b/map65/libm65/decode0.f90 index aa4c83c5..438079f1 100755..100644 --- a/map65/libm65/decode0.f90 +++ b/map65/libm65/decode0.f90 @@ -1,71 +1,71 @@ -subroutine decode0(dd,ss,savg,nstandalone)
-
- use timer_module, only: timer
- parameter (NSMAX=60*96000)
-
- real*4 dd(4,NSMAX),ss(4,322,NFFT),savg(4,NFFT)
- real*8 fcenter
- integer hist(0:32768)
- logical ldecoded
- character mycall*12,hiscall*12,mygrid*6,hisgrid*6,datetime*20
- character mycall0*12,hiscall0*12,hisgrid0*6
- common/npar/fcenter,nutc,idphi,mousedf,mousefqso,nagain, &
- ndepth,ndiskdat,neme,newdat,nfa,nfb,nfcal,nfshift, &
- mcall3,nkeep,ntol,nxant,nrxlog,nfsample,nxpol,nmode, &
- ndop00,nsave,max_drift,nhsym,mycall,mygrid,hiscall,hisgrid,datetime
- common/early/nhsym1,nhsym2,ldecoded(32768)
- common/decodes/ndecodes
- data neme0/-99/,mcall3b/1/
- save
-
- call sec0(0,tquick)
- call timer('decode0 ',0)
- if(newdat.ne.0) then
- nz=96000*nhsym/5.3833
- hist=0
- do i=1,nz
- j1=min(abs(dd(1,i)),32768.0)
- hist(j1)=hist(j1)+1
- j2=min(abs(dd(2,i)),32768.0)
- hist(j2)=hist(j2)+1
- j3=min(abs(dd(3,i)),32768.0)
- hist(j3)=hist(j3)+1
- j4=min(abs(dd(4,i)),32768.0)
- hist(j4)=hist(j4)+1
- enddo
- m=0
- do i=0,32768
- m=m+hist(i)
- if(m.ge.2*nz) go to 10
- enddo
-10 rmsdd=1.5*i
- endif
- ndphi=0
- if(iand(nrxlog,8).ne.0) ndphi=1
-
- if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0 .or. &
- hisgrid.ne.hisgrid0 .or. mcall3.ne.0 .or. neme.ne.neme0) mcall3b=1
-
- mycall0=mycall
- hiscall0=hiscall
- hisgrid0=hisgrid
- neme0=neme
-
- call timer('map65a ',0)
- call map65a(dd,ss,savg,newdat,nutc,fcenter,ntol,idphi,nfa,nfb, &
- mousedf,mousefqso,nagain,ndecdone,nfshift,ndphi,max_drift, &
- nfcal,nkeep,mcall3b,nsum,nsave,nxant,mycall,mygrid, &
- neme,ndepth,nstandalone,hiscall,hisgrid,nhsym,nfsample, &
- ndiskdat,nxpol,nmode,ndop00)
- call timer('map65a ',1)
- call timer('decode0 ',1)
-
- call sec0(1,tdec)
- if(nhsym.eq.nhsym1) write(*,1010) nsum,nsave,nstandalone,nhsym,tdec
-1010 format('<EarlyFinished>',3i4,i6,f6.2)
- if(nhsym.eq.nhsym2) write(*,1012) nsum,nsave,nstandalone,nhsym,tdec,ndecodes
-1012 format('<DecodeFinished>',3i4,i6,f6.2,i5)
- flush(6)
-
- return
-end subroutine decode0
+subroutine decode0(dd,ss,savg,nstandalone) + + use timer_module, only: timer + parameter (NSMAX=60*96000) + + real*4 dd(4,NSMAX),ss(4,322,NFFT),savg(4,NFFT) + real*8 fcenter + integer hist(0:32768) + logical ldecoded + character mycall*12,hiscall*12,mygrid*6,hisgrid*6,datetime*20 + character mycall0*12,hiscall0*12,hisgrid0*6 + common/npar/fcenter,nutc,idphi,mousedf,mousefqso,nagain, & + ndepth,ndiskdat,neme,newdat,nfa,nfb,nfcal,nfshift, & + mcall3,nkeep,ntol,nxant,nrxlog,nfsample,nxpol,nmode, & + ndop00,nsave,max_drift,nhsym,mycall,mygrid,hiscall,hisgrid,datetime + common/early/nhsym1,nhsym2,ldecoded(32768) + common/decodes/ndecodes + data neme0/-99/,mcall3b/1/ + save + + call sec0(0,tquick) + call timer('decode0 ',0) + if(newdat.ne.0) then + nz=96000*nhsym/5.3833 + hist=0 + do i=1,nz + j1=min(abs(dd(1,i)),32768.0) + hist(j1)=hist(j1)+1 + j2=min(abs(dd(2,i)),32768.0) + hist(j2)=hist(j2)+1 + j3=min(abs(dd(3,i)),32768.0) + hist(j3)=hist(j3)+1 + j4=min(abs(dd(4,i)),32768.0) + hist(j4)=hist(j4)+1 + enddo + m=0 + do i=0,32768 + m=m+hist(i) + if(m.ge.2*nz) go to 10 + enddo +10 rmsdd=1.5*i + endif + ndphi=0 + if(iand(nrxlog,8).ne.0) ndphi=1 + + if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0 .or. & + hisgrid.ne.hisgrid0 .or. mcall3.ne.0 .or. neme.ne.neme0) mcall3b=1 + + mycall0=mycall + hiscall0=hiscall + hisgrid0=hisgrid + neme0=neme + + call timer('map65a ',0) + call map65a(dd,ss,savg,newdat,nutc,fcenter,ntol,idphi,nfa,nfb, & + mousedf,mousefqso,nagain,ndecdone,nfshift,ndphi,max_drift, & + nfcal,nkeep,mcall3b,nsum,nsave,nxant,mycall,mygrid, & + neme,ndepth,nstandalone,hiscall,hisgrid,nhsym,nfsample, & + ndiskdat,nxpol,nmode,ndop00) + call timer('map65a ',1) + call timer('decode0 ',1) + + call sec0(1,tdec) + if(nhsym.eq.nhsym1) write(*,1010) nsum,nsave,nstandalone,nhsym,tdec +1010 format('<EarlyFinished>',3i4,i6,f6.2) + if(nhsym.eq.nhsym2) write(*,1012) nsum,nsave,nstandalone,nhsym,tdec,ndecodes +1012 format('<DecodeFinished>',3i4,i6,f6.2,i5) + flush(6) + + return +end subroutine decode0 diff --git a/map65/libm65/decode1a.f90 b/map65/libm65/decode1a.f90 index d1cdd598..4219c004 100755..100644 --- a/map65/libm65/decode1a.f90 +++ b/map65/libm65/decode1a.f90 @@ -1,145 +1,145 @@ -subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
- mycall,hiscall,hisgrid,neme,ndepth,nqd,dphi,ndphi, &
- nutc,nkhz,ndf,ipol,ntol,sync2,a,dt,pol,nkv,nhist,nsum,nsave, &
- qual,decoded)
-
-! Apply AFC corrections to a candidate JT65 signal, then decode it.
-
- use timer_module, only: timer
- parameter (NMAX=60*96000) !Samples per 60 s
- real*4 dd(4,NMAX) !92 MB: raw data from Linrad timf2
- complex cx(NMAX/64), cy(NMAX/64) !Data at 1378.125 samples/s
- complex c5x(NMAX/256),c5y(NMAX/256) !Data at 344.53125 Hz
- complex c5a(512)
- complex z
- real s2(66,126)
- real s3(64,63),sy(63)
- real a(5)
- logical first,xpol
- character decoded*22
- character mycall*12,hiscall*12,hisgrid*6
- data first/.true./,jjjmin/1000/,jjjmax/-1000/
- data nutc0/-999/,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,NMAX,f0,newdat,nfsample,xpol,cx,cy,n5)
-! NB: cx, cy have sample rate 96000*77125/5376000 = 1378.125 Hz
- call timer('filbig ',1)
- if(mode65.eq.0) goto 900
- sqa=0.
- sqb=0.
- do i=1,n5
- sqa=sqa + real(cx(i))**2 + aimag(cx(i))**2
- if(xpol) sqb=sqb + real(cy(i))**2 + aimag(cy(i))**2
- enddo
- sqa=sqa/n5
- sqb=sqb/n5
-
-! Find best DF, f1, f2, DT, and pol. Start by downsampling to 344.53125 Hz
- if(xpol) then
- z=cmplx(cos(dphi),sin(dphi))
- cy(:n5)=z*cy(:n5) !Adjust for cable length difference
- endif
-! 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)
- if(xpol) then
- c5y(:nadd)=0.
- call fil6521(cy,n5,c5y(nadd+1),n6)
- endif
- n6=n6+nadd
-
- fsample=1378.125/4.
- a(5)=dt00
- i0=nint((a(5)+0.5)*fsample) - 2 + nadd
- if(i0.lt.1) then
- write(13,*) 'i0 too small in decode1a:',i0,f0
- flush(13)
- 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.
-! Best fit for DF, f1, f2, pol
- call afc65b(c5x(i0),c5y(i0),nz,fsample,nflip,ipol,xpol,ndphi,a,ccfbest,dtbest)
-
- pol=a(4)/57.2957795
- aa=cos(pol)
- bb=sin(pol)
- sq0=aa*aa*sqa + bb*bb*sqb
- sync2=3.7*ccfbest/sq0
-
-! 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 twkfreq_xy(cx,cy,n5,a)
-
-! Compute spectrum at best polarization 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
-
-
-! Perhaps should try full-symbol-length FFTs even in B, C sub-modes?
-! (Tried this, found no significant difference in decodes.)
-
- do k=1,nsym
-! do n=1,mode65
- do n=1,1
- do i=1,nfft
- j=min(j+1,NMAX/64)
- c5a(i)=aa*cx(j) + bb*cy(j)
- enddo
- call four2a(c5a,nfft,1,1,1)
- if(n.eq.1) then
- do i=1,66
-! s2(i,k)=real(c5a(i))**2 + aimag(c5a(i))**2
- 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
- else
- do i=1,66
- s2(i,k)=s2(i,k) + real(c5a(i))**2 + aimag(c5a(i))**2
- enddo
- endif
- enddo
- enddo
-
- flip=nflip
- call timer('dec65b ',0)
- call decode65b(s2,flip,mycall,hiscall,hisgrid,mode65,neme,ndepth, &
- nqd,nkv,nhist,qual,decoded,s3,sy)
- dt=dt00 + dtbest + 1.7
- call timer('dec65b ',1)
-
- if(nqd.eq.1 .and. decoded.eq.' ') then
- nhz=1000*nkhz + ndf
- ihzdiff=min(500,ntol)
- if(nutc.ne.nutc0 .or. abs(nhz-nhz0).ge.ihzdiff) syncbest=0.
- if(sync2.gt.0.99999*syncbest) then
- nsave=nsave+1
- nsave=mod(nsave-1,64)+1
- npol=nint(57.296*pol)
-
- call s3avg(nsave,mode65,nutc,nhz,xdt,npol,ntol,s3,nsum,nkv,decoded)
- syncbest=sync2
- nhz0=nhz
- endif
- nutc0=nutc
- endif
-
-900 return
-end subroutine decode1a
+subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, & + mycall,hiscall,hisgrid,neme,ndepth,nqd,dphi,ndphi, & + nutc,nkhz,ndf,ipol,ntol,sync2,a,dt,pol,nkv,nhist,nsum,nsave, & + qual,decoded) + +! Apply AFC corrections to a candidate JT65 signal, then decode it. + + use timer_module, only: timer + parameter (NMAX=60*96000) !Samples per 60 s + real*4 dd(4,NMAX) !92 MB: raw data from Linrad timf2 + complex cx(NMAX/64), cy(NMAX/64) !Data at 1378.125 samples/s + complex c5x(NMAX/256),c5y(NMAX/256) !Data at 344.53125 Hz + complex c5a(512) + complex z + real s2(66,126) + real s3(64,63),sy(63) + real a(5) + logical first,xpol + character decoded*22 + character mycall*12,hiscall*12,hisgrid*6 + data first/.true./,jjjmin/1000/,jjjmax/-1000/ + data nutc0/-999/,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,NMAX,f0,newdat,nfsample,xpol,cx,cy,n5) +! NB: cx, cy have sample rate 96000*77125/5376000 = 1378.125 Hz + call timer('filbig ',1) + if(mode65.eq.0) goto 900 + sqa=0. + sqb=0. + do i=1,n5 + sqa=sqa + real(cx(i))**2 + aimag(cx(i))**2 + if(xpol) sqb=sqb + real(cy(i))**2 + aimag(cy(i))**2 + enddo + sqa=sqa/n5 + sqb=sqb/n5 + +! Find best DF, f1, f2, DT, and pol. Start by downsampling to 344.53125 Hz + if(xpol) then + z=cmplx(cos(dphi),sin(dphi)) + cy(:n5)=z*cy(:n5) !Adjust for cable length difference + endif +! 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) + if(xpol) then + c5y(:nadd)=0. + call fil6521(cy,n5,c5y(nadd+1),n6) + endif + n6=n6+nadd + + fsample=1378.125/4. + a(5)=dt00 + i0=nint((a(5)+0.5)*fsample) - 2 + nadd + if(i0.lt.1) then + write(13,*) 'i0 too small in decode1a:',i0,f0 + flush(13) + 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. +! Best fit for DF, f1, f2, pol + call afc65b(c5x(i0),c5y(i0),nz,fsample,nflip,ipol,xpol,ndphi,a,ccfbest,dtbest) + + pol=a(4)/57.2957795 + aa=cos(pol) + bb=sin(pol) + sq0=aa*aa*sqa + bb*bb*sqb + sync2=3.7*ccfbest/sq0 + +! 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 twkfreq_xy(cx,cy,n5,a) + +! Compute spectrum at best polarization 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 + + +! Perhaps should try full-symbol-length FFTs even in B, C sub-modes? +! (Tried this, found no significant difference in decodes.) + + do k=1,nsym +! do n=1,mode65 + do n=1,1 + do i=1,nfft + j=min(j+1,NMAX/64) + c5a(i)=aa*cx(j) + bb*cy(j) + enddo + call four2a(c5a,nfft,1,1,1) + if(n.eq.1) then + do i=1,66 +! s2(i,k)=real(c5a(i))**2 + aimag(c5a(i))**2 + 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 + else + do i=1,66 + s2(i,k)=s2(i,k) + real(c5a(i))**2 + aimag(c5a(i))**2 + enddo + endif + enddo + enddo + + flip=nflip + call timer('dec65b ',0) + call decode65b(s2,flip,mycall,hiscall,hisgrid,mode65,neme,ndepth, & + nqd,nkv,nhist,qual,decoded,s3,sy) + dt=dt00 + dtbest + 1.7 + call timer('dec65b ',1) + + if(nqd.eq.1 .and. decoded.eq.' ') then + nhz=1000*nkhz + ndf + ihzdiff=min(500,ntol) + if(nutc.ne.nutc0 .or. abs(nhz-nhz0).ge.ihzdiff) syncbest=0. + if(sync2.gt.0.99999*syncbest) then + nsave=nsave+1 + nsave=mod(nsave-1,64)+1 + npol=nint(57.296*pol) + + call s3avg(nsave,mode65,nutc,nhz,xdt,npol,ntol,s3,nsum,nkv,decoded) + syncbest=sync2 + nhz0=nhz + endif + nutc0=nutc + endif + +900 return +end subroutine decode1a diff --git a/map65/libm65/decode65b.f90 b/map65/libm65/decode65b.f90 index 7b243818..9b3ebccd 100755..100644 --- a/map65/libm65/decode65b.f90 +++ b/map65/libm65/decode65b.f90 @@ -1,48 +1,48 @@ -subroutine decode65b(s2,flip,mycall,hiscall,hisgrid,mode65,neme,ndepth, &
- nqd,nkv,nhist,qual,decoded,s3,sy)
-
- real s2(66,126)
- real s3(64,63),sy(63)
- logical first,ltext
- character decoded*22,deepmsg*22
- character mycall*12,hiscall*12,hisgrid*6
- 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(flip.lt.0.0) k=mdat2(j)
- do i=1,64
- s3(i,j)=s2(i+2,k)
- enddo
- k=mdat2(j) !Points to data symbol
- if(flip.lt.0.0) k=mdat(j)
- sy(j)=s2(1,k)
- enddo
-
- nadd=mode65
- call extract(s3,nadd,ncount,nhist,decoded,ltext) !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(flip.lt.0.0 .and. ltext) ncount=-1
- nkv=1
- if(ncount.lt.0) then
- nkv=0
- decoded=' '
- endif
-
- qual=0.
- if(ndepth.ge.1 .and. (nqd.eq.1 .or. flip.eq.1.0)) then
- call deep65(s3,mode65,neme,flip,mycall,hiscall,hisgrid,deepmsg,qual)
- if(nqd.ne.1 .and. qual.lt.10.0) qual=0.0
- if(ndepth.lt.2 .and. qual.lt.6.0) qual=0.0
- endif
- if(nkv.eq.0 .and. qual.ge.1.0) decoded=deepmsg
-
- return
-end subroutine decode65b
+subroutine decode65b(s2,flip,mycall,hiscall,hisgrid,mode65,neme,ndepth, & + nqd,nkv,nhist,qual,decoded,s3,sy) + + real s2(66,126) + real s3(64,63),sy(63) + logical first,ltext + character decoded*22,deepmsg*22 + character mycall*12,hiscall*12,hisgrid*6 + 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(flip.lt.0.0) k=mdat2(j) + do i=1,64 + s3(i,j)=s2(i+2,k) + enddo + k=mdat2(j) !Points to data symbol + if(flip.lt.0.0) k=mdat(j) + sy(j)=s2(1,k) + enddo + + nadd=mode65 + call extract(s3,nadd,ncount,nhist,decoded,ltext) !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(flip.lt.0.0 .and. ltext) ncount=-1 + nkv=1 + if(ncount.lt.0) then + nkv=0 + decoded=' ' + endif + + qual=0. + if(ndepth.ge.1 .and. (nqd.eq.1 .or. flip.eq.1.0)) then + call deep65(s3,mode65,neme,flip,mycall,hiscall,hisgrid,deepmsg,qual) + if(nqd.ne.1 .and. qual.lt.10.0) qual=0.0 + if(ndepth.lt.2 .and. qual.lt.6.0) qual=0.0 + endif + if(nkv.eq.0 .and. qual.ge.1.0) decoded=deepmsg + + return +end subroutine decode65b diff --git a/map65/libm65/decode_rs.c b/map65/libm65/decode_rs.c index 8fe972b9..91f582ac 100755..100644 --- a/map65/libm65/decode_rs.c +++ b/map65/libm65/decode_rs.c @@ -1,268 +1,268 @@ -/* Reed-Solomon decoder
- * Copyright 2002 Phil Karn, KA9Q
- * May be used under the terms of the GNU General Public License (GPL)
- * Modified by Steve Franke, K9AN, for use in a soft-symbol RS decoder
- */
-
-#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(
-#ifndef FIXED
- void *p,
-#endif
- DTYPE *data, int *eras_pos, int no_eras, int calc_syn){
-
-#ifndef FIXED
- 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]; // Err+Eras Locator poly
- static DTYPE s[51]; // 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;
-
- if( calc_syn ) {
- /* 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;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++)
- 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(®[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 = 0;
- for (i = 0; i < NROOTS;i++){
- tmp = 0;
- j = (deg_lambda < i) ? deg_lambda : i;
- for(;j >= 0; j--){
- if ((s[i - j] != A0) && (lambda[j] != A0))
- tmp ^= ALPHA_TO[MODNN(s[i - j] + lambda[j])];
- }
- if(tmp != 0)
- deg_omega = i;
- omega[i] = INDEX_OF[tmp];
- }
- omega[NROOTS] = A0;
-
- /*
- * 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 (den == 0) {
-#if DEBUG >= 1
- printf("\n ERROR: denominator = 0\n");
-#endif
- count = -1;
- goto finish;
- }
- /* Apply error to data */
- if (num1 != 0) {
- data[loc[j]] ^= 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;
-}
+/* Reed-Solomon decoder + * Copyright 2002 Phil Karn, KA9Q + * May be used under the terms of the GNU General Public License (GPL) + * Modified by Steve Franke, K9AN, for use in a soft-symbol RS decoder + */ + +#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( +#ifndef FIXED + void *p, +#endif + DTYPE *data, int *eras_pos, int no_eras, int calc_syn){ + +#ifndef FIXED + 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]; // Err+Eras Locator poly + static DTYPE s[51]; // 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; + + if( calc_syn ) { + /* 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;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++) + 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(®[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 = 0; + for (i = 0; i < NROOTS;i++){ + tmp = 0; + j = (deg_lambda < i) ? deg_lambda : i; + for(;j >= 0; j--){ + if ((s[i - j] != A0) && (lambda[j] != A0)) + tmp ^= ALPHA_TO[MODNN(s[i - j] + lambda[j])]; + } + if(tmp != 0) + deg_omega = i; + omega[i] = INDEX_OF[tmp]; + } + omega[NROOTS] = A0; + + /* + * 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 (den == 0) { +#if DEBUG >= 1 + printf("\n ERROR: denominator = 0\n"); +#endif + count = -1; + goto finish; + } + /* Apply error to data */ + if (num1 != 0) { + data[loc[j]] ^= 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/map65/libm65/deep65.f90 b/map65/libm65/deep65.f90 index b43d07f8..d684cd15 100755..100644 --- a/map65/libm65/deep65.f90 +++ b/map65/libm65/deep65.f90 @@ -1,170 +1,170 @@ -subroutine deep65(s3,mode65,neme,flip,mycall,hiscall,hisgrid,decoded,qual)
-
- use timer_module, only: timer
- parameter (MAXCALLS=10000,MAXRPT=63)
- real s3(64,63)
- character callsign*12,grid*4,message*22,hisgrid*6,c*1,ceme*3
- character*12 mycall,hiscall
- character*22 decoded,bestmsg
- character*22 testmsg(2*MAXCALLS + 2 + MAXRPT)
- character*15 callgrid(MAXCALLS)
- character*180 line
- character*4 rpt(MAXRPT)
- integer ncode(63,2*MAXCALLS + 2 + MAXRPT)
- real pp(2*MAXCALLS + 2 + MAXRPT)
- common/mrscom/ mrs(63),mrs2(63)
- common/c3com/ mcall3a
- 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(mcall3a.eq.0) go to 30
-
- call timer('deep65a ',0)
- 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. 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 encode65(message,ncode(1,k))
-
-! Insert CQ message
- if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid
- message='CQ '//callgrid(icall)
- k=k+1
- testmsg(k)=message
- call encode65(message,ncode(1,k))
- enddo
-10 continue
- enddo
-
-20 continue
- ntot=k
- call timer('deep65a ',1)
-
-30 continue
- call timer('deep65b ',0)
- ref0=0.
- do j=1,63
- ref0=ref0 + s3(mrs(j),j)
- enddo
-
- p1=-1.e30
- do k=1,ntot
- pp(k)=0.
- if(k.ge.2 .and. k.le.64 .and. flip.lt.0.0) cycle
-! 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
- sum=0.
- ref=ref0
- do j=1,63
- i=ncode(j,k)+1
- sum=sum + s3(i,j)
- if(i.eq.mrs(j)) ref=ref - s3(i,j) + s3(mrs2(j),j)
- enddo
- p=sum/ref
- pp(k)=p
- if(p.gt.p1) then
- p1=p
- ip1=k
- bestmsg=testmsg(k)
- endif
- endif
- enddo
-
- p2=-1.e30
- do i=1,ntot
- if(pp(i).gt.p2 .and. testmsg(i).ne.bestmsg) p2=pp(i)
- enddo
-
- 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) then
- open(77,file='error.log',status='unknown',access='append')
- write(77,*) p1,p2,ip1,bestmsg
- close(77)
- endif
-
- qual=100.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
- call timer('deep65b ',1)
-
- return
-end subroutine deep65
+subroutine deep65(s3,mode65,neme,flip,mycall,hiscall,hisgrid,decoded,qual) + + use timer_module, only: timer + parameter (MAXCALLS=10000,MAXRPT=63) + real s3(64,63) + character callsign*12,grid*4,message*22,hisgrid*6,c*1,ceme*3 + character*12 mycall,hiscall + character*22 decoded,bestmsg + character*22 testmsg(2*MAXCALLS + 2 + MAXRPT) + character*15 callgrid(MAXCALLS) + character*180 line + character*4 rpt(MAXRPT) + integer ncode(63,2*MAXCALLS + 2 + MAXRPT) + real pp(2*MAXCALLS + 2 + MAXRPT) + common/mrscom/ mrs(63),mrs2(63) + common/c3com/ mcall3a + 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(mcall3a.eq.0) go to 30 + + call timer('deep65a ',0) + 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. 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 encode65(message,ncode(1,k)) + +! Insert CQ message + if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid + message='CQ '//callgrid(icall) + k=k+1 + testmsg(k)=message + call encode65(message,ncode(1,k)) + enddo +10 continue + enddo + +20 continue + ntot=k + call timer('deep65a ',1) + +30 continue + call timer('deep65b ',0) + ref0=0. + do j=1,63 + ref0=ref0 + s3(mrs(j),j) + enddo + + p1=-1.e30 + do k=1,ntot + pp(k)=0. + if(k.ge.2 .and. k.le.64 .and. flip.lt.0.0) cycle +! 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 + sum=0. + ref=ref0 + do j=1,63 + i=ncode(j,k)+1 + sum=sum + s3(i,j) + if(i.eq.mrs(j)) ref=ref - s3(i,j) + s3(mrs2(j),j) + enddo + p=sum/ref + pp(k)=p + if(p.gt.p1) then + p1=p + ip1=k + bestmsg=testmsg(k) + endif + endif + enddo + + p2=-1.e30 + do i=1,ntot + if(pp(i).gt.p2 .and. testmsg(i).ne.bestmsg) p2=pp(i) + enddo + + 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) then + open(77,file='error.log',status='unknown',access='append') + write(77,*) p1,p2,ip1,bestmsg + close(77) + endif + + qual=100.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 + call timer('deep65b ',1) + + return +end subroutine deep65 diff --git a/map65/libm65/deg2grid.f90 b/map65/libm65/deg2grid.f90 index fdbb5f2f..9ca3602f 100755..100644 --- a/map65/libm65/deg2grid.f90 +++ b/map65/libm65/deg2grid.f90 @@ -1,30 +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=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=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
+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=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=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/map65/libm65/demod64a.f90 b/map65/libm65/demod64a.f90 index 43cedb0a..3b8ee03c 100755..100644 --- a/map65/libm65/demod64a.f90 +++ b/map65/libm65/demod64a.f90 @@ -1,77 +1,77 @@ -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)
-
- 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.
- psum=0.
- do i=1,64
- x=min(afac*s3(i,j)/ave,50.d0)
- fs(i)=exp(x)
- fsum=fsum+fs(i)
- psum=psum + s3(i,j)
- 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
- p1=s1/psum
- p2=s2/psum
- 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
- ntest=sum
-
- return
-end subroutine demod64a
+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) + + 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. + psum=0. + do i=1,64 + x=min(afac*s3(i,j)/ave,50.d0) + fs(i)=exp(x) + fsum=fsum+fs(i) + psum=psum + s3(i,j) + 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 + p1=s1/psum + p2=s2/psum + 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 + ntest=sum + + return +end subroutine demod64a diff --git a/map65/libm65/display.f90 b/map65/libm65/display.f90 index cd193506..b5ced07c 100755..100644 --- a/map65/libm65/display.f90 +++ b/map65/libm65/display.f90 @@ -1,176 +1,184 @@ -subroutine display(nkeep,ftol)
-
- parameter (MAXLINES=400,MX=400,MAXCALLS=500)
- integer indx(MAXLINES),indx2(MX)
- character*83 line(MAXLINES),line2(MX),line3(MAXLINES)
- character out*63,out0*63,cfreq0*3 ! was 57,57,3
- character*6 callsign,callsign0
- character*12 freqcall(MAXCALLS)
- real freqkHz(MAXLINES)
- integer utc(MAXLINES),utc2(MX),utcz
- real*8 f0
- save
-
- character(len=83) :: livecq2
- character(len=83) :: livecq3
-
- out0=' '
- rewind(26)
-
- do i=1,MAXLINES
- read(26,1010,end=10) line(i)
-1010 format(a83) ! was a77
- read(line(i),1020) f0,ndf,nh,nm
-1020 format(f8.3,i5,25x,i3,i2)
- utc(i)=60*nh + nm
- freqkHz(i)=1000.d0*(f0-144.d0) + 0.001d0*ndf
- enddo
-
-10 backspace(26)
- nz=i-1
- utcz=utc(nz)
- nz=nz-1
- if(nz.lt.1) go to 999
- nquad=max(nkeep/4,3)
- do i=1,nz
- nage=utcz-utc(i)
- if(nage.lt.0) nage=nage+1440
- iage=nage/nquad
- write(line(i)(79:80),1021) iage ! was 73:74
-1021 format(i2)
- enddo
-
- nage=utcz-utc(1)
- if(nage.lt.0) nage=nage+1440
- if(nage.gt.nkeep) then
- do i=1,nz
- nage=utcz-utc(i)
- if(nage.lt.0) nage=nage+1440
- if(nage.le.nkeep) go to 20
- enddo
-20 i0=i
- nz=nz-i0+1
- rewind(26)
- if(nz.lt.1) go to 999
- do i=1,nz
- j=i+i0-1
- line(i)=line(j)
- utc(i)=utc(j)
- freqkHz(i)=freqkHz(j)
- write(26,1022) line(i)
-1022 format(a83) ! was a77
- enddo
- endif
-
- call flush(26)
- call indexx(freqkHz,nz,indx)
-
- nstart=1
- k3=0
- k=1
- m=indx(1)
- if(m.lt.1 .or. m.gt.MAXLINES) then
- print*,'Error in display.f90: ',nz,m
- m=1
- endif
- line2(1)=line(m)
- utc2(1)=utc(m)
- do i=2,nz
- j0=indx(i-1)
- j=indx(i)
- if(freqkHz(j)-freqkHz(j0).gt.2.0*ftol) then
- if(nstart.eq.0) then
- k=k+1
- line2(k)=""
- utc2(k)=-1
- endif
- kz=k
- if(nstart.eq.1) then
- call indexx(float(utc2(1:kz)),kz,indx2)
- k3=0
- do k=1,kz
- k3=min(k3+1,400)
- line3(k3)=line2(indx2(k))
- enddo
- nstart=0
- else
- call indexx(float(utc2(1:kz)),kz,indx2)
- do k=1,kz
- k3=min(k3+1,400)
- line3(k3)=line2(indx2(k))
- enddo
- endif
- k=0
- endif
- if(i.eq.nz) then
- k=k+1
- line2(k)=""
- utc2(k)=-1
- endif
- k=k+1
- line2(k)=line(j)
- utc2(k)=utc(j)
- j0=j
- enddo
- kz=k
- call indexx(float(utc2(1:kz)),kz,indx2)
- do k=1,kz
- k3=min(k3+1,400)
- line3(k3)=line2(indx2(k))
- enddo
-
- rewind 19
- rewind 20
- cfreq0=' '
- nc=0
- callsign0=' '
- do k=1,k3
- out=line3(k)(1:13)//line3(k)(28:31)//line3(k)(39:45)// &
- line3(k)(35:38)//line3(k)(46:80) ! was 46:74
- livecq2=line3(k)
- if(out(6:8).ne.' ') then
- cfreq0=out(6:8)
-
-! Suppress listing duplicate (same time, decoded message, and frequency)
- if(out(19:22).ne.out0(19:22) .or. out(31:55).ne.out0(31:55) .or. &
- out(6:8).ne.out0(6:8)) then
- livecq3 = out(1:61) // ' ' // livecq2(23:27) // ' ' // livecq2(79:83) ! was 1:55 and 73:77
- write(*,1030) livecq3
-1030 format('@',a83) ! was a77
- out0=out
- endif
-
- i1=index(out(31:),' ')
- callsign=out(i1+31:)
- i2=index(callsign,' ')
- if(i2.gt.1) callsign(i2:)=' '
- if(callsign.ne.' ' .and. callsign.ne.callsign0) then
- len=i2-1
- if(len.lt.0) len=6
- if(len.ge.4) then !Omit short "callsigns"
- if(nc.lt.MAXCALLS) nc=nc+1
- freqcall(nc)=cfreq0//' '//callsign//line3(k)(79:80) ! was 73:74
- callsign0=callsign
- endif
- endif
- if(callsign.ne.' ' .and. callsign.eq.callsign0) then
- freqcall(nc)=cfreq0//' '//callsign//line3(k)(79:80) ! was 73:74
- endif
- endif
- enddo
-
- if(nc.lt.MAXCALLS) nc=nc+1
- freqcall(nc)=' '
- if(nc.lt.MAXCALLS) nc=nc+1
- freqcall(nc)=' '
- freqcall(nc+1)=' '
- freqcall(nc+2)=' '
-
- do i=1,nc
- write(*,1042) freqcall(i) !Band Map
-1042 format('&',a12)
- enddo
-
-999 continue
- return
-end subroutine display
+subroutine display(nkeep,ftol) + + parameter (MAXLINES=400,MX=400,MAXCALLS=500) + integer indx(MAXLINES),indx2(MX) + character*83 line(MAXLINES),line2(MX),line3(MAXLINES) + character out*63,out0*63,cfreq0*3 ! was 57,57,3 + character*6 callsign,callsign0 + character*12 freqcall(MAXCALLS) + real freqkHz(MAXLINES) + integer utc(MAXLINES),utc2(MX),utcz + real*8 f0 + save + + character(len=83) :: livecq2 + character(len=83) :: livecq3 + + + integer :: io_status + integer :: ndf, nh, nm + + out0=' ' + rewind(26) + + do i=1,MAXLINES + read(26,1010,end=10) line(i) +1010 format(a83) ! was a77 + read(line(i), 1020, iostat=io_status) f0, ndf, nh, nm +1020 format(f8.3,i5,25x,i3,i2) + if (io_status /= 0) then + ! Handle error: skip + continue + end if + utc(i)=60*nh + nm + freqkHz(i)=1000.d0*(f0-144.d0) + 0.001d0*ndf + enddo + +10 backspace(26) + nz=i-1 + utcz=utc(nz) + nz=nz-1 + if(nz.lt.1) go to 999 + nquad=max(nkeep/4,3) + do i=1,nz + nage=utcz-utc(i) + if(nage.lt.0) nage=nage+1440 + iage=nage/nquad + write(line(i)(79:80),1021) iage ! was 73:74 +1021 format(i2) + enddo + + nage=utcz-utc(1) + if(nage.lt.0) nage=nage+1440 + if(nage.gt.nkeep) then + do i=1,nz + nage=utcz-utc(i) + if(nage.lt.0) nage=nage+1440 + if(nage.le.nkeep) go to 20 + enddo +20 i0=i + nz=nz-i0+1 + rewind(26) + if(nz.lt.1) go to 999 + do i=1,nz + j=i+i0-1 + line(i)=line(j) + utc(i)=utc(j) + freqkHz(i)=freqkHz(j) + write(26,1022) line(i) +1022 format(a83) ! was a77 + enddo + endif + + call flush(26) + call indexx(freqkHz,nz,indx) + + nstart=1 + k3=0 + k=1 + m=indx(1) + if(m.lt.1 .or. m.gt.MAXLINES) then + print*,'Error in display.f90: ',nz,m + m=1 + endif + line2(1)=line(m) + utc2(1)=utc(m) + do i=2,nz + j0=indx(i-1) + j=indx(i) + if(freqkHz(j)-freqkHz(j0).gt.2.0*ftol) then + if(nstart.eq.0) then + k=k+1 + line2(k)="" + utc2(k)=-1 + endif + kz=k + if(nstart.eq.1) then + call indexx(float(utc2(1:kz)),kz,indx2) + k3=0 + do k=1,kz + k3=min(k3+1,400) + line3(k3)=line2(indx2(k)) + enddo + nstart=0 + else + call indexx(float(utc2(1:kz)),kz,indx2) + do k=1,kz + k3=min(k3+1,400) + line3(k3)=line2(indx2(k)) + enddo + endif + k=0 + endif + if(i.eq.nz) then + k=k+1 + line2(k)="" + utc2(k)=-1 + endif + k=k+1 + line2(k)=line(j) + utc2(k)=utc(j) + j0=j + enddo + kz=k + call indexx(float(utc2(1:kz)),kz,indx2) + do k=1,kz + k3=min(k3+1,400) + line3(k3)=line2(indx2(k)) + enddo + + rewind 19 + rewind 20 + cfreq0=' ' + nc=0 + callsign0=' ' + do k=1,k3 + out=line3(k)(1:13)//line3(k)(28:31)//line3(k)(39:45)// & + line3(k)(35:38)//line3(k)(46:80) ! was 46:74 + livecq2=line3(k) + if(out(6:8).ne.' ') then + cfreq0=out(6:8) + +! Suppress listing duplicate (same time, decoded message, and frequency) + if(out(19:22).ne.out0(19:22) .or. out(31:55).ne.out0(31:55) .or. & + out(6:8).ne.out0(6:8)) then + livecq3 = out(1:61) // ' ' // livecq2(23:27) // ' ' // livecq2(79:83) ! was 1:55 and 73:77 + write(*,1030) livecq3 +1030 format('@',a83) ! was a77 + out0=out + endif + + i1=index(out(31:),' ') + callsign=out(i1+31:) + i2=index(callsign,' ') + if(i2.gt.1) callsign(i2:)=' ' + if(callsign.ne.' ' .and. callsign.ne.callsign0) then + len=i2-1 + if(len.lt.0) len=6 + if(len.ge.3) then !Omit short "callsigns" + if(nc.lt.MAXCALLS) nc=nc+1 + freqcall(nc)=cfreq0//' '//callsign//line3(k)(79:80) ! was 73:74 + callsign0=callsign + endif + endif + if(callsign.ne.' ' .and. callsign.eq.callsign0) then + freqcall(nc)=cfreq0//' '//callsign//line3(k)(79:80) ! was 73:74 + endif + endif + enddo + + if(nc.lt.MAXCALLS) nc=nc+1 + freqcall(nc)=' ' + if(nc.lt.MAXCALLS) nc=nc+1 + freqcall(nc)=' ' + freqcall(nc+1)=' ' + freqcall(nc+2)=' ' + + do i=1,nc + write(*,1042) freqcall(i) !Band Map +1042 format('&',a12) + enddo + +999 continue + return +end subroutine display diff --git a/map65/libm65/dot.f90 b/map65/libm65/dot.f90 index a68c5bd1..5829e878 100755..100644 --- a/map65/libm65/dot.f90 +++ b/map65/libm65/dot.f90 @@ -1,11 +1,11 @@ -real*8 function dot(x,y)
-
- real*8 x(3),y(3)
-
- dot=0.d0
- do i=1,3
- dot=dot+x(i)*y(i)
- enddo
-
- return
-end function dot
+real*8 function dot(x,y) + + real*8 x(3),y(3) + + dot=0.d0 + do i=1,3 + dot=dot+x(i)*y(i) + enddo + + return +end function dot diff --git a/map65/libm65/dpol.f90 b/map65/libm65/dpol.f90 index 5f5bea93..3f8085c0 100755..100644 --- a/map65/libm65/dpol.f90 +++ b/map65/libm65/dpol.f90 @@ -1,41 +1,41 @@ -real function dpol(mygrid,hisgrid)
-
-! Compute spatial polartzation offset in degrees for the present
-! time, between two specified grid locators.
-
- character*6 MyGrid,HisGrid
- real lat,lon,LST
- character cdate*8,ctime2*10,czone*5
- integer it(8)
- data rad/57.2957795/
-
- call date_and_time(cdate,ctime2,czone,it)
- nyear=it(1)
- month=it(2)
- nday=it(3)
- nh=it(5)-it(4)/60
- nm=it(6)
- ns=it(7)
- uth=nh + nm/60.0 + ns/3600.0
-
- call grid2deg(MyGrid,lon,lat)
- call MoonDop(nyear,month,nday,uth,-lon,lat,RAMoon,DecMoon, &
- LST,HA,AzMoon,ElMoon,vr,dist)
- xx=sin(lat/rad)*cos(ElMoon/rad) - cos(lat/rad)* &
- cos(AzMoon/rad)*sin(ElMoon/rad)
- yy=cos(lat/rad)*sin(AzMoon/rad)
- poloffset1=rad*atan2(yy,xx)
-
- call grid2deg(hisGrid,lon,lat)
- call MoonDop(nyear,month,nday,uth,-lon,lat,RAMoon,DecMoon, &
- LST,HA,AzMoon,ElMoon,vr,dist)
- xx=sin(lat/rad)*cos(ElMoon/rad) - cos(lat/rad)* &
- cos(AzMoon/rad)*sin(ElMoon/rad)
- yy=cos(lat/rad)*sin(AzMoon/rad)
- poloffset2=rad*atan2(yy,xx)
-
- dpol=mod(poloffset2-poloffset1+720.0,180.0)
- if(dpol.gt.90.0) dpol=dpol-180.0
-
- return
-end function dpol
+real function dpol(mygrid,hisgrid) + +! Compute spatial polartzation offset in degrees for the present +! time, between two specified grid locators. + + character*6 MyGrid,HisGrid + real lat,lon,LST + character cdate*8,ctime2*10,czone*5 + integer it(8) + data rad/57.2957795/ + + call date_and_time(cdate,ctime2,czone,it) + nyear=it(1) + month=it(2) + nday=it(3) + nh=it(5)-it(4)/60 + nm=it(6) + ns=it(7) + uth=nh + nm/60.0 + ns/3600.0 + + call grid2deg(MyGrid,lon,lat) + call MoonDop(nyear,month,nday,uth,-lon,lat,RAMoon,DecMoon, & + LST,HA,AzMoon,ElMoon,vr,dist) + xx=sin(lat/rad)*cos(ElMoon/rad) - cos(lat/rad)* & + cos(AzMoon/rad)*sin(ElMoon/rad) + yy=cos(lat/rad)*sin(AzMoon/rad) + poloffset1=rad*atan2(yy,xx) + + call grid2deg(hisGrid,lon,lat) + call MoonDop(nyear,month,nday,uth,-lon,lat,RAMoon,DecMoon, & + LST,HA,AzMoon,ElMoon,vr,dist) + xx=sin(lat/rad)*cos(ElMoon/rad) - cos(lat/rad)* & + cos(AzMoon/rad)*sin(ElMoon/rad) + yy=cos(lat/rad)*sin(AzMoon/rad) + poloffset2=rad*atan2(yy,xx) + + dpol=mod(poloffset2-poloffset1+720.0,180.0) + if(dpol.gt.90.0) dpol=dpol-180.0 + + return +end function dpol diff --git a/map65/libm65/encode65.f90 b/map65/libm65/encode65.f90 index 312bcc24..920d9c84 100755..100644 --- a/map65/libm65/encode65.f90 +++ b/map65/libm65/encode65.f90 @@ -1,14 +1,14 @@ -subroutine encode65(message,sent)
-
- use packjt
- character message*22
- integer dgen(12)
- integer sent(63)
-
- call packmsg(message,dgen,itype)
- call rs_encode(dgen,sent)
- call interleave63(sent,1)
- call graycode(sent,63,1)
-
- return
-end subroutine encode65
+subroutine encode65(message,sent) + + use packjt + character message*22 + integer dgen(12) + integer sent(63) + + call packmsg(message,dgen,itype) + call rs_encode(dgen,sent) + call interleave63(sent,1) + call graycode(sent,63,1) + + return +end subroutine encode65 diff --git a/map65/libm65/encode_rs.c b/map65/libm65/encode_rs.c index 26b81c46..9d56d0bf 100755..100644 --- a/map65/libm65/encode_rs.c +++ b/map65/libm65/encode_rs.c @@ -1,47 +1,47 @@ -/* 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(
-#ifndef FIXED
-void *p,
-#endif
-DTYPE *data, DTYPE *bb){
-#ifndef FIXED
- struct rs *rs = (struct rs *)p;
-#endif
- int i, j;
- DTYPE feedback;
-
- memset(bb,0,NROOTS*sizeof(DTYPE));
-
- for(i=0;i<NN-NROOTS;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;
- }
-}
+/* 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( +#ifndef FIXED +void *p, +#endif +DTYPE *data, DTYPE *bb){ +#ifndef FIXED + struct rs *rs = (struct rs *)p; +#endif + int i, j; + DTYPE feedback; + + memset(bb,0,NROOTS*sizeof(DTYPE)); + + for(i=0;i<NN-NROOTS;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/map65/libm65/extract.f90 b/map65/libm65/extract.f90 index becc06af..4d8af58a 100755..100644 --- a/map65/libm65/extract.f90 +++ b/map65/libm65/extract.f90 @@ -1,136 +1,136 @@ -subroutine extract(s3,nadd,ncount,nhist,decoded,ltext)
-
- use packjt
- use timer_module, only: timer
- real s3(64,63)
- character decoded*22
- integer dat4(12)
- integer mrsym(63),mr2sym(63),mrprob(63),mr2prob(63)
- logical first,ltext
- integer correct(63),itmp(63)
- integer param(0:8)
- integer h0(0:11),d0(0:11)
- real r0(0:11)
- common/test001/s3a(64,63),mrs(63),mrs2(63) !### TEST ONLY ###
-
-! 0 1 2 3 4 5 6 7 8 9 10 11
- data h0/41,42,43,43,44,45,46,47,48,48,49,49/
- data d0/71,72,73,74,76,77,78,80,81,82,83,83/
-! 0 1 2 3 4 5 6 7 8 9 10 11
- data r0/0.70,0.72,0.74,0.76,0.78,0.80,0.82,0.84,0.86,0.88,0.90,0.90/
-
- data first/.true./,nsec1/0/
- save
-
- nfail=0
- call pctile(s3,4032,50,base) ! ### or, use ave from demod64a
- s3=s3/base
- s3a=s3
-1 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
- s3(ipk,1:63)=base
- if(nfail.gt.30) then
- decoded=' '
- ncount=-1
- go to 900
- endif
- go to 1
- endif
-
- mrs=mrsym
- mrs2=mr2sym
-
- call graycode(mrsym,63,-1)
- call interleave63(mrsym,-1)
- call interleave63(mrprob,-1)
-
- call graycode(mr2sym,63,-1)
- call interleave63(mr2sym,-1)
- call interleave63(mr2prob,-1)
-
- ntrials=10000
- naggressive=10
-
- ntry=0
- param=0
-
- call timer('ftrsd ',0)
- call ftrsd2(mrsym,mrprob,mr2sym,mr2prob,ntrials,correct,param,ntry)
- call timer('ftrsd ',1)
- ncandidates=param(0)
- nhard=param(1)
- nsoft=param(2)
- nerased=param(3)
- rtt=0.001*param(4)
- ntotal=param(5)
- qual=0.001*param(7)
- nd0=81
- r00=0.87
- if(naggressive.eq.10) then
- nd0=83
- r00=0.90
- endif
- if(ntotal.le.nd0 .and. rtt.le.r00) nft=1
- n=naggressive
- if(nhard.gt.50) nft=0
- if(nhard.gt.h0(n)) nft=0
- if(ntotal.gt.d0(n)) nft=0
- if(rtt.gt.r0(n)) nft=0
-
- ncount=-1
- decoded=' '
- ltext=.false.
- if(nft.gt.0) then
-! Turn the corrected symbol array into channel symbols for subtraction;
-! pass it back to jt65a via common block "chansyms65".
- do i=1,12
- dat4(i)=correct(13-i)
- enddo
- do i=1,63
- itmp(i)=correct(64-i)
- enddo
- correct(1:63)=itmp(1:63)
- call interleave63(correct,1)
- call graycode65(correct,63,1)
- call unpackmsg(dat4,decoded) !Unpack the user message
- ncount=0
- if(iand(dat4(10),8).ne.0) ltext=.true.
- endif
-900 continue
- if(nft.eq.1 .and. nhard.lt.0) decoded=' '
-! write(81,3001) naggressive,ncandidates,nhard,ntotal,rtt,qual,decoded
-!3001 format(i2,i6,i3,i4,2f8.2,2x,a22)
-
- return
-end subroutine extract
-
-subroutine getpp(workdat,p)
-
- integer workdat(63)
- integer a(63)
- common/test001/s3a(64,63),mrs(63),mrs2(63)
-
- a(1:63)=workdat(63:1:-1)
- call interleave63(a,1)
- call graycode(a,63,1)
-
- psum=0.
- do j=1,63
- i=a(j)+1
- x=s3a(i,j)
- s3a(i,j)=0.
- psum=psum + x
- s3a(i,j)=x
- enddo
- p=psum/63.0
-
- return
-end subroutine getpp
+subroutine extract(s3,nadd,ncount,nhist,decoded,ltext) + + use packjt + use timer_module, only: timer + real s3(64,63) + character decoded*22 + integer dat4(12) + integer mrsym(63),mr2sym(63),mrprob(63),mr2prob(63) + logical first,ltext + integer correct(63),itmp(63) + integer param(0:8) + integer h0(0:11),d0(0:11) + real r0(0:11) + common/test001/s3a(64,63),mrs(63),mrs2(63) !### TEST ONLY ### + +! 0 1 2 3 4 5 6 7 8 9 10 11 + data h0/41,42,43,43,44,45,46,47,48,48,49,49/ + data d0/71,72,73,74,76,77,78,80,81,82,83,83/ +! 0 1 2 3 4 5 6 7 8 9 10 11 + data r0/0.70,0.72,0.74,0.76,0.78,0.80,0.82,0.84,0.86,0.88,0.90,0.90/ + + data first/.true./,nsec1/0/ + save + + nfail=0 + call pctile(s3,4032,50,base) ! ### or, use ave from demod64a + s3=s3/base + s3a=s3 +1 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 + s3(ipk,1:63)=base + if(nfail.gt.30) then + decoded=' ' + ncount=-1 + go to 900 + endif + go to 1 + endif + + mrs=mrsym + mrs2=mr2sym + + call graycode(mrsym,63,-1) + call interleave63(mrsym,-1) + call interleave63(mrprob,-1) + + call graycode(mr2sym,63,-1) + call interleave63(mr2sym,-1) + call interleave63(mr2prob,-1) + + ntrials=10000 + naggressive=10 + + ntry=0 + param=0 + + call timer('ftrsd ',0) + call ftrsd2(mrsym,mrprob,mr2sym,mr2prob,ntrials,correct,param,ntry) + call timer('ftrsd ',1) + ncandidates=param(0) + nhard=param(1) + nsoft=param(2) + nerased=param(3) + rtt=0.001*param(4) + ntotal=param(5) + qual=0.001*param(7) + nd0=81 + r00=0.87 + if(naggressive.eq.10) then + nd0=83 + r00=0.90 + endif + if(ntotal.le.nd0 .and. rtt.le.r00) nft=1 + n=naggressive + if(nhard.gt.50) nft=0 + if(nhard.gt.h0(n)) nft=0 + if(ntotal.gt.d0(n)) nft=0 + if(rtt.gt.r0(n)) nft=0 + + ncount=-1 + decoded=' ' + ltext=.false. + if(nft.gt.0) then +! Turn the corrected symbol array into channel symbols for subtraction; +! pass it back to jt65a via common block "chansyms65". + do i=1,12 + dat4(i)=correct(13-i) + enddo + do i=1,63 + itmp(i)=correct(64-i) + enddo + correct(1:63)=itmp(1:63) + call interleave63(correct,1) + call graycode65(correct,63,1) + call unpackmsg(dat4,decoded) !Unpack the user message + ncount=0 + if(iand(dat4(10),8).ne.0) ltext=.true. + endif +900 continue + if(nft.eq.1 .and. nhard.lt.0) decoded=' ' +! write(81,3001) naggressive,ncandidates,nhard,ntotal,rtt,qual,decoded +!3001 format(i2,i6,i3,i4,2f8.2,2x,a22) + + return +end subroutine extract + +subroutine getpp(workdat,p) + + integer workdat(63) + integer a(63) + common/test001/s3a(64,63),mrs(63),mrs2(63) + + a(1:63)=workdat(63:1:-1) + call interleave63(a,1) + call graycode(a,63,1) + + psum=0. + do j=1,63 + i=a(j)+1 + x=s3a(i,j) + s3a(i,j)=0. + psum=psum + x + s3a(i,j)=x + enddo + p=psum/63.0 + + return +end subroutine getpp diff --git a/map65/libm65/f77_wisdom.f b/map65/libm65/f77_wisdom.f index 5fd8b3a6..b0a72585 100755..100644 --- a/map65/libm65/f77_wisdom.f +++ b/map65/libm65/f77_wisdom.f @@ -1,45 +1,45 @@ - subroutine write_char(c, iunit)
- character c
- integer iunit
- write(iunit,1000) c
- 1000 format(a,$)
- end
-
- subroutine export_wisdom_to_file(iunit)
- integer iunit
- external write_char
-c call dfftw_export_wisdom(write_char, iunit)
- call sfftw_export_wisdom(write_char, iunit)
- end
-
- 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 import_wisdom_from_file(isuccess, iunit)
- integer isuccess
- integer iunit
- external read_char
-c call dfftw_import_wisdom(isuccess, read_char, iunit)
- call sfftw_import_wisdom(isuccess, read_char, iunit)
- end
+ subroutine write_char(c, iunit) + character c + integer iunit + write(iunit,1000) c + 1000 format(a,$) + end + + subroutine export_wisdom_to_file(iunit) + integer iunit + external write_char +c call dfftw_export_wisdom(write_char, iunit) + call sfftw_export_wisdom(write_char, iunit) + end + + 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 import_wisdom_from_file(isuccess, iunit) + integer isuccess + integer iunit + external read_char +c call dfftw_import_wisdom(isuccess, read_char, iunit) + call sfftw_import_wisdom(isuccess, read_char, iunit) + end diff --git a/map65/libm65/fchisq.f90 b/map65/libm65/fchisq.f90 index 3de0d6c4..7d030583 100755..100644 --- a/map65/libm65/fchisq.f90 +++ b/map65/libm65/fchisq.f90 @@ -1,77 +1,77 @@ -real function fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax)
-
- use timer_module, only: timer
- parameter (NMAX=60*96000) !Samples per 60 s
- complex cx(npts),cy(npts)
- real a(5)
- complex w,wstep,za,zb,z
- real ss(3000)
- complex csx(0:NMAX/64),csy(0:NMAX/64)
- data twopi/6.283185307/a1,a2,a3/99.,99.,99./
- save
-
- call timer('fchisq ',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 X and Y signals
- csx(0)=0.
- csy(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
-! 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
- csx(i)=csx(i-1) + w*cx(i)
- csy(i)=csy(i-1) + w*cy(i)
- enddo
- endif
-
-! Compute 1/2-symbol powers at 1/16-symbol steps.
- fac=1.e-4
- pol=a(4)/57.2957795
- aa=cos(pol)
- bb=sin(pol)
-
- do i=1,nout
- j=i*nsps/ndiv
- k=j-nsph
- ss(i)=0.
- if(k.ge.1) then
- za=csx(j)-csx(k)
- zb=csy(j)-csy(k)
- z=aa*za + bb*zb
- 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
- fchisq=-ccfmax
- call timer('fchisq ',1)
-
- return
-end function fchisq
+real function fchisq(cx,cy,npts,fsample,nflip,a,ccfmax,dtmax) + + use timer_module, only: timer + parameter (NMAX=60*96000) !Samples per 60 s + complex cx(npts),cy(npts) + real a(5) + complex w,wstep,za,zb,z + real ss(3000) + complex csx(0:NMAX/64),csy(0:NMAX/64) + data twopi/6.283185307/a1,a2,a3/99.,99.,99./ + save + + call timer('fchisq ',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 X and Y signals + csx(0)=0. + csy(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 +! 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 + csx(i)=csx(i-1) + w*cx(i) + csy(i)=csy(i-1) + w*cy(i) + enddo + endif + +! Compute 1/2-symbol powers at 1/16-symbol steps. + fac=1.e-4 + pol=a(4)/57.2957795 + aa=cos(pol) + bb=sin(pol) + + do i=1,nout + j=i*nsps/ndiv + k=j-nsph + ss(i)=0. + if(k.ge.1) then + za=csx(j)-csx(k) + zb=csy(j)-csy(k) + z=aa*za + bb*zb + 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 + fchisq=-ccfmax + call timer('fchisq ',1) + + return +end function fchisq diff --git a/map65/libm65/fchisq0.f90 b/map65/libm65/fchisq0.f90 index 742df078..2c62f275 100755..100644 --- a/map65/libm65/fchisq0.f90 +++ b/map65/libm65/fchisq0.f90 @@ -1,23 +1,23 @@ -real function fchisq0(y,npts,a)
-
- real y(npts),a(4)
-
-! rewind 51
- chisq = 0.
- do i=1,npts
- x=i
- z=(x-a(3))/(0.5*a(4))
- yfit=a(1)
- if(abs(z).lt.3.0) then
- d=1.0 + z*z
- yfit=a(1) + a(2) * (1.0/d - 0.1)
- endif
- chisq=chisq + (y(i) - yfit)**2
-! write(51,3001) i,y(i),yfit,y(i)-yfit
-!3001 format(i5,3f10.4)
- enddo
- fchisq0=chisq
-
- return
-end function fchisq0
-
+real function fchisq0(y,npts,a) + + real y(npts),a(4) + +! rewind 51 + chisq = 0. + do i=1,npts + x=i + z=(x-a(3))/(0.5*a(4)) + yfit=a(1) + if(abs(z).lt.3.0) then + d=1.0 + z*z + yfit=a(1) + a(2) * (1.0/d - 0.1) + endif + chisq=chisq + (y(i) - yfit)**2 +! write(51,3001) i,y(i),yfit,y(i)-yfit +!3001 format(i5,3f10.4) + enddo + fchisq0=chisq + + return +end function fchisq0 + diff --git a/map65/libm65/fftw3.f b/map65/libm65/fftw3.f index 90748b2f..3410184c 100755..100644 --- a/map65/libm65/fftw3.f +++ b/map65/libm65/fftw3.f @@ -1,64 +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)
+ 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/map65/libm65/fftw3.f90 b/map65/libm65/fftw3.f90 index f1c8775b..440ccc28 100755..100644 --- a/map65/libm65/fftw3.f90 +++ b/map65/libm65/fftw3.f90 @@ -1,64 +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)
+ 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/map65/libm65/fil6521.f90 b/map65/libm65/fil6521.f90 index 3b1899c2..f588d0c1 100755..100644 --- a/map65/libm65/fil6521.f90 +++ b/map65/libm65/fil6521.f90 @@ -1,44 +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-1)/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
+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-1)/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/map65/libm65/filbig.f90 b/map65/libm65/filbig.f90 index bafab955..ada8ccc0 100755..100644 --- a/map65/libm65/filbig.f90 +++ b/map65/libm65/filbig.f90 @@ -1,132 +1,132 @@ -subroutine filbig(dd,nmax,f0,newdat,nfsample,xpol,c4a,c4b,n4)
-
-! Filter and downsample complex data stored in array dd(4,nmax).
-! Output is downsampled from 96000 Hz to 1375.125 Hz.
-
- use timer_module, only: timer
- parameter (MAXFFT1=5376000,MAXFFT2=77175)
- real*4 dd(4,nmax) !Input data
- complex ca(MAXFFT1),cb(MAXFFT1) !FFTs of input
- complex c4a(MAXFFT2),c4b(MAXFFT2) !Output data
- real*8 df
- real halfpulse(8) !Impulse response of filter (one sided)
- complex cfilt(MAXFFT2) !Filter (complex; imag = 0)
- real rfilt(MAXFFT2) !Filter (real)
- integer*8 plan1,plan2,plan3,plan4,plan5
- logical first,xpol
- include 'fftw3.f'
- common/cacb/ca,cb
- equivalence (rfilt,cfilt)
- data first/.true./,npatience/1/
- data halfpulse/114.97547150,36.57879257,-20.93789101, &
- 5.89886379,1.59355187,-2.49138308,0.60910773,-0.04248129/
- save
-
- if(nmax.lt.0) go to 900
-
- nfft1=MAXFFT1
- nfft2=MAXFFT2
- if(nfsample.eq.95238) then
- nfft1=5120000
- nfft2=74088
- endif
-
- 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,nfft1,cb,cb,FFTW_BACKWARD,nflags)
- call sfftw_plan_dft_1d(plan3,nfft2,c4a,c4a,FFTW_FORWARD,nflags)
- call sfftw_plan_dft_1d(plan4,nfft2,c4b,c4b,FFTW_FORWARD,nflags)
- call sfftw_plan_dft_1d(plan5,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 sfftw_execute(plan5)
-
- base=cfilt(nfft2/2+1)
- do i=1,nfft2
- rfilt(i)=real(cfilt(i))-base
- enddo
-
- df=96000.d0/nfft1
- if(nfsample.eq.95238) df=95238.1d0/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 ca and cb.
-
- if(newdat.ne.0 .or. sum(abs(ca)).eq.0.0) then !### Test on ca should be unnecessary?
- nz=min(nmax,nfft1)
- do i=1,nz
- ca(i)=cmplx(dd(1,i),dd(2,i))
- if(xpol) cb(i)=cmplx(dd(3,i),dd(4,i))
- enddo
-
- if(nmax.lt.nfft1) then
- do i=nmax+1,nfft1
- ca(i)=0.
- if(xpol) cb(i)=0.
- enddo
- endif
- call timer('FFTbig ',0)
- call sfftw_execute(plan1)
- if(xpol) call sfftw_execute(plan2)
- call timer('FFTbig ',1)
- newdat=0
- endif
-
-! NB: f0 is the frequency at which we want our filter centered.
-! i0 is the bin number in ca and cb closest to f0.
-
- i0=nint(f0/df) + 1
- nh=nfft2/2
- do i=1,nh !Copy data into c4a and c4b,
- j=i0+i-1 !and apply the filter function
- if(j.ge.1 .and. j.le.nfft1) then
- c4a(i)=rfilt(i)*ca(j)
- if(xpol) c4b(i)=rfilt(i)*cb(j)
- else
- c4a(i)=0.
- if(xpol) c4b(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)
- if(xpol) c4b(i)=rfilt(i)*cb(j)
- enddo
-
-! Do the short reverse transform, to go back to time domain.
- call timer('FFTsmall',0)
- call sfftw_execute(plan3)
- if(xpol) call sfftw_execute(plan4)
- call timer('FFTsmall',1)
- n4=min(nmax/64,nfft2)
- go to 999
-
-900 call sfftw_destroy_plan(plan1)
- call sfftw_destroy_plan(plan2)
- call sfftw_destroy_plan(plan3)
- call sfftw_destroy_plan(plan4)
- call sfftw_destroy_plan(plan5)
-
-999 return
-end subroutine filbig
+subroutine filbig(dd,nmax,f0,newdat,nfsample,xpol,c4a,c4b,n4) + +! Filter and downsample complex data stored in array dd(4,nmax). +! Output is downsampled from 96000 Hz to 1375.125 Hz. + + use timer_module, only: timer + parameter (MAXFFT1=5376000,MAXFFT2=77175) + real*4 dd(4,nmax) !Input data + complex ca(MAXFFT1),cb(MAXFFT1) !FFTs of input + complex c4a(MAXFFT2),c4b(MAXFFT2) !Output data + real*8 df + real halfpulse(8) !Impulse response of filter (one sided) + complex cfilt(MAXFFT2) !Filter (complex; imag = 0) + real rfilt(MAXFFT2) !Filter (real) + integer*8 plan1,plan2,plan3,plan4,plan5 + logical first,xpol + include 'fftw3.f' + common/cacb/ca,cb + equivalence (rfilt,cfilt) + data first/.true./,npatience/1/ + data halfpulse/114.97547150,36.57879257,-20.93789101, & + 5.89886379,1.59355187,-2.49138308,0.60910773,-0.04248129/ + save + + if(nmax.lt.0) go to 900 + + nfft1=MAXFFT1 + nfft2=MAXFFT2 + if(nfsample.eq.95238) then + nfft1=5120000 + nfft2=74088 + endif + + 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,nfft1,cb,cb,FFTW_BACKWARD,nflags) + call sfftw_plan_dft_1d(plan3,nfft2,c4a,c4a,FFTW_FORWARD,nflags) + call sfftw_plan_dft_1d(plan4,nfft2,c4b,c4b,FFTW_FORWARD,nflags) + call sfftw_plan_dft_1d(plan5,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 sfftw_execute(plan5) + + base=cfilt(nfft2/2+1) + do i=1,nfft2 + rfilt(i)=real(cfilt(i))-base + enddo + + df=96000.d0/nfft1 + if(nfsample.eq.95238) df=95238.1d0/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 ca and cb. + + if(newdat.ne.0 .or. sum(abs(ca)).eq.0.0) then !### Test on ca should be unnecessary? + nz=min(nmax,nfft1) + do i=1,nz + ca(i)=cmplx(dd(1,i),dd(2,i)) + if(xpol) cb(i)=cmplx(dd(3,i),dd(4,i)) + enddo + + if(nmax.lt.nfft1) then + do i=nmax+1,nfft1 + ca(i)=0. + if(xpol) cb(i)=0. + enddo + endif + call timer('FFTbig ',0) + call sfftw_execute(plan1) + if(xpol) call sfftw_execute(plan2) + call timer('FFTbig ',1) + newdat=0 + endif + +! NB: f0 is the frequency at which we want our filter centered. +! i0 is the bin number in ca and cb closest to f0. + + i0=nint(f0/df) + 1 + nh=nfft2/2 + do i=1,nh !Copy data into c4a and c4b, + j=i0+i-1 !and apply the filter function + if(j.ge.1 .and. j.le.nfft1) then + c4a(i)=rfilt(i)*ca(j) + if(xpol) c4b(i)=rfilt(i)*cb(j) + else + c4a(i)=0. + if(xpol) c4b(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) + if(xpol) c4b(i)=rfilt(i)*cb(j) + enddo + +! Do the short reverse transform, to go back to time domain. + call timer('FFTsmall',0) + call sfftw_execute(plan3) + if(xpol) call sfftw_execute(plan4) + call timer('FFTsmall',1) + n4=min(nmax/64,nfft2) + go to 999 + +900 call sfftw_destroy_plan(plan1) + call sfftw_destroy_plan(plan2) + call sfftw_destroy_plan(plan3) + call sfftw_destroy_plan(plan4) + call sfftw_destroy_plan(plan5) + +999 return +end subroutine filbig diff --git a/map65/libm65/fmtmsg.f90 b/map65/libm65/fmtmsg.f90 index 27d97ed6..2ceb8155 100755..100644 --- a/map65/libm65/fmtmsg.f90 +++ b/map65/libm65/fmtmsg.f90 @@ -1,21 +1,21 @@ -subroutine fmtmsg(msg,iz)
-
- character*22 msg
-
-! 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 100
- msg=msg(1:ib2)//msg(ib2+2:)
- iz=iz-1
- enddo
-
-100 return
-end subroutine fmtmsg
+subroutine fmtmsg(msg,iz) + + character*22 msg + +! 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 100 + msg=msg(1:ib2)//msg(ib2+2:) + iz=iz-1 + enddo + +100 return +end subroutine fmtmsg diff --git a/map65/libm65/four2a.f90 b/map65/libm65/four2a.f90 index 16a86bc5..fc46109e 100755..100644 --- a/map65/libm65/four2a.f90 +++ b/map65/libm65/four2a.f90 @@ -1,115 +1,115 @@ -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.
-
-! This version of four2a makes calls to the FFTW library to do the
-! actual computations.
-
- use fftw3
- parameter (NPMAX=2100) !Max numberf of stored plans
- parameter (NSMALL=16384) !Max size of "small" FFTs
- complex a(nfft+1) !Array to be transformed
- complex aa(NSMALL) !Local copy of "small" a()
- integer nn(NPMAX),ns(NPMAX),nf(NPMAX) !Params of stored plans
- integer*8 nl(NPMAX),nloc !More params of plans
- integer*8 plan(NPMAX) !Pointers to stored plans
- logical found_plan
- data nplan/0/ !Number of stored plans
- common/patience/npatience,nthreads !Patience and threads for FFTW plans
- save plan,nplan,nn,ns,nf,nl
-
- if(nfft.lt.0) go to 999
-
- nloc=loc(a)
-
- found_plan = .false.
- !$omp critical(four2a_setup)
- do i=1,nplan
- if(nfft.eq.nn(i) .and. isign.eq.ns(i) .and. &
- iform.eq.nf(i) .and. nloc.eq.nl(i)) then
- found_plan = .true.
- exit
- end if
- enddo
-
- if(i.ge.NPMAX) stop 'Too many FFTW plans requested.'
-
- if (.not. found_plan) then
- 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
- aa(1:jz)=a(1:jz)
- endif
-
- !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls
- 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
- !$omp end critical(fftw)
-
- if(nfft.le.NSMALL) then
- jz=nfft
- if(iform.eq.0) jz=nfft/2
- a(1:jz)=aa(1:jz)
- endif
- end if
- !$omp end critical(four2a_setup)
-
- call sfftw_execute(plan(i))
- return
-
-999 continue
-
- !$omp critical(four2a)
- do i=1,nplan
-! The test is only to silence a compiler warning:
- if(ndim.ne.-999) then
- !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls
- call sfftw_destroy_plan(plan(i))
- !$omp end critical(fftw)
- end if
- enddo
-
- nplan=0
- !$omp end critical(four2a)
-
- return
-end subroutine four2a
+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. + +! This version of four2a makes calls to the FFTW library to do the +! actual computations. + + use fftw3 + parameter (NPMAX=2100) !Max numberf of stored plans + parameter (NSMALL=16384) !Max size of "small" FFTs + complex a(nfft+1) !Array to be transformed + complex aa(NSMALL) !Local copy of "small" a() + integer nn(NPMAX),ns(NPMAX),nf(NPMAX) !Params of stored plans + integer*8 nl(NPMAX),nloc !More params of plans + integer*8 plan(NPMAX) !Pointers to stored plans + logical found_plan + data nplan/0/ !Number of stored plans + common/patience/npatience,nthreads !Patience and threads for FFTW plans + save plan,nplan,nn,ns,nf,nl + + if(nfft.lt.0) go to 999 + + nloc=loc(a) + + found_plan = .false. + !$omp critical(four2a_setup) + do i=1,nplan + if(nfft.eq.nn(i) .and. isign.eq.ns(i) .and. & + iform.eq.nf(i) .and. nloc.eq.nl(i)) then + found_plan = .true. + exit + end if + enddo + + if(i.ge.NPMAX) stop 'Too many FFTW plans requested.' + + if (.not. found_plan) then + 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 + aa(1:jz)=a(1:jz) + endif + + !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls + 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 + !$omp end critical(fftw) + + if(nfft.le.NSMALL) then + jz=nfft + if(iform.eq.0) jz=nfft/2 + a(1:jz)=aa(1:jz) + endif + end if + !$omp end critical(four2a_setup) + + call sfftw_execute(plan(i)) + return + +999 continue + + !$omp critical(four2a) + do i=1,nplan +! The test is only to silence a compiler warning: + if(ndim.ne.-999) then + !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls + call sfftw_destroy_plan(plan(i)) + !$omp end critical(fftw) + end if + enddo + + nplan=0 + !$omp end critical(four2a) + + return +end subroutine four2a diff --git a/map65/libm65/ftninit.f90 b/map65/libm65/ftninit.f90 index c6c90716..26911a19 100755..100644 --- a/map65/libm65/ftninit.f90 +++ b/map65/libm65/ftninit.f90 @@ -1,31 +1,31 @@ -subroutine ftninit(appd)
-
- use timer_module, only: timer
- use, intrinsic :: iso_c_binding, only: C_NULL_CHAR
- use FFTW3
- character*(*) appd
- character addpfx*8
- character wisfile*256
- common/pfxcom/addpfx
-
- addpfx=' '
- call pfxdump(appd//'/prefixes.txt')
- open(12,file=appd//'/wb_q65.txt',status='unknown')
- open(13,file=appd//'/map65.log',status='unknown')
-! open(19,file=appd//'/livecq.txt',status='unknown') ! not written with new livecq code
- open(21,file=appd//'/map65_rx.log',status='unknown',access='append',err=950)
- open(26,file=appd//'/tmp26.txt',status='unknown')
-
-! Import FFTW wisdom, if available:
- iret=fftwf_init_threads() !Initialize FFTW threading
-! Default to 1 thread, but use nthreads for the big ones
- call fftwf_plan_with_nthreads(1)
-! Import FFTW wisdom, if available
- wisfile=trim(appd)//'/m65_wisdom.dat'// C_NULL_CHAR
- iret=fftwf_import_wisdom_from_filename(wisfile)
- return
-
-950 write(0,*) '!Error opening ALL65.TXT'
- stop
-
-end subroutine ftninit
+subroutine ftninit(appd) + + use timer_module, only: timer + use, intrinsic :: iso_c_binding, only: C_NULL_CHAR + use FFTW3 + character*(*) appd + character addpfx*8 + character wisfile*256 + common/pfxcom/addpfx + + addpfx=' ' + call pfxdump(appd//'/prefixes.txt') + open(12,file=appd//'/wb_q65.txt',status='unknown') + open(13,file=appd//'/map65.log',status='unknown') +! open(19,file=appd//'/livecq.txt',status='unknown') ! not written with new livecq code + open(21,file=appd//'/map65_rx.log',status='unknown',access='append',err=950) + open(26,file=appd//'/tmp26.txt',status='unknown') + +! Import FFTW wisdom, if available: + iret=fftwf_init_threads() !Initialize FFTW threading +! Default to 1 thread, but use nthreads for the big ones + call fftwf_plan_with_nthreads(1) +! Import FFTW wisdom, if available + wisfile=trim(appd)//'/m65_wisdom.dat'// C_NULL_CHAR + iret=fftwf_import_wisdom_from_filename(wisfile) + return + +950 write(0,*) '!Error opening ALL65.TXT' + stop + +end subroutine ftninit diff --git a/map65/libm65/ftnquit.f90 b/map65/libm65/ftnquit.f90 index 518f1f30..b74e2b9e 100755..100644 --- a/map65/libm65/ftnquit.f90 +++ b/map65/libm65/ftnquit.f90 @@ -1,8 +1,8 @@ -subroutine ftnquit
-
-! Destroy the FFTW plans
- call four2a(a,-1,1,1,1)
- call filbig(id,-1,1,f0,newdat,nfsample,c4a,c4b,n4)
-
- return
-end subroutine ftnquit
+subroutine ftnquit + +! Destroy the FFTW plans + call four2a(a,-1,1,1,1) + call filbig(id,-1,1,f0,newdat,nfsample,c4a,c4b,n4) + + return +end subroutine ftnquit diff --git a/map65/libm65/ftrsd2.c b/map65/libm65/ftrsd2.c index 2be186f0..7d8dd366 100755..100644 --- a/map65/libm65/ftrsd2.c +++ b/map65/libm65/ftrsd2.c @@ -1,213 +1,213 @@ -/*
- ftrsd2.c
-
- A soft-decision decoder for the JT65 (63,12) Reed-Solomon code.
-
- This decoding scheme is built around Phil Karn's Berlekamp-Massey
- errors and erasures decoder. The approach is inspired by a number of
- publications, including the stochastic Chase decoder described
- in "Stochastic Chase Decoding of Reed-Solomon Codes", by Leroux et al.,
- IEEE Communications Letters, Vol. 14, No. 9, September 2010 and
- "Soft-Decision Decoding of Reed-Solomon Codes Using Successive Error-
- and-Erasure Decoding," by Soo-Woong Lee and B. V. K. Vijaya Kumar.
-
- Steve Franke K9AN and Joe Taylor K1JT
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <string.h>
-#include "rs2.h"
-
-static void *rs;
-void getpp_(int workdat[], float *pp);
-
-void ftrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[],
- int* ntrials0, int correct[], int param[], int ntry[])
-{
- int rxdat[63], rxprob[63], rxdat2[63], rxprob2[63];
- int workdat[63];
- int indexes[63];
- int era_pos[51];
- int i, j, numera, nerr, nn=63;
- int ntrials = *ntrials0;
- int nhard=0,nhard_min=32768,nsoft=0,nsoft_min=32768;
- int ntotal=0,ntotal_min=32768,ncandidates;
- int nera_best=0;
- float pp,pp1,pp2;
- static unsigned int nseed;
-
-// Power-percentage symbol metrics - composite gnnf/hf
- int perr[8][8] = {
- { 4, 9, 11, 13, 14, 14, 15, 15},
- { 2, 20, 20, 30, 40, 50, 50, 50},
- { 7, 24, 27, 40, 50, 50, 50, 50},
- {13, 25, 35, 46, 52, 70, 50, 50},
- {17, 30, 42, 54, 55, 64, 71, 70},
- {25, 39, 48, 57, 64, 66, 77, 77},
- {32, 45, 54, 63, 66, 75, 78, 83},
- {51, 58, 57, 66, 72, 77, 82, 86}};
-
-
-// Initialize the KA9Q Reed-Solomon encoder/decoder
- unsigned int symsize=6, gfpoly=0x43, fcr=3, prim=1, nroots=51;
- rs=init_rs_int(symsize, gfpoly, fcr, prim, nroots, 0);
-
-// Reverse the received symbol vectors for BM decoder
- for (i=0; i<63; i++) {
- rxdat[i]=mrsym[62-i];
- rxprob[i]=mrprob[62-i];
- rxdat2[i]=mr2sym[62-i];
- rxprob2[i]=mr2prob[62-i];
- }
-
-// Sort rxprob to find indexes of the least reliable symbols
- int k, pass, tmp, nsym=63;
- int probs[63];
- for (i=0; i<63; i++) {
- indexes[i]=i;
- probs[i]=rxprob[i];
- }
- for (pass = 1; pass <= nsym-1; pass++) {
- for (k = 0; k < nsym - pass; k++) {
- if( probs[k] < probs[k+1] ) {
- tmp = probs[k];
- probs[k] = probs[k+1];
- probs[k+1] = tmp;
- tmp = indexes[k];
- indexes[k] = indexes[k+1];
- indexes[k+1] = tmp;
- }
- }
- }
-
-// See if we can decode using BM HDD, and calculate the syndrome vector.
- memset(era_pos,0,51*sizeof(int));
- numera=0;
- memcpy(workdat,rxdat,sizeof(rxdat));
- nerr=decode_rs_int(rs,workdat,era_pos,numera,1);
- if( nerr >= 0 ) {
- // Hard-decision decoding succeeded. Save codeword and some parameters.
- nhard=0;
- for (i=0; i<63; i++) {
- if( workdat[i] != rxdat[i] ) nhard=nhard+1;
- }
- memcpy(correct,workdat,63*sizeof(int));
- param[0]=0;
- param[1]=nhard;
- param[2]=0;
- param[3]=0;
- param[4]=0;
- param[5]=0;
- param[7]=1000*1000;
- ntry[0]=0;
- return;
- }
-
-/*
-Hard-decision decoding failed. Try the FT soft-decision method.
-Generate random erasure-locator vectors and see if any of them
-decode. This will generate a list of "candidate" codewords. The
-soft distance between each candidate codeword and the received
-word is estimated by finding the largest (pp1) and second-largest
-(pp2) outputs from a synchronized filter-bank operating on the
-symbol spectra, and using these to decide which candidate
-codeword is "best".
-*/
-
- nseed=1; //Seed for random numbers
- float ratio;
- int thresh, nsum;
- int thresh0[63];
- ncandidates=0;
- nsum=0;
- int ii,jj;
- for (i=0; i<nn; i++) {
- nsum=nsum+rxprob[i];
- j = indexes[62-i];
- ratio = (float)rxprob2[j]/((float)rxprob[j]+0.01);
- ii = 7.999*ratio;
- jj = (62-i)/8;
- thresh0[i] = 1.3*perr[ii][jj];
- }
- if(nsum<=0) return;
-
- pp1=0.0;
- pp2=0.0;
- for (k=1; k<=ntrials; k++) {
- memset(era_pos,0,51*sizeof(int));
- memcpy(workdat,rxdat,sizeof(rxdat));
-
-/*
-Mark a subset of the symbols as erasures.
-Run through the ranked symbols, starting with the worst, i=0.
-NB: j is the symbol-vector index of the symbol with rank i.
-*/
- numera=0;
- for (i=0; i<nn; i++) {
- j = indexes[62-i];
- thresh=thresh0[i];
- long int ir;
-
-// Generate a random number ir, 0 <= ir < 100 (see POSIX.1-2001 example).
- nseed = nseed * 1103515245 + 12345;
- ir = (unsigned)(nseed/65536) % 32768;
- ir = (100*ir)/32768;
-
- if((ir < thresh ) && numera < 51) {
- era_pos[numera]=j;
- numera=numera+1;
- }
- }
-
- nerr=decode_rs_int(rs,workdat,era_pos,numera,0);
- if( nerr >= 0 ) {
- // We have a candidate codeword. Find its hard and soft distance from
- // the received word. Also find pp1 and pp2 from the full array
- // s3(64,63) of synchronized symbol spectra.
- ncandidates=ncandidates+1;
- nhard=0;
- nsoft=0;
- for (i=0; i<63; i++) {
- if(workdat[i] != rxdat[i]) {
- nhard=nhard+1;
- if(workdat[i] != rxdat2[i]) {
- nsoft=nsoft+rxprob[i];
- }
- }
- }
- nsoft=63*nsoft/nsum;
- ntotal=nsoft+nhard;
-
- getpp_(workdat,&pp);
- if(pp>pp1) {
- pp2=pp1;
- pp1=pp;
- nsoft_min=nsoft;
- nhard_min=nhard;
- ntotal_min=ntotal;
- memcpy(correct,workdat,63*sizeof(int));
- nera_best=numera;
- ntry[0]=k;
- } else {
- if(pp>pp2 && pp!=pp1) pp2=pp;
- }
- if(nhard_min <= 41 && ntotal_min <= 71) break;
- }
- if(k == ntrials) ntry[0]=k;
- }
-
- param[0]=ncandidates;
- param[1]=nhard_min;
- param[2]=nsoft_min;
- param[3]=nera_best;
- param[4]= pp1 > 0 ? 1000.0*pp2/pp1 : 1000.0;
- param[5]=ntotal_min;
- param[6]=ntry[0];
- param[7]=1000.0*pp2;
- param[8]=1000.0*pp1;
- if(param[0]==0) param[2]=-1;
- return;
-}
+/* + ftrsd2.c + + A soft-decision decoder for the JT65 (63,12) Reed-Solomon code. + + This decoding scheme is built around Phil Karn's Berlekamp-Massey + errors and erasures decoder. The approach is inspired by a number of + publications, including the stochastic Chase decoder described + in "Stochastic Chase Decoding of Reed-Solomon Codes", by Leroux et al., + IEEE Communications Letters, Vol. 14, No. 9, September 2010 and + "Soft-Decision Decoding of Reed-Solomon Codes Using Successive Error- + and-Erasure Decoding," by Soo-Woong Lee and B. V. K. Vijaya Kumar. + + Steve Franke K9AN and Joe Taylor K1JT + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <time.h> +#include <string.h> +#include "rs2.h" + +static void *rs; +void getpp_(int workdat[], float *pp); + +void ftrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], + int* ntrials0, int correct[], int param[], int ntry[]) +{ + int rxdat[63], rxprob[63], rxdat2[63], rxprob2[63]; + int workdat[63]; + int indexes[63]; + int era_pos[51]; + int i, j, numera, nerr, nn=63; + int ntrials = *ntrials0; + int nhard=0,nhard_min=32768,nsoft=0,nsoft_min=32768; + int ntotal=0,ntotal_min=32768,ncandidates; + int nera_best=0; + float pp,pp1,pp2; + static unsigned int nseed; + +// Power-percentage symbol metrics - composite gnnf/hf + int perr[8][8] = { + { 4, 9, 11, 13, 14, 14, 15, 15}, + { 2, 20, 20, 30, 40, 50, 50, 50}, + { 7, 24, 27, 40, 50, 50, 50, 50}, + {13, 25, 35, 46, 52, 70, 50, 50}, + {17, 30, 42, 54, 55, 64, 71, 70}, + {25, 39, 48, 57, 64, 66, 77, 77}, + {32, 45, 54, 63, 66, 75, 78, 83}, + {51, 58, 57, 66, 72, 77, 82, 86}}; + + +// Initialize the KA9Q Reed-Solomon encoder/decoder + unsigned int symsize=6, gfpoly=0x43, fcr=3, prim=1, nroots=51; + rs=init_rs_int(symsize, gfpoly, fcr, prim, nroots, 0); + +// Reverse the received symbol vectors for BM decoder + for (i=0; i<63; i++) { + rxdat[i]=mrsym[62-i]; + rxprob[i]=mrprob[62-i]; + rxdat2[i]=mr2sym[62-i]; + rxprob2[i]=mr2prob[62-i]; + } + +// Sort rxprob to find indexes of the least reliable symbols + int k, pass, tmp, nsym=63; + int probs[63]; + for (i=0; i<63; i++) { + indexes[i]=i; + probs[i]=rxprob[i]; + } + for (pass = 1; pass <= nsym-1; pass++) { + for (k = 0; k < nsym - pass; k++) { + if( probs[k] < probs[k+1] ) { + tmp = probs[k]; + probs[k] = probs[k+1]; + probs[k+1] = tmp; + tmp = indexes[k]; + indexes[k] = indexes[k+1]; + indexes[k+1] = tmp; + } + } + } + +// See if we can decode using BM HDD, and calculate the syndrome vector. + memset(era_pos,0,51*sizeof(int)); + numera=0; + memcpy(workdat,rxdat,sizeof(rxdat)); + nerr=decode_rs_int(rs,workdat,era_pos,numera,1); + if( nerr >= 0 ) { + // Hard-decision decoding succeeded. Save codeword and some parameters. + nhard=0; + for (i=0; i<63; i++) { + if( workdat[i] != rxdat[i] ) nhard=nhard+1; + } + memcpy(correct,workdat,63*sizeof(int)); + param[0]=0; + param[1]=nhard; + param[2]=0; + param[3]=0; + param[4]=0; + param[5]=0; + param[7]=1000*1000; + ntry[0]=0; + return; + } + +/* +Hard-decision decoding failed. Try the FT soft-decision method. +Generate random erasure-locator vectors and see if any of them +decode. This will generate a list of "candidate" codewords. The +soft distance between each candidate codeword and the received +word is estimated by finding the largest (pp1) and second-largest +(pp2) outputs from a synchronized filter-bank operating on the +symbol spectra, and using these to decide which candidate +codeword is "best". +*/ + + nseed=1; //Seed for random numbers + float ratio; + int thresh, nsum; + int thresh0[63]; + ncandidates=0; + nsum=0; + int ii,jj; + for (i=0; i<nn; i++) { + nsum=nsum+rxprob[i]; + j = indexes[62-i]; + ratio = (float)rxprob2[j]/((float)rxprob[j]+0.01); + ii = 7.999*ratio; + jj = (62-i)/8; + thresh0[i] = 1.3*perr[ii][jj]; + } + if(nsum<=0) return; + + pp1=0.0; + pp2=0.0; + for (k=1; k<=ntrials; k++) { + memset(era_pos,0,51*sizeof(int)); + memcpy(workdat,rxdat,sizeof(rxdat)); + +/* +Mark a subset of the symbols as erasures. +Run through the ranked symbols, starting with the worst, i=0. +NB: j is the symbol-vector index of the symbol with rank i. +*/ + numera=0; + for (i=0; i<nn; i++) { + j = indexes[62-i]; + thresh=thresh0[i]; + long int ir; + +// Generate a random number ir, 0 <= ir < 100 (see POSIX.1-2001 example). + nseed = nseed * 1103515245 + 12345; + ir = (unsigned)(nseed/65536) % 32768; + ir = (100*ir)/32768; + + if((ir < thresh ) && numera < 51) { + era_pos[numera]=j; + numera=numera+1; + } + } + + nerr=decode_rs_int(rs,workdat,era_pos,numera,0); + if( nerr >= 0 ) { + // We have a candidate codeword. Find its hard and soft distance from + // the received word. Also find pp1 and pp2 from the full array + // s3(64,63) of synchronized symbol spectra. + ncandidates=ncandidates+1; + nhard=0; + nsoft=0; + for (i=0; i<63; i++) { + if(workdat[i] != rxdat[i]) { + nhard=nhard+1; + if(workdat[i] != rxdat2[i]) { + nsoft=nsoft+rxprob[i]; + } + } + } + nsoft=63*nsoft/nsum; + ntotal=nsoft+nhard; + + getpp_(workdat,&pp); + if(pp>pp1) { + pp2=pp1; + pp1=pp; + nsoft_min=nsoft; + nhard_min=nhard; + ntotal_min=ntotal; + memcpy(correct,workdat,63*sizeof(int)); + nera_best=numera; + ntry[0]=k; + } else { + if(pp>pp2 && pp!=pp1) pp2=pp; + } + if(nhard_min <= 41 && ntotal_min <= 71) break; + } + if(k == ntrials) ntry[0]=k; + } + + param[0]=ncandidates; + param[1]=nhard_min; + param[2]=nsoft_min; + param[3]=nera_best; + param[4]= pp1 > 0 ? 1000.0*pp2/pp1 : 1000.0; + param[5]=ntotal_min; + param[6]=ntry[0]; + param[7]=1000.0*pp2; + param[8]=1000.0*pp1; + if(param[0]==0) param[2]=-1; + return; +} diff --git a/map65/libm65/gen65.f90 b/map65/libm65/gen65.f90 index e63f25b7..f09d0868 100755..100644 --- a/map65/libm65/gen65.f90 +++ b/map65/libm65/gen65.f90 @@ -1,99 +1,99 @@ -subroutine gen65(message,mode65,samfac,nsendingsh,msgsent,iwave,nwave)
-
-! Encodes a JT65 message into a wavefile.
-! Executes in 17 ms on opti-745.
-
- use packjt
-
- parameter (NMAX=2*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 dt,phi,f,f0,dfgen,dphi,twopi,samfac
- integer*2 iwave(NMAX) !Generated wave file
- integer dgen(12)
- integer sent(63)
- logical first
- integer nprc(126)
- real pr(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/
- data twopi/6.283185307179586476d0/,first/.true./
- save
-
- if(first) then
- do i=1,126
- pr(i)=2*nprc(i)-1
- enddo
- first=.false.
- endif
-
- call chkmsg(message,cok,nspecial,flip)
- if(nspecial.eq.0) then
- call packmsg(message,dgen,itype) !Pack message into 72 bits
- nsendingsh=0
- if(iand(dgen(10),8).ne.0) nsendingsh=-1 !Plain text flag
-
- call rs_encode(dgen,sent)
- call interleave63(sent,1) !Apply interleaving
- call graycode(sent,63,1) !Apply Gray code
- nsym=126 !Symbols per transmission
- nsps=4096
- else
- nsym=32
- nsps=16384
- nsendingsh=1 !Flag for shorthand message
- endif
- if(mode65.eq.0) go to 900
-
-! Set up necessary constants
- dt=1.d0/(samfac*11025.d0)
- f0=118*11025.d0/1024
- dfgen=mode65*11025.d0/4096.d0
- phi=0.d0
- dphi=twopi*dt*f0
- i=0
- k=0
- do j=1,nsym
- if(message(1:5).ne.'@TUNE') then
- f=f0
- if(nspecial.ne.0 .and. mod(j,2).eq.0) f=f0+10*nspecial*dfgen
- if(nspecial.eq.0 .and. flip*pr(j).lt.0.0) then
- k=k+1
- f=f0+(sent(k)+2)*dfgen
- endif
- dphi=twopi*dt*f
- endif
- do ii=1,nsps
- phi=phi+dphi
- if(phi.gt.twopi) phi=phi-twopi
- xphi=phi
- i=i+1
- iwave(2*i-1)=32767.0*cos(xphi)
- iwave(2*i)=32767.0*sin(xphi)
- enddo
- enddo
-
- iwave(2*nsym*nsps+1:)=0
- nwave=2*nsym*nsps + 5512
- call unpackmsg(dgen,msgsent)
- 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
-
- if(nsendingsh.eq.1) then
- if(nspecial.eq.2) msgsent='RO'
- if(nspecial.eq.3) msgsent='RRR'
- if(nspecial.eq.4) msgsent='73'
- endif
-
-900 return
-end subroutine gen65
+subroutine gen65(message,mode65,samfac,nsendingsh,msgsent,iwave,nwave) + +! Encodes a JT65 message into a wavefile. +! Executes in 17 ms on opti-745. + + use packjt + + parameter (NMAX=2*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 dt,phi,f,f0,dfgen,dphi,twopi,samfac + integer*2 iwave(NMAX) !Generated wave file + integer dgen(12) + integer sent(63) + logical first + integer nprc(126) + real pr(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/ + data twopi/6.283185307179586476d0/,first/.true./ + save + + if(first) then + do i=1,126 + pr(i)=2*nprc(i)-1 + enddo + first=.false. + endif + + call chkmsg(message,cok,nspecial,flip) + if(nspecial.eq.0) then + call packmsg(message,dgen,itype) !Pack message into 72 bits + nsendingsh=0 + if(iand(dgen(10),8).ne.0) nsendingsh=-1 !Plain text flag + + call rs_encode(dgen,sent) + call interleave63(sent,1) !Apply interleaving + call graycode(sent,63,1) !Apply Gray code + nsym=126 !Symbols per transmission + nsps=4096 + else + nsym=32 + nsps=16384 + nsendingsh=1 !Flag for shorthand message + endif + if(mode65.eq.0) go to 900 + +! Set up necessary constants + dt=1.d0/(samfac*11025.d0) + f0=118*11025.d0/1024 + dfgen=mode65*11025.d0/4096.d0 + phi=0.d0 + dphi=twopi*dt*f0 + i=0 + k=0 + do j=1,nsym + if(message(1:5).ne.'@TUNE') then + f=f0 + if(nspecial.ne.0 .and. mod(j,2).eq.0) f=f0+10*nspecial*dfgen + if(nspecial.eq.0 .and. flip*pr(j).lt.0.0) then + k=k+1 + f=f0+(sent(k)+2)*dfgen + endif + dphi=twopi*dt*f + endif + do ii=1,nsps + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + i=i+1 + iwave(2*i-1)=32767.0*cos(xphi) + iwave(2*i)=32767.0*sin(xphi) + enddo + enddo + + iwave(2*nsym*nsps+1:)=0 + nwave=2*nsym*nsps + 5512 + call unpackmsg(dgen,msgsent) + 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 + + if(nsendingsh.eq.1) then + if(nspecial.eq.2) msgsent='RO' + if(nspecial.eq.3) msgsent='RRR' + if(nspecial.eq.4) msgsent='73' + endif + +900 return +end subroutine gen65 diff --git a/map65/libm65/gen_q65_cwave.f90 b/map65/libm65/gen_q65_cwave.f90 index 305d2e5c..115d1fc4 100755..100644 --- a/map65/libm65/gen_q65_cwave.f90 +++ b/map65/libm65/gen_q65_cwave.f90 @@ -1,52 +1,52 @@ -subroutine gen_q65_cwave(msg,ntxfreq,ntone_spacing,msgsent,cwave,nwave)
-
-! Encodes a Q65 message to yield complex cwave() at fsample = 96000 Hz
-
- use packjt
- use q65_encoding
- parameter (NMAX=60*96000)
- character*24 msg !w3sz was *22
- character*24 msgsent !w3sz was *22 !Message as it will be received
- character*37 msg37
- real*8 t,dt,phi,f,f0,dfgen,dphi,twopi,tsym
- complex cwave(NMAX)
- integer codeword(65),itone(85)
- integer icos7(0:6)
- data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array
- data twopi/6.283185307179586476d0/
- save
-
- msgsent=msg
- msg37=''
- msg37(1:24)=msg !w3sz was 1:22
- call get_q65_tones(msg37,codeword,itone)
-
-! Set up necessary constants
- nsym=85
- tsym=7200.d0/12000.d0
- dt=1.d0/96000.d0
- f0=ntxfreq
- dfgen=ntone_spacing*12000.d0/7200.d0
- phi=0.d0
- dphi=twopi*dt*f0
- i=0
- nwave=85*7200*96000.d0/12000.d0
- t=0.d0
- j0=0
- do i=1,nwave
- t=t+dt
- j=t/tsym + 1
- if(j.gt.85) exit
- if(j.ne.j0) then
- f=f0 + itone(j)*dfgen
- dphi=twopi*dt*f
- j0=j
- endif
- phi=phi+dphi
- if(phi.gt.twopi) phi=phi-twopi
- xphi=phi
- cwave(i)=cmplx(cos(xphi),-sin(xphi))
- enddo
-
-999 return
-end subroutine gen_q65_cwave
+subroutine gen_q65_cwave(msg,ntxfreq,ntone_spacing,msgsent,cwave,nwave) + +! Encodes a Q65 message to yield complex cwave() at fsample = 96000 Hz + + use packjt + use q65_encoding + parameter (NMAX=60*96000) + character*24 msg !w3sz was *22 + character*24 msgsent !w3sz was *22 !Message as it will be received + character*37 msg37 + real*8 t,dt,phi,f,f0,dfgen,dphi,twopi,tsym + complex cwave(NMAX) + integer codeword(65),itone(85) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array + data twopi/6.283185307179586476d0/ + save + + msgsent=msg + msg37='' + msg37(1:24)=msg !w3sz was 1:22 + call get_q65_tones(msg37,codeword,itone) + +! Set up necessary constants + nsym=85 + tsym=7200.d0/12000.d0 + dt=1.d0/96000.d0 + f0=ntxfreq + dfgen=ntone_spacing*12000.d0/7200.d0 + phi=0.d0 + dphi=twopi*dt*f0 + i=0 + nwave=85*7200*96000.d0/12000.d0 + t=0.d0 + j0=0 + do i=1,nwave + t=t+dt + j=t/tsym + 1 + if(j.gt.85) exit + if(j.ne.j0) then + f=f0 + itone(j)*dfgen + dphi=twopi*dt*f + j0=j + endif + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + cwave(i)=cmplx(cos(xphi),-sin(xphi)) + enddo + +999 return +end subroutine gen_q65_cwave diff --git a/map65/libm65/gen_q65_wave.f90 b/map65/libm65/gen_q65_wave.f90 index d9f258b5..bd91c8dd 100755..100644 --- a/map65/libm65/gen_q65_wave.f90 +++ b/map65/libm65/gen_q65_wave.f90 @@ -1,54 +1,54 @@ -subroutine gen_q65_wave(msg,ntxfreq,mode65,msgsent,iwave,nwave)
-
-! Encodes a Q65 message to yield complex iwave() at fsample = 11025 Hz
-
- use packjt
- use q65_encoding
- parameter (NMAX=2*60*11025)
- character*22 msg
- character*22 msgsent !Message as it will be received
- character*37 msg37
- real*8 t,dt,phi,f,f0,dfgen,dphi,twopi,tsym
- integer codeword(65),itone(85)
- integer*2 iwave(NMAX)
- integer icos7(0:6)
- data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array
- data twopi/6.283185307179586476d0/
- save
-
- msgsent=msg
- msg37=''
- msg37(1:22)=msg
- call get_q65_tones(msg37,codeword,itone)
-
-! Set up necessary constants
- nsym=85
- tsym=7200.d0/12000.d0
- dt=1.d0/11025.d0
- f0=ntxfreq
- ndf=2**(mode65-1)
- dfgen=ndf*12000.d0/7200.d0
- phi=0.d0
- dphi=twopi*dt*f0
- i=0
- iz=85*7200*11025.d0/12000.d0
- t=0.d0
- j0=0
- do i=1,iz
- t=t+dt
- j=t/tsym + 1.0
- if(j.ne.j0) then
- f=f0 + itone(j)*dfgen
- dphi=twopi*dt*f
- j0=j
- endif
- phi=phi+dphi
- if(phi.gt.twopi) phi=phi-twopi
- xphi=phi
- iwave(2*i-1)=32767.0*cos(xphi)
- iwave(2*i)=32767.0*sin(xphi)
- enddo
- nwave=2*iz
-
-999 return
-end subroutine gen_q65_wave
+subroutine gen_q65_wave(msg,ntxfreq,mode65,msgsent,iwave,nwave) + +! Encodes a Q65 message to yield complex iwave() at fsample = 11025 Hz + + use packjt + use q65_encoding + parameter (NMAX=2*60*11025) + character*22 msg + character*22 msgsent !Message as it will be received + character*37 msg37 + real*8 t,dt,phi,f,f0,dfgen,dphi,twopi,tsym + integer codeword(65),itone(85) + integer*2 iwave(NMAX) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array + data twopi/6.283185307179586476d0/ + save + + msgsent=msg + msg37='' + msg37(1:22)=msg + call get_q65_tones(msg37,codeword,itone) + +! Set up necessary constants + nsym=85 + tsym=7200.d0/12000.d0 + dt=1.d0/11025.d0 + f0=ntxfreq + ndf=2**(mode65-1) + dfgen=ndf*12000.d0/7200.d0 + phi=0.d0 + dphi=twopi*dt*f0 + i=0 + iz=85*7200*11025.d0/12000.d0 + t=0.d0 + j0=0 + do i=1,iz + t=t+dt + j=t/tsym + 1.0 + if(j.ne.j0) then + f=f0 + itone(j)*dfgen + dphi=twopi*dt*f + j0=j + endif + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + iwave(2*i-1)=32767.0*cos(xphi) + iwave(2*i)=32767.0*sin(xphi) + enddo + nwave=2*iz + +999 return +end subroutine gen_q65_wave diff --git a/map65/libm65/geocentric.f90 b/map65/libm65/geocentric.f90 index 11ea7cb6..59ed90b5 100755..100644 --- a/map65/libm65/geocentric.f90 +++ b/map65/libm65/geocentric.f90 @@ -1,17 +1,17 @@ -subroutine geocentric(alat,elev,hlt,erad)
-
- implicit real*8 (a-h,o-z)
-
-! IAU 1976 flattening f, equatorial radius a
- f = 1.d0/298.257d0
- a = 6378140.d0
- c = 1.d0/sqrt(1.d0 + (-2.d0 + f)*f*sin(alat)*sin(alat))
- arcf = (a*c + elev)*cos(alat)
- arsf = (a*(1.d0 - f)*(1.d0 - f)*c + elev)*sin(alat)
- hlt = datan2(arsf,arcf)
- erad = sqrt(arcf*arcf + arsf*arsf)
- erad = 0.001d0*erad
-
- return
-end subroutine geocentric
-
+subroutine geocentric(alat,elev,hlt,erad) + + implicit real*8 (a-h,o-z) + +! IAU 1976 flattening f, equatorial radius a + f = 1.d0/298.257d0 + a = 6378140.d0 + c = 1.d0/sqrt(1.d0 + (-2.d0 + f)*f*sin(alat)*sin(alat)) + arcf = (a*c + elev)*cos(alat) + arsf = (a*(1.d0 - f)*(1.d0 - f)*c + elev)*sin(alat) + hlt = datan2(arsf,arcf) + erad = sqrt(arcf*arcf + arsf*arsf) + erad = 0.001d0*erad + + return +end subroutine geocentric + diff --git a/map65/libm65/getdphi.f90 b/map65/libm65/getdphi.f90 index f44c2d06..e55d7120 100755..100644 --- a/map65/libm65/getdphi.f90 +++ b/map65/libm65/getdphi.f90 @@ -1,18 +1,18 @@ -subroutine getdphi(qphi)
-
- real qphi(12)
-
- s=0.
- c=0.
- do i=1,12
- th=i*30/57.2957795
- s=s+qphi(i)*sin(th)
- c=c+qphi(i)*cos(th)
- enddo
-
- dphi=57.2957795*atan2(s,c)
- write(*,1010) nint(dphi)
-1010 format('!Best-fit Dphi =',i4,' deg')
-
- return
- end
+subroutine getdphi(qphi) + + real qphi(12) + + s=0. + c=0. + do i=1,12 + th=i*30/57.2957795 + s=s+qphi(i)*sin(th) + c=c+qphi(i)*cos(th) + enddo + + dphi=57.2957795*atan2(s,c) + write(*,1010) nint(dphi) +1010 format('!Best-fit Dphi =',i4,' deg') + + return + end diff --git a/map65/libm65/getpfx1.f90 b/map65/libm65/getpfx1.f90 index cdd210de..40fcc369 100755..100644 --- a/map65/libm65/getpfx1.f90 +++ b/map65/libm65/getpfx1.f90 @@ -1,96 +1,96 @@ -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
- 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
-
+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 + 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/map65/libm65/getpfx2.f90 b/map65/libm65/getpfx2.f90 index c4104e62..d747e7f2 100755..100644 --- a/map65/libm65/getpfx2.f90 +++ b/map65/libm65/getpfx2.f90 @@ -1,24 +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
-
+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/map65/libm65/gran.c b/map65/libm65/gran.c index ceeb6da7..24b98650 100755..100644 --- a/map65/libm65/gran.c +++ b/map65/libm65/gran.c @@ -1,28 +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;
-}
+#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/map65/libm65/graycode.f90 b/map65/libm65/graycode.f90 index 0b36af3f..2074241a 100755..100644 --- a/map65/libm65/graycode.f90 +++ b/map65/libm65/graycode.f90 @@ -1,10 +1,10 @@ -subroutine graycode(dat,n,idir)
-
- integer dat(n)
- do i=1,n
- dat(i)=igray(dat(i),idir)
- enddo
-
- return
-end subroutine graycode
-
+subroutine graycode(dat,n,idir) + + integer dat(n) + do i=1,n + dat(i)=igray(dat(i),idir) + enddo + + return +end subroutine graycode + diff --git a/map65/libm65/graycode65.f90 b/map65/libm65/graycode65.f90 index 3ee9a42f..bb2c669c 100755..100644 --- a/map65/libm65/graycode65.f90 +++ b/map65/libm65/graycode65.f90 @@ -1,9 +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
+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/map65/libm65/grid2deg.f90 b/map65/libm65/grid2deg.f90 index 0c776416..344351dd 100755..100644 --- a/map65/libm65/grid2deg.f90 +++ b/map65/libm65/grid2deg.f90 @@ -1,38 +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
+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/map65/libm65/grid2k.f90 b/map65/libm65/grid2k.f90 index 65fb7b72..f68b1409 100755..100644 --- a/map65/libm65/grid2k.f90 +++ b/map65/libm65/grid2k.f90 @@ -1,12 +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
+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/map65/libm65/igray.c b/map65/libm65/igray.c index b1d9dbaf..395f7971 100755..100644 --- a/map65/libm65/igray.c +++ b/map65/libm65/igray.c @@ -1,22 +1,22 @@ -#ifdef CVF
-extern int __stdcall IGRAY(int *n0, int *idir)
-#else
-int igray_(int *n0, int *idir)
-#endif
-{
- 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);
-}
+#ifdef CVF +extern int __stdcall IGRAY(int *n0, int *idir) +#else +int igray_(int *n0, int *idir) +#endif +{ + 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/map65/libm65/indexx.f90 b/map65/libm65/indexx.f90 index c14587bb..7a35f53b 100755..100644 --- a/map65/libm65/indexx.f90 +++ b/map65/libm65/indexx.f90 @@ -1,91 +1,91 @@ -subroutine indexx(arr,n,indx)
-
- parameter (M=7,NSTACK=50)
- integer n,indx(n)
- real arr(n)
- integer i,indxt,ir,itemp,j,jstack,k,l,istack(NSTACK)
- real a
-
- do j=1,n
- indx(j)=j
- enddo
-
- jstack=0
- l=1
- ir=n
-1 if(ir-l.lt.M) then
- do j=l+1,ir
- indxt=indx(j)
- a=arr(indxt)
- do i=j-1,1,-1
- if(arr(indx(i)).le.a) goto 2
- indx(i+1)=indx(i)
- enddo
- i=0
-2 indx(i+1)=indxt
- enddo
- if(jstack.eq.0) return
-
- ir=istack(jstack)
- l=istack(jstack-1)
- jstack=jstack-2
-
- else
- k=(l+ir)/2
- itemp=indx(k)
- indx(k)=indx(l+1)
- indx(l+1)=itemp
-
- if(arr(indx(l+1)).gt.arr(indx(ir))) then
- itemp=indx(l+1)
- indx(l+1)=indx(ir)
- indx(ir)=itemp
- endif
-
- if(arr(indx(l)).gt.arr(indx(ir))) then
- itemp=indx(l)
- indx(l)=indx(ir)
- indx(ir)=itemp
- endif
-
- if(arr(indx(l+1)).gt.arr(indx(l))) then
- itemp=indx(l+1)
- indx(l+1)=indx(l)
- indx(l)=itemp
- endif
-
- i=l+1
- j=ir
- indxt=indx(l)
- a=arr(indxt)
-3 continue
- i=i+1
- if(arr(indx(i)).lt.a) goto 3
-
-4 continue
- j=j-1
- if(arr(indx(j)).gt.a) goto 4
- if(j.lt.i) goto 5
- itemp=indx(i)
- indx(i)=indx(j)
- indx(j)=itemp
- goto 3
-
-5 indx(l)=indx(j)
- indx(j)=indxt
- jstack=jstack+2
- if(jstack.gt.NSTACK) stop 'NSTACK too small in indexx'
- if(ir-i+1.ge.j-l)then
- istack(jstack)=ir
- istack(jstack-1)=i
- ir=j-1
- else
- istack(jstack)=j-1
- istack(jstack-1)=l
- l=i
- endif
- endif
- goto 1
-
-end subroutine indexx
-
+subroutine indexx(arr,n,indx) + + parameter (M=7,NSTACK=50) + integer n,indx(n) + real arr(n) + integer i,indxt,ir,itemp,j,jstack,k,l,istack(NSTACK) + real a + + do j=1,n + indx(j)=j + enddo + + jstack=0 + l=1 + ir=n +1 if(ir-l.lt.M) then + do j=l+1,ir + indxt=indx(j) + a=arr(indxt) + do i=j-1,1,-1 + if(arr(indx(i)).le.a) goto 2 + indx(i+1)=indx(i) + enddo + i=0 +2 indx(i+1)=indxt + enddo + if(jstack.eq.0) return + + ir=istack(jstack) + l=istack(jstack-1) + jstack=jstack-2 + + else + k=(l+ir)/2 + itemp=indx(k) + indx(k)=indx(l+1) + indx(l+1)=itemp + + if(arr(indx(l+1)).gt.arr(indx(ir))) then + itemp=indx(l+1) + indx(l+1)=indx(ir) + indx(ir)=itemp + endif + + if(arr(indx(l)).gt.arr(indx(ir))) then + itemp=indx(l) + indx(l)=indx(ir) + indx(ir)=itemp + endif + + if(arr(indx(l+1)).gt.arr(indx(l))) then + itemp=indx(l+1) + indx(l+1)=indx(l) + indx(l)=itemp + endif + + i=l+1 + j=ir + indxt=indx(l) + a=arr(indxt) +3 continue + i=i+1 + if(arr(indx(i)).lt.a) goto 3 + +4 continue + j=j-1 + if(arr(indx(j)).gt.a) goto 4 + if(j.lt.i) goto 5 + itemp=indx(i) + indx(i)=indx(j) + indx(j)=itemp + goto 3 + +5 indx(l)=indx(j) + indx(j)=indxt + jstack=jstack+2 + if(jstack.gt.NSTACK) stop 'NSTACK too small in indexx' + if(ir-i+1.ge.j-l)then + istack(jstack)=ir + istack(jstack-1)=i + ir=j-1 + else + istack(jstack)=j-1 + istack(jstack-1)=l + l=i + endif + endif + goto 1 + +end subroutine indexx + diff --git a/map65/libm65/init_rs.c b/map65/libm65/init_rs.c index 679f5486..876819f8 100755..100644 --- a/map65/libm65/init_rs.c +++ b/map65/libm65/init_rs.c @@ -1,120 +1,120 @@ -/* 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
-
-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)
- */
-void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned fcr,unsigned prim,
- unsigned int nroots){
- struct rs *rs;
- int i, j, sr,root,iprim;
-
- /* Check parameter ranges */
- if(symsize < 0 || symsize > (int)(8*sizeof(DTYPE)))
- return NULL; /* Need version with ints rather than chars */
-
- if(fcr >= (1<<symsize))
- return NULL;
- if(prim == 0 || prim >= (1<<symsize))
- return NULL;
- if(nroots >= (1<<symsize))
- return NULL; /* Can't have more roots than symbol values! */
-
- rs = (struct rs *)calloc(1,sizeof(struct rs));
- rs->mm = symsize;
- rs->nn = (1<<symsize)-1;
-
- 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;
-}
+/* 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 + +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) + */ +void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned fcr,unsigned prim, + unsigned int nroots){ + struct rs *rs; + int i, j, sr,root,iprim; + + /* Check parameter ranges */ + if(symsize < 0 || symsize > (int)(8*sizeof(DTYPE))) + return NULL; /* Need version with ints rather than chars */ + + if(fcr >= (1<<symsize)) + return NULL; + if(prim == 0 || prim >= (1<<symsize)) + return NULL; + if(nroots >= (1<<symsize)) + return NULL; /* Can't have more roots than symbol values! */ + + rs = (struct rs *)calloc(1,sizeof(struct rs)); + rs->mm = symsize; + rs->nn = (1<<symsize)-1; + + 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/map65/libm65/int.h b/map65/libm65/int.h index 3c4f26a6..ada5bfd4 100755..100644 --- a/map65/libm65/int.h +++ b/map65/libm65/int.h @@ -1,54 +1,54 @@ -/* 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 {
- unsigned int mm; /* Bits per symbol */
- unsigned int nn; /* Symbols per block (= (1<<mm)-1) */
- int *alpha_to; /* log lookup table */
- int *index_of; /* Antilog lookup table */
- int *genpoly; /* Generator polynomial */
- unsigned int nroots; /* Number of generator roots = number of parity symbols */
- unsigned int fcr; /* First consecutive root, index form */
- unsigned int prim; /* Primitive element, index form */
- unsigned int iprim; /* prim-th root of 1, index form */
-};
-
-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 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, int calc_syn);
-void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned int fcr,
- unsigned int prim,unsigned int nroots);
-void FREE_RS(void *p);
-
-
-
-
+/* 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 { + unsigned int mm; /* Bits per symbol */ + unsigned int nn; /* Symbols per block (= (1<<mm)-1) */ + int *alpha_to; /* log lookup table */ + int *index_of; /* Antilog lookup table */ + int *genpoly; /* Generator polynomial */ + unsigned int nroots; /* Number of generator roots = number of parity symbols */ + unsigned int fcr; /* First consecutive root, index form */ + unsigned int prim; /* Primitive element, index form */ + unsigned int iprim; /* prim-th root of 1, index form */ +}; + +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 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, int calc_syn); +void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned int fcr, + unsigned int prim,unsigned int nroots); +void FREE_RS(void *p); + + + + diff --git a/map65/libm65/interleave63.f90 b/map65/libm65/interleave63.f90 index 048244e6..a32ef34c 100755..100644 --- a/map65/libm65/interleave63.f90 +++ b/map65/libm65/interleave63.f90 @@ -1,25 +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
+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/map65/libm65/ipcomm.cpp b/map65/libm65/ipcomm.cpp index 83e98ebd..b40a0999 100755..100644 --- a/map65/libm65/ipcomm.cpp +++ b/map65/libm65/ipcomm.cpp @@ -1,34 +1,34 @@ -#include <QDebug>
-#include <qsharedmemory.h>
-#include <QSystemSemaphore>
-
-QSharedMemory mem_m65("mem_m65");
-QSystemSemaphore sem_m65("sem_m65", 1, QSystemSemaphore::Open);
-
-extern "C" {
- bool attach_m65_();
- bool create_m65_(int nsize);
- bool detach_m65_();
- bool lock_m65_();
- bool unlock_m65_();
- char* address_m65_();
- int size_m65_();
-
- bool acquire_m65_();
- bool release_m65_();
-
- extern struct {
- char c[10];
- } m65com_;
-}
-
-bool attach_m65_() {return mem_m65.attach();}
-bool create_m65_(int nsize) {return mem_m65.create(nsize);}
-bool detach_m65_() {return mem_m65.detach();}
-bool lock_m65_() {return mem_m65.lock();}
-bool unlock_m65_() {return mem_m65.unlock();}
-char* address_m65_() {return (char*)mem_m65.constData();}
-int size_m65_() {return (int)mem_m65.size();}
-
-bool acquire_m65_() {return sem_m65.acquire();}
-bool release_m65_() {return sem_m65.release();}
+#include <QDebug> +#include <qsharedmemory.h> +#include <QSystemSemaphore> + +QSharedMemory mem_m65("mem_m65"); +QSystemSemaphore sem_m65("sem_m65", 1, QSystemSemaphore::Open); + +extern "C" { + bool attach_m65_(); + bool create_m65_(int nsize); + bool detach_m65_(); + bool lock_m65_(); + bool unlock_m65_(); + char* address_m65_(); + int size_m65_(); + + bool acquire_m65_(); + bool release_m65_(); + + extern struct { + char c[10]; + } m65com_; +} + +bool attach_m65_() {return mem_m65.attach();} +bool create_m65_(int nsize) {return mem_m65.create(nsize);} +bool detach_m65_() {return mem_m65.detach();} +bool lock_m65_() {return mem_m65.lock();} +bool unlock_m65_() {return mem_m65.unlock();} +char* address_m65_() {return (char*)mem_m65.constData();} +int size_m65_() {return (int)mem_m65.size();} + +bool acquire_m65_() {return sem_m65.acquire();} +bool release_m65_() {return sem_m65.release();} diff --git a/map65/libm65/iqcal.f90 b/map65/libm65/iqcal.f90 index c7ee7fd9..c0c4fce2 100755..100644 --- a/map65/libm65/iqcal.f90 +++ b/map65/libm65/iqcal.f90 @@ -1,30 +1,30 @@ -subroutine iqcal(nn,c,nfft,gain,phase,zsum,ipk,reject)
-
- complex c(0:nfft-1)
- complex z,zsum,zave
-
- if(nn.eq.0) then
- zsum=0.
- endif
- nn=nn+1
- smax=0.
- ipk=1
- do i=1,nfft-1 !Find strongest signal
- s=real(c(i))**2 + aimag(c(i))**2
- if(s.gt.smax) then
- smax=s
- ipk=i
- endif
- enddo
- pimage=real(c(nfft-ipk))**2 + aimag(c(nfft-ipk))**2
- p=smax + pimage
- z=c(ipk)*c(nfft-ipk)/p !Synchronous detection of image
- zsum=zsum+z
- zave=zsum/nn
- tmp=sqrt(1.0 - (2.0*real(zave))**2)
- phase=asin(2.0*aimag(zave)/tmp) !Estimate phase
- gain=tmp/(1.0-2.0*real(zave)) !Estimate gain
- reject=10.0*log10(pimage/smax)
-
- return
-end subroutine iqcal
+subroutine iqcal(nn,c,nfft,gain,phase,zsum,ipk,reject) + + complex c(0:nfft-1) + complex z,zsum,zave + + if(nn.eq.0) then + zsum=0. + endif + nn=nn+1 + smax=0. + ipk=1 + do i=1,nfft-1 !Find strongest signal + s=real(c(i))**2 + aimag(c(i))**2 + if(s.gt.smax) then + smax=s + ipk=i + endif + enddo + pimage=real(c(nfft-ipk))**2 + aimag(c(nfft-ipk))**2 + p=smax + pimage + z=c(ipk)*c(nfft-ipk)/p !Synchronous detection of image + zsum=zsum+z + zave=zsum/nn + tmp=sqrt(1.0 - (2.0*real(zave))**2) + phase=asin(2.0*aimag(zave)/tmp) !Estimate phase + gain=tmp/(1.0-2.0*real(zave)) !Estimate gain + reject=10.0*log10(pimage/smax) + + return +end subroutine iqcal diff --git a/map65/libm65/iqfix.f90 b/map65/libm65/iqfix.f90 index aabaebec..93cace4b 100755..100644 --- a/map65/libm65/iqfix.f90 +++ b/map65/libm65/iqfix.f90 @@ -1,28 +1,28 @@ -subroutine iqfix(c,nfft,gain,phase)
-
- complex c(0:nfft-1)
- complex z,h,u,v
-
- nh=nfft/2
- h=gain*cmplx(cos(phase),sin(phase))
-
- do i=1,nh-1
- u=c(i)
- v=c(nfft-i)
- x=real(u) + real(v) - (aimag(u) + aimag(v))*aimag(h) + &
- (real(u) - real(v))*real(h)
- y=aimag(u) - aimag(v) + (aimag(u) + aimag(v))*real(h) + &
- (real(u) - real(v))*aimag(h)
- c(i)=0.5*cmplx(x,y)
- z=u
- u=v
- v=z
- x=real(u) + real(v) - (aimag(u) + aimag(v))*aimag(h) + &
- (real(u) - real(v))*real(h)
- y=aimag(u) - aimag(v) + (aimag(u) + aimag(v))*real(h) + &
- (real(u) - real(v))*aimag(h)
- c(nfft-i)=0.5*cmplx(x,y)
- enddo
-
- return
-end subroutine iqfix
+subroutine iqfix(c,nfft,gain,phase) + + complex c(0:nfft-1) + complex z,h,u,v + + nh=nfft/2 + h=gain*cmplx(cos(phase),sin(phase)) + + do i=1,nh-1 + u=c(i) + v=c(nfft-i) + x=real(u) + real(v) - (aimag(u) + aimag(v))*aimag(h) + & + (real(u) - real(v))*real(h) + y=aimag(u) - aimag(v) + (aimag(u) + aimag(v))*real(h) + & + (real(u) - real(v))*aimag(h) + c(i)=0.5*cmplx(x,y) + z=u + u=v + v=z + x=real(u) + real(v) - (aimag(u) + aimag(v))*aimag(h) + & + (real(u) - real(v))*real(h) + y=aimag(u) - aimag(v) + (aimag(u) + aimag(v))*real(h) + & + (real(u) - real(v))*aimag(h) + c(nfft-i)=0.5*cmplx(x,y) + enddo + + return +end subroutine iqfix diff --git a/map65/libm65/jt65code.f90 b/map65/libm65/jt65code.f90 index 35289e82..b232fcdd 100755..100644 --- a/map65/libm65/jt65code.f90 +++ b/map65/libm65/jt65code.f90 @@ -1,47 +1,47 @@ -program JT65code
-
-! Provides examples of message packing, bit and symbol ordering,
-! Reed Solomon encoding, and other necessary details of the JT65
-! protocol.
-
- character*22 msg0,msg,decoded,cok*3
- integer dgen(12),sent(63),recd(12),era(51)
-
- nargs=iargc()
- if(nargs.ne.1) then
- print*,'Usage: JT65code "message"'
- go to 999
- endif
-
- call getarg(1,msg0) !Get message from command line
- msg=msg0
-
- call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report
- if(nspecial.gt.0) then !or is a shorthand message
- write(*,1010)
-1010 format('Shorthand message.')
- go to 999
- endif
-
- call packmsg(msg,dgen) !Pack message into 72 bits
- write(*,1020) msg0
-1020 format('Message: ',a22) !Echo input message
- if(iand(dgen(10),8).ne.0) write(*,1030) !Is plain text bit set?
-1030 format('Plain text.')
- write(*,1040) dgen
-1040 format('Packed message, 6-bit symbols: ',12i3) !Display packed symbols
-
- call rs_encode(dgen,sent) !RS encode
- call interleave63(sent,1) !Interleave channel symbols
- call graycode(sent,63,1) !Apply Gray code
- write(*,1050) sent
-1050 format('Channel symbols, including FEC:'/(i5,20i3))
-
- call graycode(sent,63,-1)
- call interleave63(sent,-1)
- call rs_decode(sent,era,0,recd,nerr)
- call unpackmsg(recd,decoded) !Unpack the user message
- write(*,1060) decoded,cok
-1060 format('Decoded message: ',a22,2x,a3)
-
-999 end program JT65code
+program JT65code + +! Provides examples of message packing, bit and symbol ordering, +! Reed Solomon encoding, and other necessary details of the JT65 +! protocol. + + character*22 msg0,msg,decoded,cok*3 + integer dgen(12),sent(63),recd(12),era(51) + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: JT65code "message"' + go to 999 + endif + + call getarg(1,msg0) !Get message from command line + msg=msg0 + + call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report + if(nspecial.gt.0) then !or is a shorthand message + write(*,1010) +1010 format('Shorthand message.') + go to 999 + endif + + call packmsg(msg,dgen) !Pack message into 72 bits + write(*,1020) msg0 +1020 format('Message: ',a22) !Echo input message + if(iand(dgen(10),8).ne.0) write(*,1030) !Is plain text bit set? +1030 format('Plain text.') + write(*,1040) dgen +1040 format('Packed message, 6-bit symbols: ',12i3) !Display packed symbols + + call rs_encode(dgen,sent) !RS encode + call interleave63(sent,1) !Interleave channel symbols + call graycode(sent,63,1) !Apply Gray code + write(*,1050) sent +1050 format('Channel symbols, including FEC:'/(i5,20i3)) + + call graycode(sent,63,-1) + call interleave63(sent,-1) + call rs_decode(sent,era,0,recd,nerr) + call unpackmsg(recd,decoded) !Unpack the user message + write(*,1060) decoded,cok +1060 format('Decoded message: ',a22,2x,a3) + +999 end program JT65code diff --git a/map65/libm65/k2grid.f90 b/map65/libm65/k2grid.f90 index ab7640c8..aa763157 100755..100644 --- a/map65/libm65/k2grid.f90 +++ b/map65/libm65/k2grid.f90 @@ -1,12 +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
+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/map65/libm65/lorentzian.f90 b/map65/libm65/lorentzian.f90 index e1ea9693..cd2257a7 100755..100644 --- a/map65/libm65/lorentzian.f90 +++ b/map65/libm65/lorentzian.f90 @@ -1,102 +1,102 @@ -subroutine lorentzian(y,npts,a)
-
-! Input: y(npts); assume x(i)=i, i=1,npts
-! Output: a(5)
-! a(1) = baseline
-! a(2) = amplitude
-! a(3) = x0
-! a(4) = width
-! a(5) = chisqr
-
- real y(npts)
- real a(5)
- real deltaa(4)
-
- a=0.
- df=12000.0/8192.0 !df = 1.465 Hz
- width=0.
- ipk=0
- ymax=-1.e30
- do i=1,npts
- if(y(i).gt.ymax) then
- ymax=y(i)
- ipk=i
- endif
-! write(50,3001) i,i*df,y(i)
-!3001 format(i6,2f12.3)
- enddo
-! base=(sum(y(ipk-149:ipk-50)) + sum(y(ipk+51:ipk+150)))/200.0
- base=(sum(y(1:20)) + sum(y(npts-19:npts)))/40.0
- stest=ymax - 0.5*(ymax-base)
- ssum=y(ipk)
- do i=1,50
- if(ipk+i.gt.npts) exit
- if(y(ipk+i).lt.stest) exit
- ssum=ssum + y(ipk+i)
- enddo
- do i=1,50
- if(ipk-i.lt.1) exit
- if(y(ipk-i).lt.stest) exit
- ssum=ssum + y(ipk-i)
- enddo
- ww=ssum/y(ipk)
- width=2
- t=ww*ww - 5.67
- if(t.gt.0.0) width=sqrt(t)
- a(1)=base
- a(2)=ymax-base
- a(3)=ipk
- a(4)=width
-
-! Now find Lorentzian parameters
-
- deltaa(1)=0.1
- deltaa(2)=0.1
- deltaa(3)=1.0
- deltaa(4)=1.0
- nterms=4
-
-! Start the iteration
- chisqr=0.
- chisqr0=1.e6
- do iter=1,5
- do j=1,nterms
- chisq1=fchisq0(y,npts,a)
- fn=0.
- delta=deltaa(j)
-10 a(j)=a(j)+delta
- chisq2=fchisq0(y,npts,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=fchisq0(y,npts,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,chisq2
-!4000 format(i1,i2,4f10.4,f11.3)
- enddo
- chisqr=fchisq0(y,npts,a)
-! write(*,4000) 0,0,a,chisqr
- if(chisqr/chisqr0.gt.0.99) exit
- chisqr0=chisqr
- enddo
- a(5)=chisqr
-
- return
-end subroutine lorentzian
-
+subroutine lorentzian(y,npts,a) + +! Input: y(npts); assume x(i)=i, i=1,npts +! Output: a(5) +! a(1) = baseline +! a(2) = amplitude +! a(3) = x0 +! a(4) = width +! a(5) = chisqr + + real y(npts) + real a(5) + real deltaa(4) + + a=0. + df=12000.0/8192.0 !df = 1.465 Hz + width=0. + ipk=0 + ymax=-1.e30 + do i=1,npts + if(y(i).gt.ymax) then + ymax=y(i) + ipk=i + endif +! write(50,3001) i,i*df,y(i) +!3001 format(i6,2f12.3) + enddo +! base=(sum(y(ipk-149:ipk-50)) + sum(y(ipk+51:ipk+150)))/200.0 + base=(sum(y(1:20)) + sum(y(npts-19:npts)))/40.0 + stest=ymax - 0.5*(ymax-base) + ssum=y(ipk) + do i=1,50 + if(ipk+i.gt.npts) exit + if(y(ipk+i).lt.stest) exit + ssum=ssum + y(ipk+i) + enddo + do i=1,50 + if(ipk-i.lt.1) exit + if(y(ipk-i).lt.stest) exit + ssum=ssum + y(ipk-i) + enddo + ww=ssum/y(ipk) + width=2 + t=ww*ww - 5.67 + if(t.gt.0.0) width=sqrt(t) + a(1)=base + a(2)=ymax-base + a(3)=ipk + a(4)=width + +! Now find Lorentzian parameters + + deltaa(1)=0.1 + deltaa(2)=0.1 + deltaa(3)=1.0 + deltaa(4)=1.0 + nterms=4 + +! Start the iteration + chisqr=0. + chisqr0=1.e6 + do iter=1,5 + do j=1,nterms + chisq1=fchisq0(y,npts,a) + fn=0. + delta=deltaa(j) +10 a(j)=a(j)+delta + chisq2=fchisq0(y,npts,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=fchisq0(y,npts,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,chisq2 +!4000 format(i1,i2,4f10.4,f11.3) + enddo + chisqr=fchisq0(y,npts,a) +! write(*,4000) 0,0,a,chisqr + if(chisqr/chisqr0.gt.0.99) exit + chisqr0=chisqr + enddo + a(5)=chisqr + + return +end subroutine lorentzian + diff --git a/map65/libm65/m65.f90 b/map65/libm65/m65.f90 index 72768826..c93357c7 100755..100644 --- a/map65/libm65/m65.f90 +++ b/map65/libm65/m65.f90 @@ -1,195 +1,195 @@ -program m65
-
-! Decoder for map65. Can run stand-alone, reading data from *.tf2 files;
-! or as the back end of map65, with data placed in a shared memory region.
-
-! Fortran logical units
-!
-! 10 binary input data, *.tf2 files
-! 11 prefixes.txt
-! 12 wb_w65.txt
-! 13 map65.log
-! 14
-! 15
-! 16 tquick log
-! 17 saved *.tf2 files
-! 18 test file to be transmitted (wsjtgen.f90)
-! 19 livecq.txt
-! 20
-! 21 map65_rx.log
-! 22
-! 23 CALL3.TXT
-! 24
-! 25
-! 26 tmp26.txt
-
- use timer_module, only: timer
- use timer_impl, only: init_timer, fini_timer
-
- include 'njunk.f90'
- parameter (NFFT=32768)
- parameter (NSMAX=60*96000)
- parameter (NREAD=2048)
- integer*2 i2(NREAD)
- real*8 hsym
- real*4 ssz5a(NFFT)
- logical*1 lstrong(0:1023),ldecoded,eof
- real*8 fc0,fcenter
- character*80 arg,infile
- character mycall*12,hiscall*12,mygrid*6,hisgrid*6,datetime*20
- common/datcom/dd(4,5760000),ss(4,322,NFFT),savg(4,NFFT),fc0,nutc0,junk(NJUNK)
- common/npar/fcenter,nutc,idphi,mousedf,mousefqso,nagain, &
- ndepth,ndiskdat,neme,newdat,nfa,nfb,nfcal,nfshift, &
- mcall3,nkeep,ntol,nxant,nrxlog,nfsample,nxpol,nmode, &
- ndop00,nsave,max_drift,nhsym,mycall,mygrid,hiscall,hisgrid,datetime
- common/early/nhsym1,nhsym2,ldecoded(32768)
-
- nargs=iargc()
- if(nargs.ne.1 .and. nargs.lt.5) then
- print*,'Usage: m65 Jsub Qsub Xpol <95238|96000> file1 [file2 ...]'
- print*,'Examples: m65 B A X 96000 *.tf2'
- print*,' m65 C C N 96000 *.iq'
- print*,''
- print*,' m65 -s'
- print*,' (Gets data from MAP65, via shared memory region.)'
- go to 999
- endif
- nstandalone=1
- nhsym1=280
- nhsym2=302
- call getarg(1,arg)
- if(arg(1:2).eq.'-s') then
- call m65a
- go to 999
- endif
- n=1
- if(arg(1:1).eq.'0') n=0
- if(arg(1:1).eq.'A') n=1
- if(arg(1:1).eq.'B') n=2
- if(arg(1:1).eq.'C') n=3
-
- call getarg(2,arg)
- m=1
- if(arg(1:1).eq.'0') m=0
- if(arg(1:1).eq.'A') m=1
- if(arg(1:1).eq.'B') m=2
- if(arg(1:1).eq.'C') m=3
- if(arg(1:1).eq.'D') m=4
- if(arg(1:1).eq.'E') m=5
- nmode=10*m + n
-
- call getarg(3,arg)
- nxpol=0
- if(arg(1:1).eq.'X') nxpol=1
-
- call getarg(4,arg)
- nfsample=96000
- if(arg.eq.'95238') nfsample=95238
-
- ifile1=5
-
-! Some default parameters for command-line execution, in early testing.
- mycall='K1JT'
- mygrid='FN20QI'
- hiscall='K9AN'
- hisgrid='EN50'
- nfa=100 !144.100
- nfb=162 !144.162
- ntol=100
- nkeep=10 !???
- mousefqso=140 !For IK4WLV in 210220_1814.tf2
- mousedf=0
- nfcal=0
- nkhz_center=125
-
- if(nxpol.eq.0) then
- nfa=55 !For KA1GT files
- nfb=143
- mousefqso=69 !W2HRO signal
- nkhz_center=100
- endif
-
- call ftninit('.')
- call init_timer('timer.out')
- call timer('m65 ',0)
-
- do ifile=ifile1,nargs
- call getarg(ifile,infile)
- open(10,file=infile,access='stream',status='old',err=998)
- i1=index(infile,'.tf2')
- if(i1.lt.1) i1=index(infile,'.iq')
- read(infile(i1-4:i1-1),*,err=1) nutc0
- go to 2
-1 nutc0=0
-2 hsym=2048.d0*96000.d0/11025.d0 !Samples per half symbol
- read(10) fcenter
- newdat=1
- nhsym0=-999
- k=0
-
- nch=2
- if(nxpol.eq.1) nch=4
- eof=.false.
- do irec=1,9999999
- if(.not.eof) read(10,end=4) i2
- go to 6
-4 eof=.true.
-6 if(eof) i2=0
- do i=1,NREAD,nch
- k=k+1
- if(k.gt.60*96000) exit
- dd(1,k)=i2(i)
- dd(2,k)=i2(i+1)
- if(nxpol.eq.1) then
- dd(3,k)=i2(i+2)
- dd(4,k)=i2(i+3)
- endif
- enddo
- nhsym=(k-2048)/hsym
- if(nhsym.ge.1 .and. nhsym.ne.nhsym0) then
- ndiskdat=1
- nb=0
-! Emit signal readyForFFT
- fgreen=-13.0
- iqadjust=0
- iqapply=0
- nbslider=100
- gainx=0.9962
- gainy=1.0265
- phasex=0.01426
- phasey=-0.01195
- call timer('symspec ',0)
- call symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, &
- fgreen,iqadjust,iqapply,gainx,gainy,phasex,phasey,rejectx, &
- rejecty,pxdb,pydb,ssz5a,nkhz,ihsym,nzap,slimit,lstrong)
- call timer('symspec ',1)
- nhsym0=nhsym
-
- nutc=nutc0
- if(nhsym.eq.nhsym1) call decode0(dd,ss,savg,nstandalone)
- if(nhsym.eq.nhsym2) then
- call decode0(dd,ss,savg,nstandalone)
- exit
- endif
- endif
- enddo ! irec
-
- if(iqadjust.ne.0) write(*,3002) rejectx,rejecty
-3002 format('Image rejection:',2f7.1,' dB')
- enddo ! ifile
-
- call timer('m65 ',1)
- call timer('m65 ',101)
- go to 999
-
-998 print*,'Cannot open file:'
- print*,infile
-
-999 call fini_timer()
- if(arg(1:2).eq.'-s') then
- write(21,1999) datetime(:17)
-1999 format('Subprocess m65 terminated normally at UTC ',a17)
- close(21)
- endif
-
-end program m65
+program m65 + +! Decoder for map65. Can run stand-alone, reading data from *.tf2 files; +! or as the back end of map65, with data placed in a shared memory region. + +! Fortran logical units +! +! 10 binary input data, *.tf2 files +! 11 prefixes.txt +! 12 wb_w65.txt +! 13 map65.log +! 14 +! 15 +! 16 tquick log +! 17 saved *.tf2 files +! 18 test file to be transmitted (wsjtgen.f90) +! 19 livecq.txt +! 20 +! 21 map65_rx.log +! 22 +! 23 CALL3.TXT +! 24 +! 25 +! 26 tmp26.txt + + use timer_module, only: timer + use timer_impl, only: init_timer, fini_timer + + include 'njunk.f90' + parameter (NFFT=32768) + parameter (NSMAX=60*96000) + parameter (NREAD=2048) + integer*2 i2(NREAD) + real*8 hsym + real*4 ssz5a(NFFT) + logical*1 lstrong(0:1023),ldecoded,eof + real*8 fc0,fcenter + character*80 arg,infile + character mycall*12,hiscall*12,mygrid*6,hisgrid*6,datetime*20 + common/datcom/dd(4,5760000),ss(4,322,NFFT),savg(4,NFFT),fc0,nutc0,junk(NJUNK) + common/npar/fcenter,nutc,idphi,mousedf,mousefqso,nagain, & + ndepth,ndiskdat,neme,newdat,nfa,nfb,nfcal,nfshift, & + mcall3,nkeep,ntol,nxant,nrxlog,nfsample,nxpol,nmode, & + ndop00,nsave,max_drift,nhsym,mycall,mygrid,hiscall,hisgrid,datetime + common/early/nhsym1,nhsym2,ldecoded(32768) + + nargs=iargc() + if(nargs.ne.1 .and. nargs.lt.5) then + print*,'Usage: m65 Jsub Qsub Xpol <95238|96000> file1 [file2 ...]' + print*,'Examples: m65 B A X 96000 *.tf2' + print*,' m65 C C N 96000 *.iq' + print*,'' + print*,' m65 -s' + print*,' (Gets data from MAP65, via shared memory region.)' + go to 999 + endif + nstandalone=1 + nhsym1=280 + nhsym2=302 + call getarg(1,arg) + if(arg(1:2).eq.'-s') then + call m65a + go to 999 + endif + n=1 + if(arg(1:1).eq.'0') n=0 + if(arg(1:1).eq.'A') n=1 + if(arg(1:1).eq.'B') n=2 + if(arg(1:1).eq.'C') n=3 + + call getarg(2,arg) + m=1 + if(arg(1:1).eq.'0') m=0 + if(arg(1:1).eq.'A') m=1 + if(arg(1:1).eq.'B') m=2 + if(arg(1:1).eq.'C') m=3 + if(arg(1:1).eq.'D') m=4 + if(arg(1:1).eq.'E') m=5 + nmode=10*m + n + + call getarg(3,arg) + nxpol=0 + if(arg(1:1).eq.'X') nxpol=1 + + call getarg(4,arg) + nfsample=96000 + if(arg.eq.'95238') nfsample=95238 + + ifile1=5 + +! Some default parameters for command-line execution, in early testing. + mycall='K1JT' + mygrid='FN20QI' + hiscall='K9AN' + hisgrid='EN50' + nfa=100 !144.100 + nfb=162 !144.162 + ntol=100 + nkeep=10 !??? + mousefqso=140 !For IK4WLV in 210220_1814.tf2 + mousedf=0 + nfcal=0 + nkhz_center=125 + + if(nxpol.eq.0) then + nfa=55 !For KA1GT files + nfb=143 + mousefqso=69 !W2HRO signal + nkhz_center=100 + endif + + call ftninit('.') + call init_timer('timer.out') + call timer('m65 ',0) + + do ifile=ifile1,nargs + call getarg(ifile,infile) + open(10,file=infile,access='stream',status='old',err=998) + i1=index(infile,'.tf2') + if(i1.lt.1) i1=index(infile,'.iq') + read(infile(i1-4:i1-1),*,err=1) nutc0 + go to 2 +1 nutc0=0 +2 hsym=2048.d0*96000.d0/11025.d0 !Samples per half symbol + read(10) fcenter + newdat=1 + nhsym0=-999 + k=0 + + nch=2 + if(nxpol.eq.1) nch=4 + eof=.false. + do irec=1,9999999 + if(.not.eof) read(10,end=4) i2 + go to 6 +4 eof=.true. +6 if(eof) i2=0 + do i=1,NREAD,nch + k=k+1 + if(k.gt.60*96000) exit + dd(1,k)=i2(i) + dd(2,k)=i2(i+1) + if(nxpol.eq.1) then + dd(3,k)=i2(i+2) + dd(4,k)=i2(i+3) + endif + enddo + nhsym=(k-2048)/hsym + if(nhsym.ge.1 .and. nhsym.ne.nhsym0) then + ndiskdat=1 + nb=0 +! Emit signal readyForFFT + fgreen=-13.0 + iqadjust=0 + iqapply=0 + nbslider=100 + gainx=0.9962 + gainy=1.0265 + phasex=0.01426 + phasey=-0.01195 + call timer('symspec ',0) + call symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, & + fgreen,iqadjust,iqapply,gainx,gainy,phasex,phasey,rejectx, & + rejecty,pxdb,pydb,ssz5a,nkhz,ihsym,nzap,slimit,lstrong) + call timer('symspec ',1) + nhsym0=nhsym + + nutc=nutc0 + if(nhsym.eq.nhsym1) call decode0(dd,ss,savg,nstandalone) + if(nhsym.eq.nhsym2) then + call decode0(dd,ss,savg,nstandalone) + exit + endif + endif + enddo ! irec + + if(iqadjust.ne.0) write(*,3002) rejectx,rejecty +3002 format('Image rejection:',2f7.1,' dB') + enddo ! ifile + + call timer('m65 ',1) + call timer('m65 ',101) + go to 999 + +998 print*,'Cannot open file:' + print*,infile + +999 call fini_timer() + if(arg(1:2).eq.'-s') then + write(21,1999) datetime(:17) +1999 format('Subprocess m65 terminated normally at UTC ',a17) + close(21) + endif + +end program m65 diff --git a/map65/libm65/m65a.f90 b/map65/libm65/m65a.f90 index 6a23e90b..ffeb176a 100755..100644 --- a/map65/libm65/m65a.f90 +++ b/map65/libm65/m65a.f90 @@ -1,107 +1,107 @@ -subroutine m65a
-
- use timer_module, only: timer
- use timer_impl, only: init_timer !, limtrace
- use, intrinsic :: iso_c_binding, only: C_NULL_CHAR
- use FFTW3
-
- interface
- function address_m65()
- integer*1, pointer :: address_m65
- end function address_m65
- end interface
-
- integer*1 attach_m65
- integer size_m65
- integer*1, pointer :: p_m65
- character*80 cwd
- character wisfile*256
- logical fileExists
-
- call getcwd(cwd)
- call ftninit(trim(cwd))
- call init_timer (trim(cwd)//'/timer.out')
-
- limtrace=0
- lu=12
- i1=attach_m65()
-
-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 timer('decode0 ',101)
- i=detach_m65()
- ! Save FFTW wisdom and free memory
- wisfile=trim(cwd)//'/m65_wisdom.dat'// C_NULL_CHAR
- if(len(trim(wisfile)).gt.0) iret=fftwf_export_wisdom_to_filename(wisfile)
- call four2a(a,-1,1,1,1)
- call filbig(a,-1,1,0.0,0,0,0,0,0) !used for FFT plans
- call fftwf_cleanup_threads()
- call fftwf_cleanup()
- go to 999
- endif
-
- nbytes=size_m65()
- if(nbytes.le.0) then
- print*,'m65a: Shared memory mem_m65 does not exist.'
- print*,'Program m65a should be started automatically from within map65.'
- go to 999
- endif
- p_m65=>address_m65()
- call m65b(p_m65,nbytes)
- call sleep_msec(500) ! wait for .lock to be recreated
- go to 10
-
-999 return
-end subroutine m65a
-
-subroutine m65b(m65com,nbytes)
- integer*1 m65com(0:nbytes-1)
- kss=4*4*60*96000
- ksavg=kss+4*4*322*32768
- kfcenter=ksavg+4*4*32768
- call m65c(m65com(0),m65com(kss),m65com(ksavg),m65com(kfcenter))
- return
-end subroutine m65b
-
-subroutine m65c(dd,ss,savg,nparams0)
-
- include 'njunk.f90'
- real*4 dd(4,5760000),ss(4,322,32768),savg(4,32768)
- real*8 fcenter
- integer nparams0(NJUNK+2),nparams(NJUNK+2)
- logical ldecoded
- character*12 mycall,hiscall
- character*6 mygrid,hisgrid
- character*20 datetime
- common/npar/fcenter,nutc,idphi,mousedf,mousefqso,nagain, &
- ndepth,ndiskdat,neme,newdat,nfa,nfb,nfcal,nfshift, &
- mcall3,nkeep,ntol,nxant,nrxlog,nfsample,nxpol,nmode, &
- ndop00,nsave,max_drift,nhsym,mycall,mygrid,hiscall,hisgrid, &
- datetime,junk1,junk2
- common/early/nhsym1,nhsym2,ldecoded(32768)
- equivalence (nparams,fcenter)
-
- nparams=nparams0 !Copy parameters into common/npar/
- npatience=1
- if(nhsym.eq.nhsym1 .and. iand(nrxlog,1).ne.0) then
- write(21,1000) datetime(:17)
-1000 format(/'UTC Date: 'a17/78('-'))
- flush(21)
- endif
- if(iand(nrxlog,2).ne.0) rewind(21)
- if(iand(nrxlog,4).ne.0) then
- if(nhsym.eq.nhsym1) rewind(26)
- if(nhsym.eq.nhsym2) backspace(26)
- endif
-
- nstandalone=0
- if(sum(nparams).ne.0) call decode0(dd,ss,savg,nstandalone)
-
- return
-end subroutine m65c
+subroutine m65a + + use timer_module, only: timer + use timer_impl, only: init_timer !, limtrace + use, intrinsic :: iso_c_binding, only: C_NULL_CHAR + use FFTW3 + + interface + function address_m65() + integer*1, pointer :: address_m65 + end function address_m65 + end interface + + integer*1 attach_m65 + integer size_m65 + integer*1, pointer :: p_m65 + character*80 cwd + character wisfile*256 + logical fileExists + + call getcwd(cwd) + call ftninit(trim(cwd)) + call init_timer (trim(cwd)//'/timer.out') + + limtrace=0 + lu=12 + i1=attach_m65() + +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 timer('decode0 ',101) + i=detach_m65() + ! Save FFTW wisdom and free memory + wisfile=trim(cwd)//'/m65_wisdom.dat'// C_NULL_CHAR + if(len(trim(wisfile)).gt.0) iret=fftwf_export_wisdom_to_filename(wisfile) + call four2a(a,-1,1,1,1) + call filbig(a,-1,1,0.0,0,0,0,0,0) !used for FFT plans + call fftwf_cleanup_threads() + call fftwf_cleanup() + go to 999 + endif + + nbytes=size_m65() + if(nbytes.le.0) then + print*,'m65a: Shared memory mem_m65 does not exist.' + print*,'Program m65a should be started automatically from within map65.' + go to 999 + endif + p_m65=>address_m65() + call m65b(p_m65,nbytes) + call sleep_msec(500) ! wait for .lock to be recreated + go to 10 + +999 return +end subroutine m65a + +subroutine m65b(m65com,nbytes) + integer*1 m65com(0:nbytes-1) + kss=4*4*60*96000 + ksavg=kss+4*4*322*32768 + kfcenter=ksavg+4*4*32768 + call m65c(m65com(0),m65com(kss),m65com(ksavg),m65com(kfcenter)) + return +end subroutine m65b + +subroutine m65c(dd,ss,savg,nparams0) + + include 'njunk.f90' + real*4 dd(4,5760000),ss(4,322,32768),savg(4,32768) + real*8 fcenter + integer nparams0(NJUNK+2),nparams(NJUNK+2) + logical ldecoded + character*12 mycall,hiscall + character*6 mygrid,hisgrid + character*20 datetime + common/npar/fcenter,nutc,idphi,mousedf,mousefqso,nagain, & + ndepth,ndiskdat,neme,newdat,nfa,nfb,nfcal,nfshift, & + mcall3,nkeep,ntol,nxant,nrxlog,nfsample,nxpol,nmode, & + ndop00,nsave,max_drift,nhsym,mycall,mygrid,hiscall,hisgrid, & + datetime,junk1,junk2 + common/early/nhsym1,nhsym2,ldecoded(32768) + equivalence (nparams,fcenter) + + nparams=nparams0 !Copy parameters into common/npar/ + npatience=1 + if(nhsym.eq.nhsym1 .and. iand(nrxlog,1).ne.0) then + write(21,1000) datetime(:17) +1000 format(/'UTC Date: 'a17/78('-')) + flush(21) + endif + if(iand(nrxlog,2).ne.0) rewind(21) + if(iand(nrxlog,4).ne.0) then + if(nhsym.eq.nhsym1) rewind(26) + if(nhsym.eq.nhsym2) backspace(26) + endif + + nstandalone=0 + if(sum(nparams).ne.0) call decode0(dd,ss,savg,nstandalone) + + return +end subroutine m65c diff --git a/map65/libm65/map65a.f90 b/map65/libm65/map65a.f90 index fcaf343e..f01bf557 100755..100644 --- a/map65/libm65/map65a.f90 +++ b/map65/libm65/map65a.f90 @@ -1,529 +1,529 @@ -subroutine map65a(dd,ss,savg,newdat,nutc,fcenter,ntol,idphi,nfa,nfb, &
- mousedf,mousefqso,nagain,ndecdone,nfshift,ndphi,max_drift, &
- nfcal,nkeep,mcall3b,nsum,nsave,nxant,mycall,mygrid, &
- neme,ndepth,nstandalone,hiscall,hisgrid,nhsym,nfsample, &
- ndiskdat,nxpol,nmode,ndop00)
-
-! Processes timf2 data from Linrad to find and decode JT65 signals.
-
- use wideband_sync
- use timer_module, only: timer
-
- parameter (MAXMSG=1000) !Size of decoded message list
- parameter (NSMAX=60*96000)
- real dd(4,NSMAX)
- real*4 ss(4,322,NFFT),savg(4,NFFT)
- real tavg(-50:50) !Temp for finding local base level
- real base(4) !Local basel level at 4 pol'ns
- real sig(MAXMSG,30) !Parameters of detected signals
- real a(5)
- real*8 fcenter
- character*22 msg(MAXMSG)
- character*3 shmsg0(4)
- character mycall*12,hiscall*12,mygrid*6,hisgrid*6,cp*1,cm*1
- integer indx(MAXMSG),nsiz(MAXMSG)
- logical done(MAXMSG)
- logical xpol,bq65,q65b_called
- logical candec(MAX_CANDIDATES)
- logical ldecoded
- character decoded*22,blank*22,cmode*2
- real short(3,NFFT) !SNR dt ipol for potential shorthands
- real qphi(12)
- type(candidate) :: cand(MAX_CANDIDATES)
-
- common/c3com/ mcall3a
- common/testcom/ifreq
- common/early/nhsym1,nhsym2,ldecoded(32768)
- common/decodes/ndecodes
-
- data blank/' '/,cm/'#'/
- data shmsg0/'ATT','RO ','RRR','73 '/
- data nfile/0/,nutc0/-999/,nid/0/,ip000/1/,ip001/1/,mousefqso0/-999/
- save
-
- rewind 12
- ndecodes=0
-
-! Clean start for Q65 at early decode
- if(nhsym.eq.nhsym1 .or. nagain.ne.0) ldecoded=.false.
- if(ndiskdat.eq.1) ldecoded=.false.
-
- nkhz_center=nint(1000.0*(fcenter-int(fcenter)))
- mfa=nfa-nkhz_center+48
- mfb=nfb-nkhz_center+48
- mode65=mod(nmode,10)
- if(mode65.eq.3) mode65=4
- mode_q65=nmode/10
- nts_jt65=mode65 !JT65 tone separation factor
- nts_q65=2**(mode_q65-1) !Q65 tone separation factor
- xpol=(nxpol.ne.0)
-
-! No second decode for JT65?
- if(nhsym.eq.nhsym2 .and. nagain.eq.0 .and.ndiskdat.eq.0) mode65=0
-
- if(nagain.eq.0) then
- call timer('get_cand',0)
- call get_candidates(ss,savg,xpol,nhsym,mfa,mfb,nts_jt65,nts_q65,cand,ncand)
- call timer('get_cand',1)
- candec=.false.
- endif
-!###
-! do k=1,ncand
-! freq=cand(k)%f+nkhz_center-48.0
-! ipk=cand(k)%indx
-! write(71,3071) k,db(cand(k)%snr),freq,cand(k)%xdt, &
-! cand(k)%ipol,cand(k)%iflip,ipk,ldecoded(ipk)
-!3071 format(i3,f8.2,f10.3,f8.2,2i3,i6,L4)
-! enddo
-!###
-
- nwrite_q65=0
- bq65=mode_q65.gt.0
-
- mcall3a=mcall3b
- mousefqso0=mousefqso
- if(.not.xpol) ndphi=0
- nsum=0
-
-!### Should use AppDir! ###
- open(23,file='CALL3.TXT',status='unknown')
-
- df=96000.0/NFFT !df = 96000/NFFT = 2.930 Hz
- if(nfsample.eq.95238) df=95238.1/NFFT
- ftol=0.010 !Frequency tolerance (kHz)
- dphi=idphi/57.2957795
- foffset=0.001*(1270 + nfcal) !Offset from sync tone, plus CAL
- fqso=mousefqso + foffset - 0.5*(nfa+nfb) + nfshift !fqso at baseband (khz)
- iloop=0
-
-2 if(ndphi.eq.1) dphi=30*iloop/57.2957795
-
- if(nutc.ne.nutc0) nfile=nfile+1
- nutc0=nutc
-
- do nqd=1,0,-1
- if(nqd.eq.1) then !Quick decode, at fQSO
- fa=1000.0*(fqso+0.001*mousedf) - ntol
- fb=1000.0*(fqso+0.001*mousedf) + ntol + 4*53.8330078
- else !Wideband decode at all freqs
- fa=-1000*0.5*(nfb-nfa) + 1000*nfshift
- fb= 1000*0.5*(nfb-nfa) + 1000*nfshift
- endif
- ia=nint(fa/df) + 16385
- ib=nint(fb/df) + 16385
- ia=max(51,ia)
- ib=min(32768-51,ib)
- if(ndiskdat.eq.1 .and. mode65.eq.0) ib=ia
-
- km=0
- nkm=1
- nz=n/8
- freq0=-999.
- sync10=-999.
- fshort0=-999.
- syncshort0=-999.
- ntry=0
- short=0. !Zero the whole short array
- jpz=1
- if(xpol) jpz=4
-
-! First steps for JT65 decoding
- do i=ia,ib !Search over freq range
- freq=0.001*(i-16385)*df
-! Find the local base level for each polarization; update every 10 bins.
- if(mod(i-ia,10).eq.0) then
- do jp=1,jpz
- do ii=-50,50
- iii=i+ii
- if(iii.ge.1 .and. iii.le.32768) then
- tavg(ii)=savg(jp,iii)
- else
- write(13,*) 'Error in iii:',iii,ia,ib,fa,fb
- flush(13)
- go to 900
- endif
- enddo
- call pctile(tavg,101,50,base(jp))
- enddo
- endif
-
-! Find max signal at this frequency
- smax=0.
- do jp=1,jpz
- if(savg(jp,i)/base(jp).gt.smax) then
- smax=savg(jp,i)/base(jp)
- jpmax=jp
- endif
- enddo
-
- if(smax.gt.1.1 .or. ia.eq.ib) then
-! Look for JT65 sync patterns and shorthand square-wave patterns.
- call timer('ccf65 ',0)
- ssmax=1.e30
- call ccf65(ss(1,1,i),nhsym,ssmax,sync1,ipol,jpz,dt, &
- flipk,syncshort,snr2,ipol2,dt2)
-!### if(dt.lt.-2.6 .or. dt.gt.2.5) sync1=-99.0 !###
- call timer('ccf65 ',1)
- if(mode65.eq.0) syncshort=-99.0 !If "No JT65", don't waste time
-
-! ########################### Search for Shorthand Messages #################
-! Is there a shorthand tone above threshold?
- thresh0=1.0
-! Use lower thresh0 at fQSO
- if(nqd.eq.1 .and. ntol.le.100) thresh0=0.
- if(syncshort.gt.thresh0) then
-! ### Do shorthand AFC here (or maybe after finding a pair?) ###
- short(1,i)=syncshort
- short(2,i)=dt2
- short(3,i)=ipol2
-
-! Check to see if lower tone of shorthand pair was found.
- do j=2,4
- i0=i-nint(j*mode65*10.0*(11025.0/4096.0)/df)
-! Should this be i0 +/- 1, or just i0?
-! Should we also insist that difference in DT be either 1.5 or -1.5 s?
- if(short(1,i0).gt.thresh0) then
- fshort=0.001*(i0-16385)*df
- noffset=0
- if(nqd.eq.1) noffset=nint(1000.0*(fshort-fqso)-mousedf)
- if(abs(noffset).le.ntol) then
-! Keep only the best candidate within ftol.
-!### NB: sync2 was not defined here!
-! sync2=syncshort !### try this ???
- if(fshort-fshort0.le.ftol .and. &
- syncshort.gt.syncshort0 .and. nkm.eq.2) km=km-1
- if(fshort-fshort0.gt.ftol .or. &
- syncshort.gt.syncshort0) then
- if(km.lt.MAXMSG) km=km+1
- sig(km,1)=nfile
- sig(km,2)=nutc
- sig(km,3)=fshort + 0.5*(nfa+nfb)
- sig(km,4)=syncshort
- sig(km,5)=dt2
- sig(km,6)=45*(ipol2-1)/57.2957795
- sig(km,7)=0
- sig(km,8)=snr2
- sig(km,9)=0
- sig(km,10)=0
-! sig(km,11)=rms0
- sig(km,12)=savg(ipol2,i)
- sig(km,13)=0
- sig(km,14)=0
- sig(km,15)=0
- sig(km,16)=0
-! sig(km,17)=0
- sig(km,18)=0
- msg(km)=shmsg0(j)
- fshort0=fshort
- syncshort0=syncshort
- nkm=2
- endif
- endif
- endif
- enddo
- endif
-
-! ########################### Search for Normal Messages ###########
-! Is sync1 above threshold?
- thresh1=1.0
-! Use lower thresh1 at fQSO
- if(nqd.eq.1 .and. ntol.le.100) thresh1=0.
- noffset=0
- if(nqd.ge.1) noffset=nint(1000.0*(freq-fqso)-mousedf)
- if(newdat.eq.1 .and. sync1.gt.-99.0) then
- sync1=thresh1+1.0
- noffset=0
- endif
- if(sync1.gt.thresh1 .and. abs(noffset).le.ntol) then
-! Keep only the best candidate within ftol.
-! (Am I deleting any good decodes by doing this?)
- if(freq-freq0.le.ftol .and. sync1.gt.sync10 .and. &
- nkm.eq.1) km=km-1
- if(freq-freq0.gt.ftol .or. sync1.gt.sync10) then
- nflip=nint(flipk)
- f00=(i-1)*df !Freq of detected sync tone (0-96000 Hz)
- ntry=ntry+1
- if((nqd.eq.1 .and. ntry.ge.40) .or. &
- (nqd.eq.0 .and. ntry.ge.400)) then
-! Too many calls to decode1a!
- write(*,*) '! Signal too strong, or suspect data? Decoding aborted.'
- write(13,*) 'Signal too strong, or suspect data? Decoding aborted.'
- call flush(13)
- go to 900
- endif
-
- call timer('decode1a',0)
- ifreq=i
- ikhz=nint(freq+0.5*(nfa+nfb)-foffset)-nfshift
- idf=nint(1000.0*(freq+0.5*(nfa+nfb)-foffset-(ikHz+nfshift)))
- call decode1a(dd,newdat,f00,nflip,mode65,nfsample, &
- xpol,mycall,hiscall,hisgrid,neme,ndepth,nqd,dphi, &
- ndphi,nutc,ikHz,idf,ipol,ntol,sync2, &
- a,dt,pol,nkv,nhist,nsum,nsave,qual,decoded)
- call timer('decode1a',1)
-
-! The case sync1=2.0 is just to make sure decode1a is called and bigfft done.
- if(mode65.ne.0 .and. sync1.ne.2.000000) then
- if(km.lt.MAXMSG) km=km+1
- sig(km,1)=nfile
- sig(km,2)=nutc
- sig(km,3)=freq + 0.5*(nfa+nfb)
- sig(km,4)=sync1
- sig(km,5)=dt
- sig(km,6)=pol
- sig(km,7)=flipk
- sig(km,8)=sync2
- sig(km,9)=nkv
- sig(km,10)=qual
-! sig(km,11)=idphi
- sig(km,12)=savg(ipol,i)
- sig(km,13)=a(1)
- sig(km,14)=a(2)
- sig(km,15)=a(3)
- sig(km,16)=a(4)
-! sig(km,17)=a(5)
- sig(km,18)=nhist
- msg(km)=decoded
- freq0=freq
- sync10=sync1
- nkm=1
- endif
- endif
- endif
- endif
- enddo !i=ia,ib
-
- if(nqd.eq.1) then
- nwrite=0
- if(mode65.eq.0) km=0
- do k=1,km
- decoded=msg(k)
- if(decoded.ne.' ') then
- nutc=sig(k,2)
- freq=sig(k,3)
- sync1=sig(k,4)
- dt=sig(k,5)
- npol=nint(57.2957795*sig(k,6))
- flip=sig(k,7)
- sync2=sig(k,8)
- nkv=sig(k,9)
- nqual=sig(k,10)
-! idphi=nint(sig(k,11))
- if(flip.lt.0.0) then
- do i=22,1,-1
- if(decoded(i:i).ne.' ') go to 8
- enddo
- stop 'Error in message format'
-8 if(i.le.18) decoded(i+2:i+4)='OOO'
- endif
- nkHz=nint(freq-foffset)-nfshift
- mhz=fcenter ! ... +fadd ???
- f0=mhz+0.001*nkHz
- ndf=nint(1000.0*(freq-foffset-(nkHz+nfshift)))
- nsync1=sync1
-
- s2db=10.0*log10(sync2) - 40 !### empirical ###
- nsync2=nint(s2db)
- if(decoded(1:4).eq.'RO ' .or. decoded(1:4).eq.'RRR ' .or. &
- decoded(1:4).eq.'73 ') then
- nsync2=nint(1.33*s2db + 2.0)
- endif
-
- nwrite=nwrite+1
- if(nxant.ne.0) then
- npol=npol-45
- if(npol.lt.0) npol=npol+180
- endif
-
- call txpol(xpol,decoded,mygrid,npol,nxant,ntxpol,cp)
-
- if(ndphi.eq.0) then
- write(*,1010) nkHz,ndf,npol,nutc,dt,nsync2, &
- cm,decoded,nkv,nqual,ntxpol,cp
-1010 format('!',i3,i5,i4,i6.4,f5.1,i5,1x,a1,1x,a22,i2,i5,i5,1x,a1)
- else
- if(iloop.ge.1) qphi(iloop)=sig(k,10)
- write(*,1010) nkHz,ndf,npol,nutc,dt,nsync2, &
- cm,decoded,nkv,nqual,30*iloop
- write(27,1011) 30*iloop,nkHz,ndf,npol,nutc, &
- dt,sync2,nkv,nqual,cm,decoded
-1011 format(i3,i4,i5,i4,i6.4,1x,f5.1,f7.1,i3,i5,a1,1x,a22)
- endif
- endif
- enddo ! k=1,km
-
- if(bq65) then
- q65b_called=.false.
- do icand=1,ncand
- if(cand(icand)%iflip.ne.0) cycle !Keep only Q65 candidates
- freq=cand(icand)%f+nkhz_center-48.0-1.27046
- nhzdiff=nint(1000.0*(freq-mousefqso)-mousedf) - nfcal
-! Now looking for "quick decode" (nqd=1) candidates at cursor freq +/- ntol.
- if(nqd.eq.1 .and. abs(nhzdiff).gt.ntol) cycle
- ikhz=mousefqso
- q65b_called=.true.
- f0=cand(icand)%f
- call timer('q65b ',0)
- call q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf, &
- ntol,xpol,mycall,mygrid, hiscall,hisgrid,mode_q65,f0,fqso, &
- newdat,nagain,max_drift,nhsym,ndop00,idec)
- call timer('q65b ',1)
- if(idec.ge.0) candec(icand)=.true.
- enddo
- if(.not.q65b_called) then
- freq=mousefqso + 0.001*mousedf
- ikhz=mousefqso
- f0=freq - (nkhz_center-48.0-1.27046) !### ??? ###
- call timer('q65b ',0)
- call q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf, &
- ntol,xpol,mycall,mygrid,hiscall,hisgrid,mode_q65,f0,fqso, &
- newdat,nagain,max_drift,nhsym,ndop00,idec)
- call timer('q65b ',1)
- endif
- endif
-
- if(nwrite.eq.0 .and. nwrite_q65.eq.0) then
- write(*,1012) mousefqso,nutc
-1012 format('!',i3,9x,i6.4,' ')
- endif
- endif !nqd.eq.1
-
- if(ndphi.eq.1 .and.iloop.lt.12) then
- iloop=iloop+1
- go to 2
- endif
-
- if(ndphi.eq.1 .and.iloop.eq.12) call getdphi(qphi)
- if(nqd.eq.1) then
- call sec0(1,tdec)
- write(*,1013) nsum,nsave,nstandalone,nhsym,tdec
-1013 format('<QuickDecodeDone>',3i4,i6,f6.2)
- flush(6)
- open(16,file='tquick.dat',status='unknown',access='append')
- write(16,1016) nutc,tdec
-1016 format(i4.4,f7.1)
- close(16)
- endif
- call sec0(1,tsec0)
- if(nhsym.eq.nhsym1 .and. tsec0.gt.3.0) go to 700
- if(nqd.eq.1 .and. nagain.eq.1) go to 900
-
- if(nqd.eq.0 .and. bq65) then
-! Do the wideband Q65 decode
- do icand=1,ncand
- if(cand(icand)%iflip.ne.0) cycle !Do only Q65 candidates here
- if(candec(icand)) cycle !Skip if already decoded
- freq=cand(icand)%f+nkhz_center-48.0-1.27046
-!###! If here at nqd=1, do only candidates at mousefqso +/- ntol
-!### if(nqd.eq.1 .and. abs(freq-mousefqso).gt.0.001*ntol) cycle
- ikhz=nint(freq)
- f0=cand(icand)%f
- call timer('q65b ',0)
- call q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf,ntol, &
- xpol,mycall,mygrid,hiscall,hisgrid,mode_q65,f0,fqso,newdat, &
- nagain,max_drift,nhsym,ndop00,idec)
- call timer('q65b ',1)
- if(idec.ge.0) candec(icand)=.true.
- enddo ! icand
- endif
- call sec0(1,tsec0)
-
- enddo ! nqd
-
-! Trim the list and produce a sorted index and sizes of groups.
-! (Should trimlist remove all but best SNR for given UTC and message content?)
-700 call trimlist(sig,km,ftol,indx,nsiz,nz)
- done(1:km)=.false.
- j=0
- ilatest=-1
- do n=1,nz
- ifile0=0
- do m=1,nsiz(n)
- i=indx(j+m)
- ifile=sig(i,1)
- if(ifile.gt.ifile0 .and.msg(i).ne.blank) then
- ilatest=i
- ifile0=ifile
- endif
- enddo
- i=ilatest
-
- if(i.ge.1) then
- if(.not.done(i)) then
- done(i)=.true.
- nutc=sig(i,2)
- freq=sig(i,3)
- sync1=sig(i,4)
- dt=sig(i,5)
- npol=nint(57.2957795*sig(i,6))
- flip=sig(i,7)
- sync2=sig(i,8)
- nkv=sig(i,9)
- nqual=min(sig(i,10),10.0)
-! rms0=sig(i,11)
- do k=1,5
- a(k)=sig(i,12+k)
- enddo
- nhist=sig(i,18)
- decoded=msg(i)
-
- if(flip.lt.0.0) then
- do i=22,1,-1
- if(decoded(i:i).ne.' ') go to 10
- enddo
- stop 'Error in message format'
-10 if(i.le.18) decoded(i+2:i+4)='OOO'
- endif
- mhz=fcenter !... +fadd ???
- nkHz=nint(freq-foffset)-nfshift
- f0=mhz+0.001*nkHz
- ndf=nint(1000.0*(freq-foffset-(nkHz+nfshift)))
- ndf0=nint(a(1))
- ndf1=nint(a(2))
- ndf2=nint(a(3))
- nsync1=sync1
-
- s2db=10.0*log10(sync2) - 40 !### empirical ###
- nsync2=nint(s2db)
- if(decoded(1:4).eq.'RO ' .or. decoded(1:4).eq.'RRR ' .or. &
- decoded(1:4).eq.'73 ') then
- nsync2=nint(1.33*s2db + 2.0)
- endif
-
- if(nxant.ne.0) then
- npol=npol-45
- if(npol.lt.0) npol=npol+180
- endif
-
- call txpol(xpol,decoded,mygrid,npol,nxant,ntxpol,cp)
-
- cmode='#A'
- if(mode65.eq.2) cmode='#B'
- if(mode65.eq.4) cmode='#C'
- write(26,1014) f0,ndf,ndf0,ndf1,ndf2,dt,npol,nsync1, &
- nsync2,nutc,decoded,'#',cp,cmode ! was decoded,cp,
-1014 format(f8.3,i5,3i3,f5.1,i4,i3,i4,i5.4,4x,a22,7x,2a1,2x,a2) ! was a22,2x,a1,3x,a2
- ndecodes=ndecodes+1
- write(21,1100) f0,ndf,dt,npol,nsync2,nutc,decoded,'#',cp, &
- cmode(1:1),cmode(2:2)! was decoded,cp,
-1100 format(f8.3,i5,f5.1,2i4,i5.4,2x,a22,7x,2a1,3x,a1,1x,a1) ! was a22,2x,a1,1x,a1
- endif
-
- endif
- j=j+nsiz(n)
- enddo !i=1,km
-
- write(26,1015) nutc
-1015 format(37x,i6.4,' ')
- call flush(21)
- call flush(26)
- call display(nkeep,ftol)
- ndecdone=2
-
-900 close(23)
- call flush(12)
- ndphi=0
- mcall3b=mcall3a
-
- return
-end subroutine map65a
+subroutine map65a(dd,ss,savg,newdat,nutc,fcenter,ntol,idphi,nfa,nfb, & + mousedf,mousefqso,nagain,ndecdone,nfshift,ndphi,max_drift, & + nfcal,nkeep,mcall3b,nsum,nsave,nxant,mycall,mygrid, & + neme,ndepth,nstandalone,hiscall,hisgrid,nhsym,nfsample, & + ndiskdat,nxpol,nmode,ndop00) + +! Processes timf2 data from Linrad to find and decode JT65 signals. + + use wideband_sync + use timer_module, only: timer + + parameter (MAXMSG=1000) !Size of decoded message list + parameter (NSMAX=60*96000) + real dd(4,NSMAX) + real*4 ss(4,322,NFFT),savg(4,NFFT) + real tavg(-50:50) !Temp for finding local base level + real base(4) !Local basel level at 4 pol'ns + real sig(MAXMSG,30) !Parameters of detected signals + real a(5) + real*8 fcenter + character*22 msg(MAXMSG) + character*3 shmsg0(4) + character mycall*12,hiscall*12,mygrid*6,hisgrid*6,cp*1,cm*1 + integer indx(MAXMSG),nsiz(MAXMSG) + logical done(MAXMSG) + logical xpol,bq65,q65b_called + logical candec(MAX_CANDIDATES) + logical ldecoded + character decoded*22,blank*22,cmode*2 + real short(3,NFFT) !SNR dt ipol for potential shorthands + real qphi(12) + type(candidate) :: cand(MAX_CANDIDATES) + + common/c3com/ mcall3a + common/testcom/ifreq + common/early/nhsym1,nhsym2,ldecoded(32768) + common/decodes/ndecodes + + data blank/' '/,cm/'#'/ + data shmsg0/'ATT','RO ','RRR','73 '/ + data nfile/0/,nutc0/-999/,nid/0/,ip000/1/,ip001/1/,mousefqso0/-999/ + save + + rewind 12 + ndecodes=0 + +! Clean start for Q65 at early decode + if(nhsym.eq.nhsym1 .or. nagain.ne.0) ldecoded=.false. + if(ndiskdat.eq.1) ldecoded=.false. + + nkhz_center=nint(1000.0*(fcenter-int(fcenter))) + mfa=nfa-nkhz_center+48 + mfb=nfb-nkhz_center+48 + mode65=mod(nmode,10) + if(mode65.eq.3) mode65=4 + mode_q65=nmode/10 + nts_jt65=mode65 !JT65 tone separation factor + nts_q65=2**(mode_q65-1) !Q65 tone separation factor + xpol=(nxpol.ne.0) + +! No second decode for JT65? + if(nhsym.eq.nhsym2 .and. nagain.eq.0 .and.ndiskdat.eq.0) mode65=0 + + if(nagain.eq.0) then + call timer('get_cand',0) + call get_candidates(ss,savg,xpol,nhsym,mfa,mfb,nts_jt65,nts_q65,cand,ncand) + call timer('get_cand',1) + candec=.false. + endif +!### +! do k=1,ncand +! freq=cand(k)%f+nkhz_center-48.0 +! ipk=cand(k)%indx +! write(71,3071) k,db(cand(k)%snr),freq,cand(k)%xdt, & +! cand(k)%ipol,cand(k)%iflip,ipk,ldecoded(ipk) +!3071 format(i3,f8.2,f10.3,f8.2,2i3,i6,L4) +! enddo +!### + + nwrite_q65=0 + bq65=mode_q65.gt.0 + + mcall3a=mcall3b + mousefqso0=mousefqso + if(.not.xpol) ndphi=0 + nsum=0 + +!### Should use AppDir! ### + open(23,file='CALL3.TXT',status='unknown') + + df=96000.0/NFFT !df = 96000/NFFT = 2.930 Hz + if(nfsample.eq.95238) df=95238.1/NFFT + ftol=0.010 !Frequency tolerance (kHz) + dphi=idphi/57.2957795 + foffset=0.001*(1270 + nfcal) !Offset from sync tone, plus CAL + fqso=mousefqso + foffset - 0.5*(nfa+nfb) + nfshift !fqso at baseband (khz) + iloop=0 + +2 if(ndphi.eq.1) dphi=30*iloop/57.2957795 + + if(nutc.ne.nutc0) nfile=nfile+1 + nutc0=nutc + + do nqd=1,0,-1 + if(nqd.eq.1) then !Quick decode, at fQSO + fa=1000.0*(fqso+0.001*mousedf) - ntol + fb=1000.0*(fqso+0.001*mousedf) + ntol + 4*53.8330078 + else !Wideband decode at all freqs + fa=-1000*0.5*(nfb-nfa) + 1000*nfshift + fb= 1000*0.5*(nfb-nfa) + 1000*nfshift + endif + ia=nint(fa/df) + 16385 + ib=nint(fb/df) + 16385 + ia=max(51,ia) + ib=min(32768-51,ib) + if(ndiskdat.eq.1 .and. mode65.eq.0) ib=ia + + km=0 + nkm=1 + nz=n/8 + freq0=-999. + sync10=-999. + fshort0=-999. + syncshort0=-999. + ntry=0 + short=0. !Zero the whole short array + jpz=1 + if(xpol) jpz=4 + +! First steps for JT65 decoding + do i=ia,ib !Search over freq range + freq=0.001*(i-16385)*df +! Find the local base level for each polarization; update every 10 bins. + if(mod(i-ia,10).eq.0) then + do jp=1,jpz + do ii=-50,50 + iii=i+ii + if(iii.ge.1 .and. iii.le.32768) then + tavg(ii)=savg(jp,iii) + else + write(13,*) 'Error in iii:',iii,ia,ib,fa,fb + flush(13) + go to 900 + endif + enddo + call pctile(tavg,101,50,base(jp)) + enddo + endif + +! Find max signal at this frequency + smax=0. + do jp=1,jpz + if(savg(jp,i)/base(jp).gt.smax) then + smax=savg(jp,i)/base(jp) + jpmax=jp + endif + enddo + + if(smax.gt.1.1 .or. ia.eq.ib) then +! Look for JT65 sync patterns and shorthand square-wave patterns. + call timer('ccf65 ',0) + ssmax=1.e30 + call ccf65(ss(1,1,i),nhsym,ssmax,sync1,ipol,jpz,dt, & + flipk,syncshort,snr2,ipol2,dt2) +!### if(dt.lt.-2.6 .or. dt.gt.2.5) sync1=-99.0 !### + call timer('ccf65 ',1) + if(mode65.eq.0) syncshort=-99.0 !If "No JT65", don't waste time + +! ########################### Search for Shorthand Messages ################# +! Is there a shorthand tone above threshold? + thresh0=1.0 +! Use lower thresh0 at fQSO + if(nqd.eq.1 .and. ntol.le.100) thresh0=0. + if(syncshort.gt.thresh0) then +! ### Do shorthand AFC here (or maybe after finding a pair?) ### + short(1,i)=syncshort + short(2,i)=dt2 + short(3,i)=ipol2 + +! Check to see if lower tone of shorthand pair was found. + do j=2,4 + i0=i-nint(j*mode65*10.0*(11025.0/4096.0)/df) +! Should this be i0 +/- 1, or just i0? +! Should we also insist that difference in DT be either 1.5 or -1.5 s? + if(short(1,i0).gt.thresh0) then + fshort=0.001*(i0-16385)*df + noffset=0 + if(nqd.eq.1) noffset=nint(1000.0*(fshort-fqso)-mousedf) + if(abs(noffset).le.ntol) then +! Keep only the best candidate within ftol. +!### NB: sync2 was not defined here! +! sync2=syncshort !### try this ??? + if(fshort-fshort0.le.ftol .and. & + syncshort.gt.syncshort0 .and. nkm.eq.2) km=km-1 + if(fshort-fshort0.gt.ftol .or. & + syncshort.gt.syncshort0) then + if(km.lt.MAXMSG) km=km+1 + sig(km,1)=nfile + sig(km,2)=nutc + sig(km,3)=fshort + 0.5*(nfa+nfb) + sig(km,4)=syncshort + sig(km,5)=dt2 + sig(km,6)=45*(ipol2-1)/57.2957795 + sig(km,7)=0 + sig(km,8)=snr2 + sig(km,9)=0 + sig(km,10)=0 +! sig(km,11)=rms0 + sig(km,12)=savg(ipol2,i) + sig(km,13)=0 + sig(km,14)=0 + sig(km,15)=0 + sig(km,16)=0 +! sig(km,17)=0 + sig(km,18)=0 + msg(km)=shmsg0(j) + fshort0=fshort + syncshort0=syncshort + nkm=2 + endif + endif + endif + enddo + endif + +! ########################### Search for Normal Messages ########### +! Is sync1 above threshold? + thresh1=1.0 +! Use lower thresh1 at fQSO + if(nqd.eq.1 .and. ntol.le.100) thresh1=0. + noffset=0 + if(nqd.ge.1) noffset=nint(1000.0*(freq-fqso)-mousedf) + if(newdat.eq.1 .and. sync1.gt.-99.0) then + sync1=thresh1+1.0 + noffset=0 + endif + if(sync1.gt.thresh1 .and. abs(noffset).le.ntol) then +! Keep only the best candidate within ftol. +! (Am I deleting any good decodes by doing this?) + if(freq-freq0.le.ftol .and. sync1.gt.sync10 .and. & + nkm.eq.1) km=km-1 + if(freq-freq0.gt.ftol .or. sync1.gt.sync10) then + nflip=nint(flipk) + f00=(i-1)*df !Freq of detected sync tone (0-96000 Hz) + ntry=ntry+1 + if((nqd.eq.1 .and. ntry.ge.40) .or. & + (nqd.eq.0 .and. ntry.ge.400)) then +! Too many calls to decode1a! + write(*,*) '! Signal too strong, or suspect data? Decoding aborted.' + write(13,*) 'Signal too strong, or suspect data? Decoding aborted.' + call flush(13) + go to 900 + endif + + call timer('decode1a',0) + ifreq=i + ikhz=nint(freq+0.5*(nfa+nfb)-foffset)-nfshift + idf=nint(1000.0*(freq+0.5*(nfa+nfb)-foffset-(ikHz+nfshift))) + call decode1a(dd,newdat,f00,nflip,mode65,nfsample, & + xpol,mycall,hiscall,hisgrid,neme,ndepth,nqd,dphi, & + ndphi,nutc,ikHz,idf,ipol,ntol,sync2, & + a,dt,pol,nkv,nhist,nsum,nsave,qual,decoded) + call timer('decode1a',1) + +! The case sync1=2.0 is just to make sure decode1a is called and bigfft done. + if(mode65.ne.0 .and. sync1.ne.2.000000) then + if(km.lt.MAXMSG) km=km+1 + sig(km,1)=nfile + sig(km,2)=nutc + sig(km,3)=freq + 0.5*(nfa+nfb) + sig(km,4)=sync1 + sig(km,5)=dt + sig(km,6)=pol + sig(km,7)=flipk + sig(km,8)=sync2 + sig(km,9)=nkv + sig(km,10)=qual +! sig(km,11)=idphi + sig(km,12)=savg(ipol,i) + sig(km,13)=a(1) + sig(km,14)=a(2) + sig(km,15)=a(3) + sig(km,16)=a(4) +! sig(km,17)=a(5) + sig(km,18)=nhist + msg(km)=decoded + freq0=freq + sync10=sync1 + nkm=1 + endif + endif + endif + endif + enddo !i=ia,ib + + if(nqd.eq.1) then + nwrite=0 + if(mode65.eq.0) km=0 + do k=1,km + decoded=msg(k) + if(decoded.ne.' ') then + nutc=sig(k,2) + freq=sig(k,3) + sync1=sig(k,4) + dt=sig(k,5) + npol=nint(57.2957795*sig(k,6)) + flip=sig(k,7) + sync2=sig(k,8) + nkv=sig(k,9) + nqual=sig(k,10) +! idphi=nint(sig(k,11)) + if(flip.lt.0.0) then + do i=22,1,-1 + if(decoded(i:i).ne.' ') go to 8 + enddo + stop 'Error in message format' +8 if(i.le.18) decoded(i+2:i+4)='OOO' + endif + nkHz=nint(freq-foffset)-nfshift + mhz=fcenter ! ... +fadd ??? + f0=mhz+0.001*nkHz + ndf=nint(1000.0*(freq-foffset-(nkHz+nfshift))) + nsync1=sync1 + + s2db=10.0*log10(sync2) - 40 !### empirical ### + nsync2=nint(s2db) + if(decoded(1:4).eq.'RO ' .or. decoded(1:4).eq.'RRR ' .or. & + decoded(1:4).eq.'73 ') then + nsync2=nint(1.33*s2db + 2.0) + endif + + nwrite=nwrite+1 + if(nxant.ne.0) then + npol=npol-45 + if(npol.lt.0) npol=npol+180 + endif + + call txpol(xpol,decoded,mygrid,npol,nxant,ntxpol,cp) + + if(ndphi.eq.0) then + write(*,1010) nkHz,ndf,npol,nutc,dt,nsync2, & + cm,decoded,nkv,nqual,ntxpol,cp +1010 format('!',i3,i5,i4,i6.4,f5.1,i5,1x,a1,1x,a22,i2,i5,i5,1x,a1) + else + if(iloop.ge.1) qphi(iloop)=sig(k,10) + write(*,1010) nkHz,ndf,npol,nutc,dt,nsync2, & + cm,decoded,nkv,nqual,30*iloop + write(27,1011) 30*iloop,nkHz,ndf,npol,nutc, & + dt,sync2,nkv,nqual,cm,decoded +1011 format(i3,i4,i5,i4,i6.4,1x,f5.1,f7.1,i3,i5,a1,1x,a22) + endif + endif + enddo ! k=1,km + + if(bq65) then + q65b_called=.false. + do icand=1,ncand + if(cand(icand)%iflip.ne.0) cycle !Keep only Q65 candidates + freq=cand(icand)%f+nkhz_center-48.0-1.27046 + nhzdiff=nint(1000.0*(freq-mousefqso)-mousedf) - nfcal +! Now looking for "quick decode" (nqd=1) candidates at cursor freq +/- ntol. + if(nqd.eq.1 .and. abs(nhzdiff).gt.ntol) cycle + ikhz=mousefqso + q65b_called=.true. + f0=cand(icand)%f + call timer('q65b ',0) + call q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf, & + ntol,xpol,mycall,mygrid, hiscall,hisgrid,mode_q65,f0,fqso, & + newdat,nagain,max_drift,nhsym,ndop00,idec) + call timer('q65b ',1) + if(idec.ge.0) candec(icand)=.true. + enddo + if(.not.q65b_called) then + freq=mousefqso + 0.001*mousedf + ikhz=mousefqso + f0=freq - (nkhz_center-48.0-1.27046) !### ??? ### + call timer('q65b ',0) + call q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf, & + ntol,xpol,mycall,mygrid,hiscall,hisgrid,mode_q65,f0,fqso, & + newdat,nagain,max_drift,nhsym,ndop00,idec) + call timer('q65b ',1) + endif + endif + + if(nwrite.eq.0 .and. nwrite_q65.eq.0) then + write(*,1012) mousefqso,nutc +1012 format('!',i3,9x,i6.4,' ') + endif + endif !nqd.eq.1 + + if(ndphi.eq.1 .and.iloop.lt.12) then + iloop=iloop+1 + go to 2 + endif + + if(ndphi.eq.1 .and.iloop.eq.12) call getdphi(qphi) + if(nqd.eq.1) then + call sec0(1,tdec) + write(*,1013) nsum,nsave,nstandalone,nhsym,tdec +1013 format('<QuickDecodeDone>',3i4,i6,f6.2) + flush(6) + open(16,file='tquick.dat',status='unknown',access='append') + write(16,1016) nutc,tdec +1016 format(i4.4,f7.1) + close(16) + endif + call sec0(1,tsec0) + if(nhsym.eq.nhsym1 .and. tsec0.gt.3.0) go to 700 + if(nqd.eq.1 .and. nagain.eq.1) go to 900 + + if(nqd.eq.0 .and. bq65) then +! Do the wideband Q65 decode + do icand=1,ncand + if(cand(icand)%iflip.ne.0) cycle !Do only Q65 candidates here + if(candec(icand)) cycle !Skip if already decoded + freq=cand(icand)%f+nkhz_center-48.0-1.27046 +!###! If here at nqd=1, do only candidates at mousefqso +/- ntol +!### if(nqd.eq.1 .and. abs(freq-mousefqso).gt.0.001*ntol) cycle + ikhz=nint(freq) + f0=cand(icand)%f + call timer('q65b ',0) + call q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf,ntol, & + xpol,mycall,mygrid,hiscall,hisgrid,mode_q65,f0,fqso,newdat, & + nagain,max_drift,nhsym,ndop00,idec) + call timer('q65b ',1) + if(idec.ge.0) candec(icand)=.true. + enddo ! icand + endif + call sec0(1,tsec0) + + enddo ! nqd + +! Trim the list and produce a sorted index and sizes of groups. +! (Should trimlist remove all but best SNR for given UTC and message content?) +700 call trimlist(sig,km,ftol,indx,nsiz,nz) + done(1:km)=.false. + j=0 + ilatest=-1 + do n=1,nz + ifile0=0 + do m=1,nsiz(n) + i=indx(j+m) + ifile=sig(i,1) + if(ifile.gt.ifile0 .and.msg(i).ne.blank) then + ilatest=i + ifile0=ifile + endif + enddo + i=ilatest + + if(i.ge.1) then + if(.not.done(i)) then + done(i)=.true. + nutc=sig(i,2) + freq=sig(i,3) + sync1=sig(i,4) + dt=sig(i,5) + npol=nint(57.2957795*sig(i,6)) + flip=sig(i,7) + sync2=sig(i,8) + nkv=sig(i,9) + nqual=min(sig(i,10),10.0) +! rms0=sig(i,11) + do k=1,5 + a(k)=sig(i,12+k) + enddo + nhist=sig(i,18) + decoded=msg(i) + + if(flip.lt.0.0) then + do i=22,1,-1 + if(decoded(i:i).ne.' ') go to 10 + enddo + stop 'Error in message format' +10 if(i.le.18) decoded(i+2:i+4)='OOO' + endif + mhz=fcenter !... +fadd ??? + nkHz=nint(freq-foffset)-nfshift + f0=mhz+0.001*nkHz + ndf=nint(1000.0*(freq-foffset-(nkHz+nfshift))) + ndf0=nint(a(1)) + ndf1=nint(a(2)) + ndf2=nint(a(3)) + nsync1=sync1 + + s2db=10.0*log10(sync2) - 40 !### empirical ### + nsync2=nint(s2db) + if(decoded(1:4).eq.'RO ' .or. decoded(1:4).eq.'RRR ' .or. & + decoded(1:4).eq.'73 ') then + nsync2=nint(1.33*s2db + 2.0) + endif + + if(nxant.ne.0) then + npol=npol-45 + if(npol.lt.0) npol=npol+180 + endif + + call txpol(xpol,decoded,mygrid,npol,nxant,ntxpol,cp) + + cmode='#A' + if(mode65.eq.2) cmode='#B' + if(mode65.eq.4) cmode='#C' + write(26,1014) f0,ndf,ndf0,ndf1,ndf2,dt,npol,nsync1, & + nsync2,nutc,decoded,'#',cp,cmode ! was decoded,cp, +1014 format(f8.3,i5,3i3,f5.1,i4,i3,i4,i5.4,4x,a22,7x,2a1,2x,a2) ! was a22,2x,a1,3x,a2 + ndecodes=ndecodes+1 + write(21,1100) f0,ndf,dt,npol,nsync2,nutc,decoded,'#',cp, & + cmode(1:1),cmode(2:2)! was decoded,cp, +1100 format(f8.3,i5,f5.1,2i4,i5.4,2x,a22,7x,2a1,3x,a1,1x,a1) ! was a22,2x,a1,1x,a1 + endif + + endif + j=j+nsiz(n) + enddo !i=1,km + + write(26,1015) nutc +1015 format(37x,i6.4,' ') + call flush(21) + call flush(26) + call display(nkeep,ftol) + ndecdone=2 + +900 close(23) + call flush(12) + ndphi=0 + mcall3b=mcall3a + + return +end subroutine map65a diff --git a/map65/libm65/mapsim.f90 b/map65/libm65/mapsim.f90 index ab933942..26933fa8 100755..100644 --- a/map65/libm65/mapsim.f90 +++ b/map65/libm65/mapsim.f90 @@ -1,240 +1,241 @@ -program mapsim
-
-! Generate simulated data for testing of MAP65
-
- parameter (NMAX=60*96000)
- real*4 d4(4,NMAX) !Floating-point data
- integer*2 id4(4,NMAX) !i*2 data, dual polarization
- integer*2 id2(2,NMAX) !i*2 data, single polarization
- complex cwave(NMAX) !Generated complex waveform (no noise)
- complex z,zx,zy
- real*8 fcenter,fsample,samfac,f,dt,twopi,phi,dphi
- logical bq65
- character msg0*24,message*24,msgsent*24,arg*8,fname*11,mode*2 !w3sz msg* was size 22
- character*24 msg_list(60) ! was *16
- integer*2 hhmm
- data msg_list/ &
- ! 'CQ K1WDG/P','CQ YL/EA8DBM','<YL/EA8DBM> OH3LWP KP11', &
- ! 'CQ PJ4/KA1ABC','CQ KH1/KH7Z','W2XCC K3XDD EM11', &
- ! '<K1WDG/P> W3SZ fn20','<PJ4/KA1ABC> WA9XYZ -10','WA9XYZ <KH1/KH7Z> -12', &
- ! '<YW18FIFA> KA1ABC 73','CQ KA1GT FN54','CQ YW18FIFA', &
- ! 'PJ4/KA1ABC <WA9XYZ> -11','<WA9XYZ> PJ4/KA1ABC 73','<WA9XYZ> PJ4/KA1ABC RR73', &
- ! '<YW18FIFA> KA1ABC FN42','<PJ4/KA1ABC> WA9XYZ R-09','<PJ4/KA1ABC> WA9XYZ EN90', &
- 'CQ DL4KGC JN68','CQ HB9Q JN47','CQ G3LTF IO91', &
- 'CQ K1JT FN20','CQ W3SZ FN10','CQ DL3WDG JN68', &
- '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', &
- 'CQ DG2YCB JO42','CQ ON4AOI JO21','CQ KA1GT FN54', &
- 'G6SSS F7TTT JN09','W1XAA K2XBB EM10','W2XCC K3XDD EM11', &
- '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'/
-
- nargs=iargc()
- if(nargs.ne.12) then
- print*,'Usage: mapsim "message" mode DT fa fb nsigs pol fDop SNR nfiles fcenter HHmm'
- print*,'Example: mapsim "CQ K1ABC FN42" B 2.5 -20 20 21 45 0.0 -20 1 1296.1 1803'
- print*,' '
- print*,' mode = A B C for JT65; QA-QE for Q65-60A'
- print*,' fa = lowest freq in kHz, relative to center'
- print*,' fb = highest freq in kHz, relative to center'
- print*,' message = "list" to use callsigns from list'
- print*,' pol = -1 to generate a range of polarization angles.'
- print*,' SNR = 0 to generate a range of SNRs.'
- go to 999
- endif
-
- call getarg(1,msg0)
- call getarg(2,mode) !JT65 sub-mode (A B C QA-QE)
- call getarg(3,arg)
- read(arg,*) dt0 !Time delay
- call getarg(4,arg)
- read(arg,*) fa !Lowest freq (kHz, relative to fcenter)
- call getarg(5,arg)
- read(arg,*) fb !Highest freq
- call getarg(6,arg)
- read(arg,*) nsigs !Number of signals in each file
- call getarg(7,arg)
- read(arg,*) npol !Polarization in degrees
- pol=npol
- call getarg(8,arg)
- read(arg,*) fdop !Doppler spread
- call getarg(9,arg)
- read(arg,*) snrdb !S/N
- call getarg(10,arg)
- read(arg,*) nfiles !Number of files !S/N
- call getarg(11,arg) ! added by w3sz
- read(arg,*) fcenter ! added by w3sz
- call getarg(12,arg) ! added by w3sz
- read(arg,*) hhmm ! added by w3sz
-
- message=msg0 !Transmitted message
- rmsdb=25.
- rms=10.0**(0.05*rmsdb)
- ! w3sz fcenter=144.125d0 !Center frequency (MHz)
- fsample=96000.d0 !Sample rate (Hz)
- dt=1.d0/fsample !Sample interval (s)
- twopi=8.d0*atan(1.d0)
- rad=360.0/twopi
- samfac=1.d0
- bq65=(mode(1:1).eq.'Q')
- ntone_spacing=1
- ntxfreq=1270
- fac=1.0/32767.0
- if(mode(1:1).eq.'B' .or. mode(2:2).eq.'B') ntone_spacing=2
- if(mode(1:1).eq.'C' .or. mode(2:2).eq.'C') ntone_spacing=4
- if(mode(2:2).eq.'D') ntone_spacing=8
- if(mode(2:2).eq.'E') ntone_spacing=16
- npts=NMAX
-
- write(*,1000)
-1000 format('File N Mode DT freq pol fDop SNR Message'/68('-'))
-
- do ifile=1,nfiles
- ilist=0
- nmin=ifile-1
- if(mode(2:2).eq.' ') nmin=2*nmin
- write(fname,1002) hhmm !Create the output filenames ! w3sz was nmin
-1002 format('000000_',i4.4)
- open(10,file=fname//'.iq',access='stream',status='unknown')
- open(11,file=fname//'.tf2',access='stream',status='unknown')
-
- call noisegen(d4,npts) !Generate Gaussuian noise
-
- if(msg0(1:4).ne.'list') then
- if(bq65) then
- call gen_q65_cwave(message,ntxfreq,ntone_spacing,msgsent, &
- cwave,nwave)
- else
- call cgen65(message,ntone_spacing,samfac,nsendingsh,msgsent, &
- cwave,nwave)
- endif
- endif
-
- if(fdop.gt.0.0) call dopspread(cwave,fdop)
-
- do isig=1,nsigs
-
- if(msg0(1:4).eq.'list') then
- ilist=ilist+1
- message=msg_list(ilist)
- if(bq65) then
- call gen_q65_cwave(message,ntxfreq,ntone_spacing,msgsent, &
- cwave,nwave)
- else
- call cgen65(message,ntone_spacing,samfac,nsendingsh,msgsent, &
- cwave,nwave)
- endif
- endif
-
- if(npol.lt.0) pol=(isig-1)*180.0/nsigs
- a=cos(pol/rad)
- b=sin(pol/rad)
- f=1000.0*(fa+fb)/2.0
- if(nsigs.gt.1) f=1000.0*(fa + (isig-1)*(fb-fa)/(nsigs-1.0))
- dphi=twopi*f*dt + 0.5*twopi
-
- snrdbx=snrdb
- if(snrdb.eq.0.0) snrdbx=-15.0 - 15.0*(isig-1.0)/nsigs
- sig=sqrt(2.2*2500.0/96000.0) * 10.0**(0.05*snrdbx)
- write(*,1020) ifile,isig,mode,dt0,0.001*f,nint(pol),fDop,snrdbx,msgsent
-1020 format(i3,i3,2x,a2,f6.2,f8.3,i5,2f7.1,2x,a24) !w3sz was a22
-
- phi=0.
-! i0=fsample*(3.5d0+0.05d0*(isig-1))
- i0=fsample*(1.d0 + dt0)
- do i=1,nwave
- phi=phi + dphi
- if(phi.lt.-twopi) phi=phi+twopi
- if(phi.gt.twopi) phi=phi-twopi
- xphi=phi
- z=sig*cwave(i)*cmplx(cos(xphi),-sin(xphi))
- zx=a*z
- zy=b*z
- j=i+i0
- d4(1,j)=d4(1,j) + real(zx)
- d4(2,j)=d4(2,j) + aimag(zx)
- d4(3,j)=d4(3,j) + real(zy)
- d4(4,j)=d4(4,j) + aimag(zy)
- enddo
- enddo
-
- do i=1,npts
- id4(1,i)=nint(rms*d4(1,i))
- id4(2,i)=nint(rms*d4(2,i))
- id4(3,i)=nint(rms*d4(3,i))
- id4(4,i)=nint(rms*d4(4,i))
- id2(1,i)=id4(1,i)
- id2(2,i)=id4(2,i)
- enddo
-
- write(10) fcenter,id2(1:2,1:npts)
- write(11) fcenter,id4(1:4,1:npts)
- close(10)
- close(11)
- enddo
-
-999 end program mapsim
-
-subroutine dopspread(cwave,fspread)
-
- parameter (NMAX=60*96000)
- parameter (NFFT=NMAX,NH=NFFT/2)
- complex cwave(NMAX)
- complex cspread(0:NMAX-1)
-
- twopi=8.0*atan(1.0)
- df=96000.0/nfft
- cspread(0)=1.0
- cspread(NH)=0.
- b=6.0 !Use truncated Lorenzian shape for fspread
- do i=1,NH
- f=i*df
- x=b*f/fspread
- z=0.
- a=0.
- if(x.lt.3.0) then !Cutoff beyond x=3
- a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian amplitude
- phi1=twopi*rran() !Random phase
- z=a*cmplx(cos(phi1),sin(phi1))
- endif
- cspread(i)=z
- z=0.
- if(x.lt.3.0) then !Same thing for negative freqs
- phi2=twopi*rran()
- z=a*cmplx(cos(phi2),sin(phi2))
- endif
- cspread(nfft-i)=z
- enddo
-
- call four2a(cspread,nfft,1,1,1) !Transform to time domain
-
- sum=0.
- do i=0,nfft-1
- p=real(cspread(i))**2 + aimag(cspread(i))**2
- sum=sum+p
- enddo
- avep=sum/nfft
- fac=sqrt(1.0/avep)
- cspread=fac*cspread !Normalize to constant avg power
- cwave=cspread*cwave !Apply Rayleigh fading
-
-! do i=0,nfft-1
-! p=real(cspread(i))**2 + aimag(cspread(i))**2
-! write(14,3010) i,p,cspread(i)
-!3010 format(i8,3f12.6)
-! enddo
-
- return
-end subroutine dopspread
+program mapsim + +! Generate simulated data for testing of MAP65 + + parameter (NMAX=60*96000) + real*4 d4(4,NMAX) !Floating-point data + integer*2 id4(4,NMAX) !i*2 data, dual polarization + integer*2 id2(2,NMAX) !i*2 data, single polarization + complex cwave(NMAX) !Generated complex waveform (no noise) + complex z,zx,zy + real*8 fcenter,fsample,samfac,f,dt,twopi,phi,dphi + logical bq65 + character msg0*24,message*24,msgsent*24,arg*8,fname*11,mode*2 !w3sz msg* was size 22 + character*24 msg_list(60) ! was *16 + integer*2 hhmm + data msg_list/ & + 'CQ K1WDG/R','CQ YL/EA8DBM','<YL/EA8DBM> OH3LWP KP11', & + 'CQ PJ4/KA1ABC','CQ KH1/KH7Z','CQ QU1RK FN20', & + '<K1WDG/P> W3SZ fn20','<PJ4/KA1ABC> WA9XYZ -10','WA9XYZ <KH1/KH7Z> -12', & + '<YW18FIFA> KA1ABC 73','CQ TEST KA1GT FN54','CQ YW18FIFA', & + 'PJ4/KA1ABC <WA9XYZ> -11','<WA9XYZ> PJ4/KA1ABC 73','<WA9XYZ> PJ4/KA1ABC RR73', & + '<YW18FIFA> KA1ABC FN42','<PJ4/KA1ABC> WA9XYZ R-09','<PJ4/KA1ABC> WA9XYZ EN90', & + 'CQ DL4KGC JN68','CQ HB9Q JN47','CQ G3LTF IO91', & + 'CQ K1JT/P FN20','CQ W3SZ/2 FN20','CQ DL3WDG JN68', & + 'CQ GM/N5L IO98','CQ 3DA0RS JJ22','CQ W7RPI/2 FN31', & + 'CQ 123 456 78','CQ DX 167 DXP','CQYDHRT 678', & + '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', & + 'CQ DG2YCB JO42','CQ ON4AOI JO21','CQ KA1GT FN54', & + 'G6SSS F7TTT JN09','W1XAA K2XBB EM10','W2XCC K3XDD EM11', & + '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'/ + + nargs=iargc() + if(nargs.ne.12) then + print*,'Usage: mapsim "message" mode DT fa fb nsigs pol fDop SNR nfiles fcenter HHmm' + print*,'Example: mapsim "CQ K1ABC FN42" B 2.5 -20 20 21 45 0.0 -20 1 1296.1 1803' + print*,' ' + print*,' mode = A B C for JT65; QA-QE for Q65-60A' + print*,' fa = lowest freq in kHz, relative to center' + print*,' fb = highest freq in kHz, relative to center' + print*,' message = "list" to use callsigns from list' + print*,' pol = -1 to generate a range of polarization angles.' + print*,' SNR = 0 to generate a range of SNRs.' + go to 999 + endif + + call getarg(1,msg0) + call getarg(2,mode) !JT65 sub-mode (A B C QA-QE) + call getarg(3,arg) + read(arg,*) dt0 !Time delay + call getarg(4,arg) + read(arg,*) fa !Lowest freq (kHz, relative to fcenter) + call getarg(5,arg) + read(arg,*) fb !Highest freq + call getarg(6,arg) + read(arg,*) nsigs !Number of signals in each file + call getarg(7,arg) + read(arg,*) npol !Polarization in degrees + pol=npol + call getarg(8,arg) + read(arg,*) fdop !Doppler spread + call getarg(9,arg) + read(arg,*) snrdb !S/N + call getarg(10,arg) + read(arg,*) nfiles !Number of files !S/N + call getarg(11,arg) ! added by w3sz + read(arg,*) fcenter ! added by w3sz + call getarg(12,arg) ! added by w3sz + read(arg,*) hhmm ! added by w3sz + + message=msg0 !Transmitted message + rmsdb=25. + rms=10.0**(0.05*rmsdb) + ! w3sz fcenter=144.125d0 !Center frequency (MHz) + fsample=96000.d0 !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + twopi=8.d0*atan(1.d0) + rad=360.0/twopi + samfac=1.d0 + bq65=(mode(1:1).eq.'Q') + ntone_spacing=1 + ntxfreq=1270 + fac=1.0/32767.0 + if(mode(1:1).eq.'B' .or. mode(2:2).eq.'B') ntone_spacing=2 + if(mode(1:1).eq.'C' .or. mode(2:2).eq.'C') ntone_spacing=4 + if(mode(2:2).eq.'D') ntone_spacing=8 + if(mode(2:2).eq.'E') ntone_spacing=16 + npts=NMAX + + write(*,1000) +1000 format('File N Mode DT freq pol fDop SNR Message'/68('-')) + + do ifile=1,nfiles + ilist=0 + nmin=ifile-1 + if(mode(2:2).eq.' ') nmin=2*nmin + write(fname,1002) hhmm !Create the output filenames ! w3sz was nmin +1002 format('000000_',i4.4) + open(10,file=fname//'.iq',access='stream',status='unknown') + open(11,file=fname//'.tf2',access='stream',status='unknown') + + call noisegen(d4,npts) !Generate Gaussuian noise + + if(msg0(1:4).ne.'list') then + if(bq65) then + call gen_q65_cwave(message,ntxfreq,ntone_spacing,msgsent, & + cwave,nwave) + else + call cgen65(message,ntone_spacing,samfac,nsendingsh,msgsent, & + cwave,nwave) + endif + endif + + if(fdop.gt.0.0) call dopspread(cwave,fdop) + + do isig=1,nsigs + + if(msg0(1:4).eq.'list') then + ilist=ilist+1 + message=msg_list(ilist) + if(bq65) then + call gen_q65_cwave(message,ntxfreq,ntone_spacing,msgsent, & + cwave,nwave) + else + call cgen65(message,ntone_spacing,samfac,nsendingsh,msgsent, & + cwave,nwave) + endif + endif + + if(npol.lt.0) pol=(isig-1)*180.0/nsigs + a=cos(pol/rad) + b=sin(pol/rad) + f=1000.0*(fa+fb)/2.0 + if(nsigs.gt.1) f=1000.0*(fa + (isig-1)*(fb-fa)/(nsigs-1.0)) + dphi=twopi*f*dt + 0.5*twopi + + snrdbx=snrdb + if(snrdb.eq.0.0) snrdbx=-15.0 - 15.0*(isig-1.0)/nsigs + sig=sqrt(2.2*2500.0/96000.0) * 10.0**(0.05*snrdbx) + write(*,1020) ifile,isig,mode,dt0,0.001*f,nint(pol),fDop,snrdbx,msgsent +1020 format(i3,i3,2x,a2,f6.2,f8.3,i5,2f7.1,2x,a24) !w3sz was a22 + + phi=0. +! i0=fsample*(3.5d0+0.05d0*(isig-1)) + i0=fsample*(1.d0 + dt0) + do i=1,nwave + phi=phi + dphi + if(phi.lt.-twopi) phi=phi+twopi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + z=sig*cwave(i)*cmplx(cos(xphi),-sin(xphi)) + zx=a*z + zy=b*z + j=i+i0 + d4(1,j)=d4(1,j) + real(zx) + d4(2,j)=d4(2,j) + aimag(zx) + d4(3,j)=d4(3,j) + real(zy) + d4(4,j)=d4(4,j) + aimag(zy) + enddo + enddo + + do i=1,npts + id4(1,i)=nint(rms*d4(1,i)) + id4(2,i)=nint(rms*d4(2,i)) + id4(3,i)=nint(rms*d4(3,i)) + id4(4,i)=nint(rms*d4(4,i)) + id2(1,i)=id4(1,i) + id2(2,i)=id4(2,i) + enddo + + write(10) fcenter,id2(1:2,1:npts) + write(11) fcenter,id4(1:4,1:npts) + close(10) + close(11) + enddo + +999 end program mapsim + +subroutine dopspread(cwave,fspread) + + parameter (NMAX=60*96000) + parameter (NFFT=NMAX,NH=NFFT/2) + complex cwave(NMAX) + complex cspread(0:NMAX-1) + + twopi=8.0*atan(1.0) + df=96000.0/nfft + cspread(0)=1.0 + cspread(NH)=0. + b=6.0 !Use truncated Lorenzian shape for fspread + do i=1,NH + f=i*df + x=b*f/fspread + z=0. + a=0. + if(x.lt.3.0) then !Cutoff beyond x=3 + a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian amplitude + phi1=twopi*rran() !Random phase + z=a*cmplx(cos(phi1),sin(phi1)) + endif + cspread(i)=z + z=0. + if(x.lt.3.0) then !Same thing for negative freqs + phi2=twopi*rran() + z=a*cmplx(cos(phi2),sin(phi2)) + endif + cspread(nfft-i)=z + enddo + + call four2a(cspread,nfft,1,1,1) !Transform to time domain + + sum=0. + do i=0,nfft-1 + p=real(cspread(i))**2 + aimag(cspread(i))**2 + sum=sum+p + enddo + avep=sum/nfft + fac=sqrt(1.0/avep) + cspread=fac*cspread !Normalize to constant avg power + cwave=cspread*cwave !Apply Rayleigh fading + +! do i=0,nfft-1 +! p=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(14,3010) i,p,cspread(i) +!3010 format(i8,3f12.6) +! enddo + + return +end subroutine dopspread diff --git a/map65/libm65/moon2.f90 b/map65/libm65/moon2.f90 index 3228b902..9fa72f1d 100755..100644 --- a/map65/libm65/moon2.f90 +++ b/map65/libm65/moon2.f90 @@ -1,163 +1,163 @@ -subroutine moon2(y,m,Day,UT,lon,lat,RA,Dec,topRA,topDec,LST,HA,Az,El,dist)
-
- implicit none
-
- integer y !Year
- integer m !Month
- integer Day !Day
- real*8 UT !UTC in hours
- real*8 RA,Dec !RA and Dec of moon
-
-! NB: Double caps are single caps in the writeup.
-
- real*8 NN !Longitude of ascending node
- real*8 i !Inclination to the ecliptic
- real*8 w !Argument of perigee
- real*8 a !Semi-major axis
- real*8 e !Eccentricity
- real*8 MM !Mean anomaly
-
- real*8 v !True anomaly
- real*8 EE !Eccentric anomaly
- real*8 ecl !Obliquity of the ecliptic
-
- real*8 d !Ephemeris time argument in days
- real*8 r !Distance to sun, AU
- real*8 xv,yv !x and y coords in ecliptic
- real*8 lonecl,latecl !Ecliptic long and lat of moon
- real*8 xg,yg,zg !Ecliptic rectangular coords
- real*8 Ms !Mean anomaly of sun
- real*8 ws !Argument of perihelion of sun
- real*8 Ls !Mean longitude of sun (Ns=0)
- real*8 Lm !Mean longitude of moon
- real*8 DD !Mean elongation of moon
- real*8 FF !Argument of latitude for moon
- real*8 xe,ye,ze !Equatorial geocentric coords of moon
- real*8 mpar !Parallax of moon (r_E / d)
- real*8 lat,lon !Station coordinates on earth
- real*8 gclat !Geocentric latitude
- real*8 rho !Earth radius factor
- real*8 GMST0,LST,HA
- real*8 g
- real*8 topRA,topDec !Topocentric coordinates of Moon
- real*8 Az,El
- real*8 dist
-
- real*8 rad,twopi,pi,pio2
- data rad/57.2957795131d0/,twopi/6.283185307d0/
-
- d=367*y - 7*(y+(m+9)/12)/4 + 275*m/9 + Day - 730530 + UT/24.d0
- ecl = 23.4393d0 - 3.563d-7 * d
-
-! Orbital elements for Moon:
- NN = 125.1228d0 - 0.0529538083d0 * d
- i = 5.1454d0
- w = mod(318.0634d0 + 0.1643573223d0 * d + 360000.d0,360.d0)
- a = 60.2666d0
- e = 0.054900d0
- MM = mod(115.3654d0 + 13.0649929509d0 * d + 360000.d0,360.d0)
-
- EE = MM + e*rad*sin(MM/rad) * (1.d0 + e*cos(MM/rad))
- EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.d0 - e*cos(EE/rad))
- EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.d0 - e*cos(EE/rad))
-
- xv = a * (cos(EE/rad) - e)
- yv = a * (sqrt(1.d0-e*e) * sin(EE/rad))
-
- v = mod(rad*atan2(yv,xv)+720.d0,360.d0)
- r = sqrt(xv*xv + yv*yv)
-
-! Get geocentric position in ecliptic rectangular coordinates:
-
- xg = r * (cos(NN/rad)*cos((v+w)/rad)-sin(NN/rad)*sin((v+w)/rad)*cos(i/rad))
- yg = r * (sin(NN/rad)*cos((v+w)/rad)+cos(NN/rad)*sin((v+w)/rad)*cos(i/rad))
- zg = r * (sin((v+w)/rad)*sin(i/rad))
-
-! Ecliptic longitude and latitude of moon:
- lonecl = mod(rad*atan2(yg/rad,xg/rad)+720.d0,360.d0)
- latecl = rad*atan2(zg/rad,sqrt(xg*xg + yg*yg)/rad)
-
-! Now include orbital perturbations:
- Ms = mod(356.0470d0 + 0.9856002585d0 * d + 3600000.d0,360.d0)
- ws = 282.9404d0 + 4.70935d-5*d
- Ls = mod(Ms + ws + 720.d0,360.d0)
- Lm = mod(MM + w + NN+720.d0,360.d0)
- DD = mod(Lm - Ls + 360.d0,360.d0)
- FF = mod(Lm - NN + 360.d0,360.d0)
-
- lonecl = lonecl &
- - 1.274d0 * sin((MM-2.d0*DD)/rad) &
- + 0.658d0 * sin(2.d0*DD/rad) &
- - 0.186d0 * sin(Ms/rad) &
- - 0.059d0 * sin((2.d0*MM-2.d0*DD)/rad) &
- - 0.057d0 * sin((MM-2.d0*DD+Ms)/rad) &
- + 0.053d0 * sin((MM+2.d0*DD)/rad) &
- + 0.046d0 * sin((2.d0*DD-Ms)/rad) &
- + 0.041d0 * sin((MM-Ms)/rad) &
- - 0.035d0 * sin(DD/rad) &
- - 0.031d0 * sin((MM+Ms)/rad) &
- - 0.015d0 * sin((2.d0*FF-2.d0*DD)/rad) &
- + 0.011d0 * sin((MM-4.d0*DD)/rad)
-
- latecl = latecl &
- - 0.173d0 * sin((FF-2.d0*DD)/rad) &
- - 0.055d0 * sin((MM-FF-2.d0*DD)/rad) &
- - 0.046d0 * sin((MM+FF-2.d0*DD)/rad) &
- + 0.033d0 * sin((FF+2.d0*DD)/rad) &
- + 0.017d0 * sin((2.d0*MM+FF)/rad)
-
- r = 60.36298d0 &
- - 3.27746d0*cos(MM/rad) &
- - 0.57994d0*cos((MM-2.d0*DD)/rad) &
- - 0.46357d0*cos(2.d0*DD/rad) &
- - 0.08904d0*cos(2.d0*MM/rad) &
- + 0.03865d0*cos((2.d0*MM-2.d0*DD)/rad) &
- - 0.03237d0*cos((2.d0*DD-Ms)/rad) &
- - 0.02688d0*cos((MM+2.d0*DD)/rad) &
- - 0.02358d0*cos((MM-2.d0*DD+Ms)/rad) &
- - 0.02030d0*cos((MM-Ms)/rad) &
- + 0.01719d0*cos(DD/rad) &
- + 0.01671d0*cos((MM+Ms)/rad)
-
- dist=r*6378.140d0
-
-! Geocentric coordinates:
-! Rectangular ecliptic coordinates of the moon:
-
- xg = r * cos(lonecl/rad)*cos(latecl/rad)
- yg = r * sin(lonecl/rad)*cos(latecl/rad)
- zg = r * sin(latecl/rad)
-
-! Rectangular equatorial coordinates of the moon:
- xe = xg
- ye = yg*cos(ecl/rad) - zg*sin(ecl/rad)
- ze = yg*sin(ecl/rad) + zg*cos(ecl/rad)
-
-! Right Ascension, Declination:
- RA = mod(rad*atan2(ye,xe)+360.d0,360.d0)
- Dec = rad*atan2(ze,sqrt(xe*xe + ye*ye))
-
-! Now convert to topocentric system:
- mpar=rad*asin(1.d0/r)
-! alt_topoc = alt_geoc - mpar*cos(alt_geoc)
- gclat = lat - 0.1924d0*sin(2.d0*lat/rad)
- rho = 0.99883d0 + 0.00167d0*cos(2.d0*lat/rad)
- GMST0 = (Ls + 180.d0)/15.d0
- LST = mod(GMST0+UT+lon/15.d0+48.d0,24.d0) !LST in hours
- HA = 15.d0*LST - RA !HA in degrees
- g = rad*atan(tan(gclat/rad)/cos(HA/rad))
- topRA = RA - mpar*rho*cos(gclat/rad)*sin(HA/rad)/cos(Dec/rad)
- topDec = Dec - mpar*rho*sin(gclat/rad)*sin((g-Dec)/rad)/sin(g/rad)
-
- HA = 15.d0*LST - topRA !HA in degrees
- if(HA.gt.180.d0) HA=HA-360.d0
- if(HA.lt.-180.d0) HA=HA+360.d0
-
- pi=0.5d0*twopi
- pio2=0.5d0*pi
- call dcoord(pi,pio2-lat/rad,0.d0,lat/rad,ha*twopi/360,topDec/rad,az,el)
- Az=az*rad
- El=El*rad
-
- return
-end subroutine moon2
+subroutine moon2(y,m,Day,UT,lon,lat,RA,Dec,topRA,topDec,LST,HA,Az,El,dist) + + implicit none + + integer y !Year + integer m !Month + integer Day !Day + real*8 UT !UTC in hours + real*8 RA,Dec !RA and Dec of moon + +! NB: Double caps are single caps in the writeup. + + real*8 NN !Longitude of ascending node + real*8 i !Inclination to the ecliptic + real*8 w !Argument of perigee + real*8 a !Semi-major axis + real*8 e !Eccentricity + real*8 MM !Mean anomaly + + real*8 v !True anomaly + real*8 EE !Eccentric anomaly + real*8 ecl !Obliquity of the ecliptic + + real*8 d !Ephemeris time argument in days + real*8 r !Distance to sun, AU + real*8 xv,yv !x and y coords in ecliptic + real*8 lonecl,latecl !Ecliptic long and lat of moon + real*8 xg,yg,zg !Ecliptic rectangular coords + real*8 Ms !Mean anomaly of sun + real*8 ws !Argument of perihelion of sun + real*8 Ls !Mean longitude of sun (Ns=0) + real*8 Lm !Mean longitude of moon + real*8 DD !Mean elongation of moon + real*8 FF !Argument of latitude for moon + real*8 xe,ye,ze !Equatorial geocentric coords of moon + real*8 mpar !Parallax of moon (r_E / d) + real*8 lat,lon !Station coordinates on earth + real*8 gclat !Geocentric latitude + real*8 rho !Earth radius factor + real*8 GMST0,LST,HA + real*8 g + real*8 topRA,topDec !Topocentric coordinates of Moon + real*8 Az,El + real*8 dist + + real*8 rad,twopi,pi,pio2 + data rad/57.2957795131d0/,twopi/6.283185307d0/ + + d=367*y - 7*(y+(m+9)/12)/4 + 275*m/9 + Day - 730530 + UT/24.d0 + ecl = 23.4393d0 - 3.563d-7 * d + +! Orbital elements for Moon: + NN = 125.1228d0 - 0.0529538083d0 * d + i = 5.1454d0 + w = mod(318.0634d0 + 0.1643573223d0 * d + 360000.d0,360.d0) + a = 60.2666d0 + e = 0.054900d0 + MM = mod(115.3654d0 + 13.0649929509d0 * d + 360000.d0,360.d0) + + EE = MM + e*rad*sin(MM/rad) * (1.d0 + e*cos(MM/rad)) + EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.d0 - e*cos(EE/rad)) + EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.d0 - e*cos(EE/rad)) + + xv = a * (cos(EE/rad) - e) + yv = a * (sqrt(1.d0-e*e) * sin(EE/rad)) + + v = mod(rad*atan2(yv,xv)+720.d0,360.d0) + r = sqrt(xv*xv + yv*yv) + +! Get geocentric position in ecliptic rectangular coordinates: + + xg = r * (cos(NN/rad)*cos((v+w)/rad)-sin(NN/rad)*sin((v+w)/rad)*cos(i/rad)) + yg = r * (sin(NN/rad)*cos((v+w)/rad)+cos(NN/rad)*sin((v+w)/rad)*cos(i/rad)) + zg = r * (sin((v+w)/rad)*sin(i/rad)) + +! Ecliptic longitude and latitude of moon: + lonecl = mod(rad*atan2(yg/rad,xg/rad)+720.d0,360.d0) + latecl = rad*atan2(zg/rad,sqrt(xg*xg + yg*yg)/rad) + +! Now include orbital perturbations: + Ms = mod(356.0470d0 + 0.9856002585d0 * d + 3600000.d0,360.d0) + ws = 282.9404d0 + 4.70935d-5*d + Ls = mod(Ms + ws + 720.d0,360.d0) + Lm = mod(MM + w + NN+720.d0,360.d0) + DD = mod(Lm - Ls + 360.d0,360.d0) + FF = mod(Lm - NN + 360.d0,360.d0) + + lonecl = lonecl & + - 1.274d0 * sin((MM-2.d0*DD)/rad) & + + 0.658d0 * sin(2.d0*DD/rad) & + - 0.186d0 * sin(Ms/rad) & + - 0.059d0 * sin((2.d0*MM-2.d0*DD)/rad) & + - 0.057d0 * sin((MM-2.d0*DD+Ms)/rad) & + + 0.053d0 * sin((MM+2.d0*DD)/rad) & + + 0.046d0 * sin((2.d0*DD-Ms)/rad) & + + 0.041d0 * sin((MM-Ms)/rad) & + - 0.035d0 * sin(DD/rad) & + - 0.031d0 * sin((MM+Ms)/rad) & + - 0.015d0 * sin((2.d0*FF-2.d0*DD)/rad) & + + 0.011d0 * sin((MM-4.d0*DD)/rad) + + latecl = latecl & + - 0.173d0 * sin((FF-2.d0*DD)/rad) & + - 0.055d0 * sin((MM-FF-2.d0*DD)/rad) & + - 0.046d0 * sin((MM+FF-2.d0*DD)/rad) & + + 0.033d0 * sin((FF+2.d0*DD)/rad) & + + 0.017d0 * sin((2.d0*MM+FF)/rad) + + r = 60.36298d0 & + - 3.27746d0*cos(MM/rad) & + - 0.57994d0*cos((MM-2.d0*DD)/rad) & + - 0.46357d0*cos(2.d0*DD/rad) & + - 0.08904d0*cos(2.d0*MM/rad) & + + 0.03865d0*cos((2.d0*MM-2.d0*DD)/rad) & + - 0.03237d0*cos((2.d0*DD-Ms)/rad) & + - 0.02688d0*cos((MM+2.d0*DD)/rad) & + - 0.02358d0*cos((MM-2.d0*DD+Ms)/rad) & + - 0.02030d0*cos((MM-Ms)/rad) & + + 0.01719d0*cos(DD/rad) & + + 0.01671d0*cos((MM+Ms)/rad) + + dist=r*6378.140d0 + +! Geocentric coordinates: +! Rectangular ecliptic coordinates of the moon: + + xg = r * cos(lonecl/rad)*cos(latecl/rad) + yg = r * sin(lonecl/rad)*cos(latecl/rad) + zg = r * sin(latecl/rad) + +! Rectangular equatorial coordinates of the moon: + xe = xg + ye = yg*cos(ecl/rad) - zg*sin(ecl/rad) + ze = yg*sin(ecl/rad) + zg*cos(ecl/rad) + +! Right Ascension, Declination: + RA = mod(rad*atan2(ye,xe)+360.d0,360.d0) + Dec = rad*atan2(ze,sqrt(xe*xe + ye*ye)) + +! Now convert to topocentric system: + mpar=rad*asin(1.d0/r) +! alt_topoc = alt_geoc - mpar*cos(alt_geoc) + gclat = lat - 0.1924d0*sin(2.d0*lat/rad) + rho = 0.99883d0 + 0.00167d0*cos(2.d0*lat/rad) + GMST0 = (Ls + 180.d0)/15.d0 + LST = mod(GMST0+UT+lon/15.d0+48.d0,24.d0) !LST in hours + HA = 15.d0*LST - RA !HA in degrees + g = rad*atan(tan(gclat/rad)/cos(HA/rad)) + topRA = RA - mpar*rho*cos(gclat/rad)*sin(HA/rad)/cos(Dec/rad) + topDec = Dec - mpar*rho*sin(gclat/rad)*sin((g-Dec)/rad)/sin(g/rad) + + HA = 15.d0*LST - topRA !HA in degrees + if(HA.gt.180.d0) HA=HA-360.d0 + if(HA.lt.-180.d0) HA=HA+360.d0 + + pi=0.5d0*twopi + pio2=0.5d0*pi + call dcoord(pi,pio2-lat/rad,0.d0,lat/rad,ha*twopi/360,topDec/rad,az,el) + Az=az*rad + El=El*rad + + return +end subroutine moon2 diff --git a/map65/libm65/moondop.f90 b/map65/libm65/moondop.f90 index 72d137a7..096c3128 100755..100644 --- a/map65/libm65/moondop.f90 +++ b/map65/libm65/moondop.f90 @@ -1,72 +1,72 @@ -subroutine MoonDop(nyear,month,nday,uth4,lon4,lat4,RAMoon4,DecMoon4, &
- LST4,HA4,AzMoon4,ElMoon4,vr4,dist4)
-
- implicit real*8 (a-h,o-z)
- real*4 uth4 !UT in hours
- real*4 lon4 !West longitude, degrees
- real*4 lat4 !Latitude, degrees
- real*4 RAMoon4 !Topocentric RA of moon, hours
- real*4 DecMoon4 !Topocentric Dec of Moon, degrees
- real*4 LST4 !Locat sidereal time, hours
- real*4 HA4 !Local Hour angle, degrees
- real*4 AzMoon4 !Topocentric Azimuth of moon, degrees
- real*4 ElMoon4 !Topocentric Elevation of moon, degrees
- real*4 vr4 !Radial velocity of moon wrt obs, km/s
- real*4 dist4 !Echo time, seconds
-
- real*8 LST
- real*8 RME(6) !Vector from Earth center to Moon
- real*8 RAE(6) !Vector from Earth center to Obs
- real*8 RMA(6) !Vector from Obs to Moon
- real*8 rme0(6)
- logical km
-
- data rad/57.2957795130823d0/,twopi/6.28310530717959d0/
-
- km=.true.
- dlat=lat4/rad
- dlong1=lon4/rad
- elev1=200.d0
- call geocentric(dlat,elev1,dlat1,erad1)
-
- dt=100.d0 !For numerical derivative, in seconds
- UT=uth4
-
-! NB: geodetic latitude used here, but geocentric latitude used when
-! determining Earth-rotation contribution to Doppler.
-
- call moon2(nyear,month,nDay,UT-dt/3600.d0,dlong1*rad,dlat*rad, &
- RA,Dec,topRA,topDec,LST,HA,Az0,El0,dist)
- call toxyz(RA/rad,Dec/rad,dist,rme0) !Convert to rectangular coords
-
- call moon2(nyear,month,nDay,UT,dlong1*rad,dlat*rad, &
- RA,Dec,topRA,topDec,LST,HA,Az,El,dist)
- call toxyz(RA/rad,Dec/rad,dist,rme) !Convert to rectangular coords
-
- phi=LST*twopi/24.d0
- call toxyz(phi,dlat1,erad1,rae) !Gencentric numbers used here!
- radps=twopi/(86400.d0/1.002737909d0)
- rae(4)=-rae(2)*radps !Vel of Obs wrt Earth center
- rae(5)=rae(1)*radps
- rae(6)=0.d0
-
- do i=1,3
- rme(i+3)=(rme(i)-rme0(i))/dt
- rma(i)=rme(i)-rae(i)
- rma(i+3)=rme(i+3)-rae(i+3)
- enddo
-
- call fromxyz(rma,alpha1,delta1,dtopo0) !Get topocentric coords
- vr=dot(rma(4),rma)/dtopo0
-
- RAMoon4=topRA
- DecMoon4=topDec
- LST4=LST
- HA4=HA
- AzMoon4=Az
- ElMoon4=El
- vr4=vr
- dist4=dist
-
- return
-end subroutine MoonDop
+subroutine MoonDop(nyear,month,nday,uth4,lon4,lat4,RAMoon4,DecMoon4, & + LST4,HA4,AzMoon4,ElMoon4,vr4,dist4) + + implicit real*8 (a-h,o-z) + real*4 uth4 !UT in hours + real*4 lon4 !West longitude, degrees + real*4 lat4 !Latitude, degrees + real*4 RAMoon4 !Topocentric RA of moon, hours + real*4 DecMoon4 !Topocentric Dec of Moon, degrees + real*4 LST4 !Locat sidereal time, hours + real*4 HA4 !Local Hour angle, degrees + real*4 AzMoon4 !Topocentric Azimuth of moon, degrees + real*4 ElMoon4 !Topocentric Elevation of moon, degrees + real*4 vr4 !Radial velocity of moon wrt obs, km/s + real*4 dist4 !Echo time, seconds + + real*8 LST + real*8 RME(6) !Vector from Earth center to Moon + real*8 RAE(6) !Vector from Earth center to Obs + real*8 RMA(6) !Vector from Obs to Moon + real*8 rme0(6) + logical km + + data rad/57.2957795130823d0/,twopi/6.28310530717959d0/ + + km=.true. + dlat=lat4/rad + dlong1=lon4/rad + elev1=200.d0 + call geocentric(dlat,elev1,dlat1,erad1) + + dt=100.d0 !For numerical derivative, in seconds + UT=uth4 + +! NB: geodetic latitude used here, but geocentric latitude used when +! determining Earth-rotation contribution to Doppler. + + call moon2(nyear,month,nDay,UT-dt/3600.d0,dlong1*rad,dlat*rad, & + RA,Dec,topRA,topDec,LST,HA,Az0,El0,dist) + call toxyz(RA/rad,Dec/rad,dist,rme0) !Convert to rectangular coords + + call moon2(nyear,month,nDay,UT,dlong1*rad,dlat*rad, & + RA,Dec,topRA,topDec,LST,HA,Az,El,dist) + call toxyz(RA/rad,Dec/rad,dist,rme) !Convert to rectangular coords + + phi=LST*twopi/24.d0 + call toxyz(phi,dlat1,erad1,rae) !Gencentric numbers used here! + radps=twopi/(86400.d0/1.002737909d0) + rae(4)=-rae(2)*radps !Vel of Obs wrt Earth center + rae(5)=rae(1)*radps + rae(6)=0.d0 + + do i=1,3 + rme(i+3)=(rme(i)-rme0(i))/dt + rma(i)=rme(i)-rae(i) + rma(i+3)=rme(i+3)-rae(i+3) + enddo + + call fromxyz(rma,alpha1,delta1,dtopo0) !Get topocentric coords + vr=dot(rma(4),rma)/dtopo0 + + RAMoon4=topRA + DecMoon4=topDec + LST4=LST + HA4=HA + AzMoon4=Az + ElMoon4=El + vr4=vr + dist4=dist + + return +end subroutine MoonDop diff --git a/map65/libm65/msgs.txt b/map65/libm65/msgs.txt index c38aba97..cb063042 100755..100644 --- a/map65/libm65/msgs.txt +++ b/map65/libm65/msgs.txt @@ -1,60 +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
+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/map65/libm65/nchar.f90 b/map65/libm65/nchar.f90 index 879043ac..21593bd1 100755..100644 --- a/map65/libm65/nchar.f90 +++ b/map65/libm65/nchar.f90 @@ -1,23 +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)
- call exit(1)
- endif
- nchar=n
-
- return
-end function nchar
+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) + call exit(1) + endif + nchar=n + + return +end function nchar diff --git a/map65/libm65/njunk.f90 b/map65/libm65/njunk.f90 index f55f1076..319fb5ab 100755..100644 --- a/map65/libm65/njunk.f90 +++ b/map65/libm65/njunk.f90 @@ -1 +1 @@ - parameter(NJUNK=40)
+ parameter(NJUNK=40) diff --git a/map65/libm65/noisegen.f90 b/map65/libm65/noisegen.f90 index f92a9df0..65d94316 100755..100644 --- a/map65/libm65/noisegen.f90 +++ b/map65/libm65/noisegen.f90 @@ -1,13 +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
+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/map65/libm65/packjt.f90 b/map65/libm65/packjt.f90 index 1e0224cb..c1fc0089 100755..100644 --- a/map65/libm65/packjt.f90 +++ b/map65/libm65/packjt.f90 @@ -1,996 +1,996 @@ -module packjt
-
- contains
-
-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(:)
- 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
-
- 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(:)
- 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
-
- 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
-
- subroutine unpackcall(ncall,word,iv2,psfx)
-
- parameter (NBASE=37*36*10*27*27*27)
- character word*12,c*37,psfx*4
-
- data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/
-
- word='......'
- psfx=' '
- 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)
-
- else 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)
-
- else 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)
-
- else 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)
-
- else 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)
-
- else 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)
-
- else 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
-
- 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
-
- 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
-
- subroutine packmsg(msg0,dat,itype)
-
- ! Packs a JT4/JT9/JT65 message into twelve 6-bit symbols
-
- ! itype Message Type
- !--------------------
- ! 1 Standardd message
- ! 2 Type 1 prefix
- ! 3 Type 1 suffix
- ! 4 Type 2 prefix
- ! 5 Type 2 suffix
- ! 6 Free text
- ! -1 Does not decode correctly
-
- parameter (NBASE=37*36*10*27*27*27)
- parameter (NBASE2=262178562)
- character*22 msg0,msg
- integer dat(:)
- character*12 c1,c2
- character*4 c3
- character*6 grid6
- logical text1,text2,text3
-
- msg=msg0
- itype=1
- call fmtmsg(msg,iz)
-
- if(msg(1:6).eq.'CQ DX ') msg(3:3)='9'
- if(msg(1:3).eq."CQ " .and. &
- msg(4:4).ge.'A' .and. msg(4:4).le.'Z' .and. &
- msg(5:5).ge.'A' .and. msg(5:5).le.'Z' .and. &
- msg(6:6).eq.' ') msg='E9'//msg(4:)
-
- ! 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,nv2a)
- if(nv2a.ge.4) go to 10
- call packcall(c1,nc1,text1)
- if(text1) go to 10
- call getpfx1(c2,k2,nv2b)
- call packcall(c2,nc2,text2)
- if(text2) go to 10
- if(nv2a.eq.2 .or. nv2a.eq.3 .or. nv2b.eq.2 .or. nv2b.eq.3) 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(nv2a.lt.4 .and. nv2b.lt.4 .and. (.not.text1) .and. (.not.text2) .and. &
- (.not.text3)) go to 20
-
- nc1=0
- if(nv2b.eq.4) 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
- else if(nv2b.eq.5) 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
- if(nc1.ne.0) go to 20
-
- ! The message will be treated as plain text.
- 10 itype=6
- call packtext(msg,nc1,nc2,ng)
- ng=ng+32768
-
- ! Encode data into 6-bit words
- 20 continue
- if(itype.ne.6) itype=max(nv2a,nv2b)
- 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
-
- subroutine unpackmsg(dat,msg)
-
- parameter (NBASE=37*36*10*27*27*27)
- parameter (NGBASE=180*180)
- integer dat(:)
- 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
- if(iv2.eq.8) msg=' '
- 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)=' '
- if(msg(1:2).eq.'E9' .and. &
- msg(3:3).ge.'A' .and. msg(3:3).le.'Z' .and. &
- msg(4:4).ge.'A' .and. msg(4:4).le.'Z' .and. &
- msg(5:5).eq.' ') msg='CQ '//msg(3:)
-
- return
- end subroutine unpackmsg
-
- 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
-
- 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
-
- 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=1
- iz=index(callsign,' ') - 1
- if(iz.lt.0) iz=12
- islash=index(callsign(1:iz),'/')
- k=0
- ! if(k.eq.0) go to 10 !Tnx to DL9RDZ for reminder:this was for tests only!
- 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
- nv2=2
- go to 10
- endif
- enddo
- if(addpfx.eq.c) then
- k=449
- nv2=2
- 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
- nv2=3
- 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=4
- 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=5
- i=index(callsign0,'/')
- callsign=callsign0(:i-1)
- endif
- endif
- endif
-
- return
- end subroutine getpfx1
-
- 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
-
- 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
-
- 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
-
- 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
-
- 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
-
- 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
-
- subroutine pack50(n1,n2,dat)
-
- integer*1 dat(:),i1
-
- i1=iand(ishft(n1,-20),255) !8 bits
- dat(1)=i1
- i1=iand(ishft(n1,-12),255) !8 bits
- dat(2)=i1
- i1=iand(ishft(n1, -4),255) !8 bits
- dat(3)=i1
- i1=16*iand(n1,15)+iand(ishft(n2,-18),15) !4+4 bits
- dat(4)=i1
- i1=iand(ishft(n2,-10),255) !8 bits
- dat(5)=i1
- i1=iand(ishft(n2, -2),255) !8 bits
- dat(6)=i1
- i1=64*iand(n2,3) !2 bits
- dat(7)=i1
- dat(8)=0
- dat(9)=0
- dat(10)=0
- dat(11)=0
-
- return
- end subroutine pack50
-
-subroutine packpfx(call1,n1,ng,nadd)
-
- character*12 call1,call0
- character*3 pfx
- logical text
-
- i1=index(call1,'/')
- if(call1(i1+2:i1+2).eq.' ') then
-! Single-character add-on suffix (maybe also fourth suffix letter?)
- call0=call1(:i1-1)
- call packcall(call0,n1,text)
- nadd=1
- nc=ichar(call1(i1+1:i1+1))
- if(nc.ge.48 .and. nc.le.57) then
- n=nc-48
- else if(nc.ge.65 .and. nc.le.90) then
- n=nc-65+10
- else
- n=38
- endif
- nadd=1
- ng=60000-32768+n
- else if(call1(i1+3:i1+3).eq.' ') then
-! Two-character numerical suffix, /10 to /99
- call0=call1(:i1-1)
- call packcall(call0,n1,text)
- nadd=1
- n=10*(ichar(call1(i1+1:i1+1))-48) + ichar(call1(i1+2:i1+2)) - 48
- nadd=1
- ng=60000 + 26 + n
- else
-! Prefix of 1 to 3 characters
- pfx=call1(:i1-1)
- if(pfx(3:3).eq.' ') pfx=' '//pfx(1:2)
- if(pfx(3:3).eq.' ') pfx=' '//pfx(1:2)
- call0=call1(i1+1:)
- call packcall(call0,n1,text)
-
- ng=0
- do i=1,3
- nc=ichar(pfx(i:i))
- if(nc.ge.48 .and. nc.le.57) then
- n=nc-48
- else if(nc.ge.65 .and. nc.le.90) then
- n=nc-65+10
- else
- n=36
- endif
- ng=37*ng + n
- enddo
- nadd=0
- if(ng.ge.32768) then
- ng=ng-32768
- nadd=1
- endif
- endif
-
- return
-end subroutine packpfx
-
-end module packjt
+module packjt + + contains + +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(:) + 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 + + 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(:) + 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 + + 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 + + subroutine unpackcall(ncall,word,iv2,psfx) + + parameter (NBASE=37*36*10*27*27*27) + character word*12,c*37,psfx*4 + + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/ + + word='......' + psfx=' ' + 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) + + else 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) + + else 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) + + else 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) + + else 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) + + else 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) + + else 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 + + 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 + + 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 + + subroutine packmsg(msg0,dat,itype) + + ! Packs a JT4/JT9/JT65 message into twelve 6-bit symbols + + ! itype Message Type + !-------------------- + ! 1 Standardd message + ! 2 Type 1 prefix + ! 3 Type 1 suffix + ! 4 Type 2 prefix + ! 5 Type 2 suffix + ! 6 Free text + ! -1 Does not decode correctly + + parameter (NBASE=37*36*10*27*27*27) + parameter (NBASE2=262178562) + character*22 msg0,msg + integer dat(:) + character*12 c1,c2 + character*4 c3 + character*6 grid6 + logical text1,text2,text3 + + msg=msg0 + itype=1 + call fmtmsg(msg,iz) + + if(msg(1:6).eq.'CQ DX ') msg(3:3)='9' + if(msg(1:3).eq."CQ " .and. & + msg(4:4).ge.'A' .and. msg(4:4).le.'Z' .and. & + msg(5:5).ge.'A' .and. msg(5:5).le.'Z' .and. & + msg(6:6).eq.' ') msg='E9'//msg(4:) + + ! 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,nv2a) + if(nv2a.ge.4) go to 10 + call packcall(c1,nc1,text1) + if(text1) go to 10 + call getpfx1(c2,k2,nv2b) + call packcall(c2,nc2,text2) + if(text2) go to 10 + if(nv2a.eq.2 .or. nv2a.eq.3 .or. nv2b.eq.2 .or. nv2b.eq.3) 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(nv2a.lt.4 .and. nv2b.lt.4 .and. (.not.text1) .and. (.not.text2) .and. & + (.not.text3)) go to 20 + + nc1=0 + if(nv2b.eq.4) 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 + else if(nv2b.eq.5) 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 + if(nc1.ne.0) go to 20 + + ! The message will be treated as plain text. + 10 itype=6 + call packtext(msg,nc1,nc2,ng) + ng=ng+32768 + + ! Encode data into 6-bit words + 20 continue + if(itype.ne.6) itype=max(nv2a,nv2b) + 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 + + subroutine unpackmsg(dat,msg) + + parameter (NBASE=37*36*10*27*27*27) + parameter (NGBASE=180*180) + integer dat(:) + 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 + if(iv2.eq.8) msg=' ' + 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)=' ' + if(msg(1:2).eq.'E9' .and. & + msg(3:3).ge.'A' .and. msg(3:3).le.'Z' .and. & + msg(4:4).ge.'A' .and. msg(4:4).le.'Z' .and. & + msg(5:5).eq.' ') msg='CQ '//msg(3:) + + return + end subroutine unpackmsg + + 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 + + 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 + + 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=1 + iz=index(callsign,' ') - 1 + if(iz.lt.0) iz=12 + islash=index(callsign(1:iz),'/') + k=0 + ! if(k.eq.0) go to 10 !Tnx to DL9RDZ for reminder:this was for tests only! + 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 + nv2=2 + go to 10 + endif + enddo + if(addpfx.eq.c) then + k=449 + nv2=2 + 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 + nv2=3 + 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=4 + 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=5 + i=index(callsign0,'/') + callsign=callsign0(:i-1) + endif + endif + endif + + return + end subroutine getpfx1 + + 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 + + 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 + + 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 + + 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 + + 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 + + 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 + + subroutine pack50(n1,n2,dat) + + integer*1 dat(:),i1 + + i1=iand(ishft(n1,-20),255) !8 bits + dat(1)=i1 + i1=iand(ishft(n1,-12),255) !8 bits + dat(2)=i1 + i1=iand(ishft(n1, -4),255) !8 bits + dat(3)=i1 + i1=16*iand(n1,15)+iand(ishft(n2,-18),15) !4+4 bits + dat(4)=i1 + i1=iand(ishft(n2,-10),255) !8 bits + dat(5)=i1 + i1=iand(ishft(n2, -2),255) !8 bits + dat(6)=i1 + i1=64*iand(n2,3) !2 bits + dat(7)=i1 + dat(8)=0 + dat(9)=0 + dat(10)=0 + dat(11)=0 + + return + end subroutine pack50 + +subroutine packpfx(call1,n1,ng,nadd) + + character*12 call1,call0 + character*3 pfx + logical text + + i1=index(call1,'/') + if(call1(i1+2:i1+2).eq.' ') then +! Single-character add-on suffix (maybe also fourth suffix letter?) + call0=call1(:i1-1) + call packcall(call0,n1,text) + nadd=1 + nc=ichar(call1(i1+1:i1+1)) + if(nc.ge.48 .and. nc.le.57) then + n=nc-48 + else if(nc.ge.65 .and. nc.le.90) then + n=nc-65+10 + else + n=38 + endif + nadd=1 + ng=60000-32768+n + else if(call1(i1+3:i1+3).eq.' ') then +! Two-character numerical suffix, /10 to /99 + call0=call1(:i1-1) + call packcall(call0,n1,text) + nadd=1 + n=10*(ichar(call1(i1+1:i1+1))-48) + ichar(call1(i1+2:i1+2)) - 48 + nadd=1 + ng=60000 + 26 + n + else +! Prefix of 1 to 3 characters + pfx=call1(:i1-1) + if(pfx(3:3).eq.' ') pfx=' '//pfx(1:2) + if(pfx(3:3).eq.' ') pfx=' '//pfx(1:2) + call0=call1(i1+1:) + call packcall(call0,n1,text) + + ng=0 + do i=1,3 + nc=ichar(pfx(i:i)) + if(nc.ge.48 .and. nc.le.57) then + n=nc-48 + else if(nc.ge.65 .and. nc.le.90) then + n=nc-65+10 + else + n=36 + endif + ng=37*ng + n + enddo + nadd=0 + if(ng.ge.32768) then + ng=ng-32768 + nadd=1 + endif + endif + + return +end subroutine packpfx + +end module packjt diff --git a/map65/libm65/pfx.f90 b/map65/libm65/pfx.f90 index 1e7b2d97..724b0f8a 100755..100644 --- a/map65/libm65/pfx.f90 +++ b/map65/libm65/pfx.f90 @@ -1,50 +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 ','HK0 ', &
- '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 '/
+ 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 ','HK0 ', & + '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/map65/libm65/pfxdump.f90 b/map65/libm65/pfxdump.f90 index 97cc9f96..7587dbf7 100755..100644 --- a/map65/libm65/pfxdump.f90 +++ b/map65/libm65/pfxdump.f90 @@ -1,13 +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
+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/map65/libm65/polfit.f90 b/map65/libm65/polfit.f90 index d3934665..33e8d44e 100755..100644 --- a/map65/libm65/polfit.f90 +++ b/map65/libm65/polfit.f90 @@ -1,87 +1,87 @@ -subroutine polfit(y,npts,a)
-
-! Input: y(npts) !Expect npts=4
-! Output: a(1) = baseline
-! a(2) = amplitude
-! a(3) = theta (deg)
-
- real y(npts)
- real a(3)
- real deltaa(3)
- integer ipk(1)
- save
-
-! Set starting values:
- a(1)=minval(y)
- a(2)=maxval(y)-a(1)
- ipk=maxloc(y)
- a(3)=(ipk(1)-1)*45.0
-
- deltaa(1:2)=0.1*a(2)
- deltaa(3)=10.0
- nterms=3
-
-! Start the iteration
- chisqr=0.
- chisqr0=1.e6
- iters=10
-
- do iter=1,iters
- do j=1,nterms
- chisq1=fchisq_pol(y,npts,a)
- fn=0.
- delta=deltaa(j)
-10 a(j)=a(j)+delta
- chisq2=fchisq_pol(y,npts,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_pol(y,npts,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(2i2,2(2x,3f8.2),f12.5)
- enddo ! j=1,nterms
- chisqr=fchisq_pol(y,npts,a)
-! write(*,4000) 0,0,a,chisqr
- if(chisqr.lt.1.0) exit
- if(deltaa(1).lt.0.01*(a(2)-a(1)) .and. deltaa(2).lt.0.01*(a(2)-a(1)) &
- .and. deltaa(3).lt.1.0) exit
- if(chisqr/chisqr0.gt.0.99) exit
- chisqr0=chisqr
- enddo ! iter
- a(3)=mod(a(3)+360.0,180.0)
-
- return
-end subroutine polfit
-
-real function fchisq_pol(y,npts,a)
-
- real y(npts),a(3)
- data rad/57.2957795/
-
- chisq = 0.
- do i=1,npts
- theta=(i-1)*45.0
- yfit=a(1) + a(2)*cos((theta-a(3))/rad)**2
- chisq=chisq + (y(i) - yfit)**2
- enddo
- fchisq_pol=chisq
-
- return
-end function fchisq_pol
+subroutine polfit(y,npts,a) + +! Input: y(npts) !Expect npts=4 +! Output: a(1) = baseline +! a(2) = amplitude +! a(3) = theta (deg) + + real y(npts) + real a(3) + real deltaa(3) + integer ipk(1) + save + +! Set starting values: + a(1)=minval(y) + a(2)=maxval(y)-a(1) + ipk=maxloc(y) + a(3)=(ipk(1)-1)*45.0 + + deltaa(1:2)=0.1*a(2) + deltaa(3)=10.0 + nterms=3 + +! Start the iteration + chisqr=0. + chisqr0=1.e6 + iters=10 + + do iter=1,iters + do j=1,nterms + chisq1=fchisq_pol(y,npts,a) + fn=0. + delta=deltaa(j) +10 a(j)=a(j)+delta + chisq2=fchisq_pol(y,npts,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_pol(y,npts,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(2i2,2(2x,3f8.2),f12.5) + enddo ! j=1,nterms + chisqr=fchisq_pol(y,npts,a) +! write(*,4000) 0,0,a,chisqr + if(chisqr.lt.1.0) exit + if(deltaa(1).lt.0.01*(a(2)-a(1)) .and. deltaa(2).lt.0.01*(a(2)-a(1)) & + .and. deltaa(3).lt.1.0) exit + if(chisqr/chisqr0.gt.0.99) exit + chisqr0=chisqr + enddo ! iter + a(3)=mod(a(3)+360.0,180.0) + + return +end subroutine polfit + +real function fchisq_pol(y,npts,a) + + real y(npts),a(3) + data rad/57.2957795/ + + chisq = 0. + do i=1,npts + theta=(i-1)*45.0 + yfit=a(1) + a(2)*cos((theta-a(3))/rad)**2 + chisq=chisq + (y(i) - yfit)**2 + enddo + fchisq_pol=chisq + + return +end function fchisq_pol diff --git a/map65/libm65/ptt.c b/map65/libm65/ptt.c index 247bffbc..0f99d1be 100755..100644 --- a/map65/libm65/ptt.c +++ b/map65/libm65/ptt.c @@ -1,43 +1,43 @@ -#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=0,i4=0,i5=0,i6=0,i9=0,i00=0;
-
- 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) {
- EscapeCommFunction(hFile,3);
- EscapeCommFunction(hFile,5);
- *iptt=1;
- }
-
- else {
- EscapeCommFunction(hFile,4);
- EscapeCommFunction(hFile,6);
- EscapeCommFunction(hFile,9);
- i00=CloseHandle(hFile);
- *iptt=0;
- open=0;
- }
- if((i00+i3+i4+i5+i6+i9)==-99) return -1; //Silence compiler warning
- return 0;
-}
+#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=0,i4=0,i5=0,i6=0,i9=0,i00=0; + + 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) { + EscapeCommFunction(hFile,3); + EscapeCommFunction(hFile,5); + *iptt=1; + } + + else { + EscapeCommFunction(hFile,4); + EscapeCommFunction(hFile,6); + EscapeCommFunction(hFile,9); + i00=CloseHandle(hFile); + *iptt=0; + open=0; + } + if((i00+i3+i4+i5+i6+i9)==-99) return -1; //Silence compiler warning + return 0; +} diff --git a/map65/libm65/ptt_unix.c b/map65/libm65/ptt_unix.c index 20f049d3..1c583f64 100755..100644 --- a/map65/libm65/ptt_unix.c +++ b/map65/libm65/ptt_unix.c @@ -1,405 +1,405 @@ -/*
- * WSJT is Copyright (c) 2001-2006 by Joseph H. Taylor, Jr., K1JT,
- * and is licensed under the GNU General Public License (GPL).
- *
- * Code used from cwdaemon for parallel port ptt only.
- *
- * cwdaemon - morse sounding daemon for the parallel or serial port
- * Copyright (C) 2002 -2005 Joop Stakenborg <pg4i@amsat.org>
- * and many authors, see the AUTHORS file.
- *
- * 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-# if HAVE_STDIO_H
-# include <stdio.h>
-#endif
-#if STDC_HEADERS
-# include <stdlib.h>
-# include <stddef.h>
-#else
-# if HAVE_STDLIB_H
-# include <stdlib.h>
-# endif
-#endif
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-#if HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-#if HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#if HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-
-#ifdef HAVE_LINUX_PPDEV_H
-# include <linux/ppdev.h>
-# include <linux/parport.h>
-#endif
-#ifdef HAVE_DEV_PPBUS_PPI_H
-# include <dev/ppbus/ppi.h>
-# include <dev/ppbus/ppbconf.h>
-#endif
-
-int lp_reset (int fd);
-int lp_ptt (int fd, int onoff);
-
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-#if (defined(__unix__) || defined(unix)) && !defined(USG)
-# include <sys/param.h>
-#endif
-
-#include <string.h>
-/* parport functions */
-
-int dev_is_parport(int fd);
-int ptt_parallel(int fd, int *ntx, int *iptt);
-int ptt_serial(int fd, int *ntx, int *iptt);
-
-int fd=-1; /* Used for both serial and parallel */
-
-/*
- * ptt_
- *
- * generic unix PTT routine called from Fortran
- *
- * Inputs
- * unused Unused, to satisfy old windows calling convention
- * ptt_port device name serial or parallel
- * ntx pointer to fortran command on or off
- * iptt pointer to fortran command status on or off
- * Returns - non 0 if error
-*/
-
-/* Tiny state machine */
-#define STATE_PORT_CLOSED 0
-#define STATE_PORT_OPEN_PARALLEL 1
-#define STATE_PORT_OPEN_SERIAL 2
-
-//int ptt_(int *unused, char *ptt_port, int *ntx, int *iptt)
-int ptt_(int *unused, int *ntx, int *iptt)
-{
- static int state=0;
- char *p;
-
-// ### Temporary:
- char* ptt_port;
- if(*unused != -99) {
- *iptt=*ntx;
- return 0;
- }
-// ###
-
- /* In the very unlikely event of a NULL pointer, just return.
- * Yes, I realise this should not be possible in WSJT.
- */
- if (ptt_port == NULL) {
- *iptt = *ntx;
- return (0);
- }
-
- switch (state) {
- case STATE_PORT_CLOSED:
-
- /* Remove trailing ' ' */
- if ((p = strchr(ptt_port, ' ')) != NULL)
- *p = '\0';
-
- /* If all that is left is a '\0' then also just return */
- if (*ptt_port == '\0') {
- *iptt = *ntx;
- return(0);
- }
-
- if ((fd = open(ptt_port, O_RDWR|O_NONBLOCK)) < 0) {
- fprintf(stderr, "Can't open %s.\n", ptt_port);
- return (1);
- }
-
- if (dev_is_parport(fd)) {
- state = STATE_PORT_OPEN_PARALLEL;
- lp_reset(fd);
- ptt_parallel(fd, ntx, iptt);
- } else {
- state = STATE_PORT_OPEN_SERIAL;
- ptt_serial(fd, ntx, iptt);
- }
- break;
-
- case STATE_PORT_OPEN_PARALLEL:
- ptt_parallel(fd, ntx, iptt);
- break;
-
- case STATE_PORT_OPEN_SERIAL:
- ptt_serial(fd, ntx, iptt);
- break;
-
- default:
- close(fd);
- fd = -1;
- state = STATE_PORT_CLOSED;
- break;
- }
- return(0);
-}
-
-/*
- * ptt_serial
- *
- * generic serial unix PTT routine called indirectly from Fortran
- *
- * fd - already opened file descriptor
- * ntx - pointer to fortran command on or off
- * iptt - pointer to fortran command status on or off
- */
-
-int
-ptt_serial(int fd, int *ntx, int *iptt)
-{
- int control = TIOCM_RTS | TIOCM_DTR;
-
-#if defined (TIOCMBIS) && defined (TIOCMBIS)
- if(*ntx) {
- ioctl(fd, TIOCMBIS, &control); /* Set DTR and RTS */
- *iptt = 1;
- } else {
- ioctl(fd, TIOCMBIC, &control);
- *iptt = 0;
- }
-#else
- unsigned y;
- ioctl(fd, TIOCMGET, &y);
- if (*ntx) {
- y |= control;
- } else {
- y &= ~control;
- }
- ioctl(fd, TIOCMSET, &y);
-#endif
- return(0);
-}
-
-
-/* parport functions */
-
-/*
- * dev_is_parport(fd):
- *
- * inputs - Already open fd
- * output - 1 if parallel port, 0 if not
- * side effects - Unfortunately, this is platform specific.
- */
-
-#if defined(HAVE_LINUX_PPDEV_H) /* Linux (ppdev) */
-
-int
-dev_is_parport(int fd)
-{
- struct stat st;
- int m;
-
- if ((fstat(fd, &st) == -1) ||
- ((st.st_mode & S_IFMT) != S_IFCHR) ||
- (ioctl(fd, PPGETMODE, &m) == -1))
- return(0);
-
- return(1);
-}
-
-#elif defined(HAVE_DEV_PPBUS_PPI_H) /* FreeBSD (ppbus/ppi) */
-
-int
-dev_is_parport(int fd)
-{
- struct stat st;
- unsigned char c;
-
- if ((fstat(fd, &st) == -1) ||
- ((st.st_mode & S_IFMT) != S_IFCHR) ||
- (ioctl(fd, PPISSTATUS, &c) == -1))
- return(0);
-
- return(1);
-}
-
-#else /* Fallback (nothing) */
-
-int
-dev_is_parport(int fd)
-{
- return(0);
-}
-
-#endif
-/* Linux wrapper around PPFCONTROL */
-#ifdef HAVE_LINUX_PPDEV_H
-static void
-parport_control (int fd, unsigned char controlbits, int values)
-{
- struct ppdev_frob_struct frob;
- frob.mask = controlbits;
- frob.val = values;
-
- if (ioctl (fd, PPFCONTROL, &frob) == -1)
- {
- fprintf(stderr, "Parallel port PPFCONTROL");
- exit (1);
- }
-}
-#endif
-
-/* FreeBSD wrapper around PPISCTRL */
-#ifdef HAVE_DEV_PPBUS_PPI_H
-static void
-parport_control (int fd, unsigned char controlbits, int values)
-{
- unsigned char val;
-
- if (ioctl (fd, PPIGCTRL, &val) == -1)
- {
- fprintf(stderr, "Parallel port PPIGCTRL");
- exit (1);
- }
-
- val &= ~controlbits;
- val |= values;
-
- if (ioctl (fd, PPISCTRL, &val) == -1)
- {
- fprintf(stderr, "Parallel port PPISCTRL");
- exit (1);
- }
-}
-#endif
-
-/* Initialise a parallel port, given open fd */
-int
-lp_init (int fd)
-{
-#ifdef HAVE_LINUX_PPDEV_H
- int mode;
-#endif
-
-#ifdef HAVE_LINUX_PPDEV_H
- mode = PARPORT_MODE_PCSPP;
-
- if (ioctl (fd, PPSETMODE, &mode) == -1)
- {
- fprintf(stderr, "Setting parallel port mode");
- close (fd);
- return(-1);
- }
-
- if (ioctl (fd, PPEXCL, NULL) == -1)
- {
- fprintf(stderr, "Parallel port is already in use.\n");
- close (fd);
- return(-1);
- }
- if (ioctl (fd, PPCLAIM, NULL) == -1)
- {
- fprintf(stderr, "Claiming parallel port.\n");
- fprintf(stderr, "HINT: did you unload the lp kernel module?");
- close (fd);
- return(-1);
- }
-
- /* Enable CW & PTT - /STROBE bit (pin 1) */
- parport_control (fd, PARPORT_CONTROL_STROBE, PARPORT_CONTROL_STROBE);
-#endif
-#ifdef HAVE_DEV_PPBUS_PPI_H
- parport_control (fd, STROBE, STROBE);
-#endif
- lp_reset (fd);
- return(0);
-}
-
-/* release ppdev and close port */
-int
-lp_free (int fd)
-{
-#ifdef HAVE_LINUX_PPDEV_H
- lp_reset (fd);
-
- /* Disable CW & PTT - /STROBE bit (pin 1) */
- parport_control (fd, PARPORT_CONTROL_STROBE, 0);
-
- ioctl (fd, PPRELEASE);
-#endif
-#ifdef HAVE_DEV_PPBUS_PPI_H
- /* Disable CW & PTT - /STROBE bit (pin 1) */
- parport_control (fd, STROBE, 0);
-#endif
- close (fd);
- return(0);
-}
-
-/* set to a known state */
-int
-lp_reset (int fd)
-{
-#if defined (HAVE_LINUX_PPDEV_H) || defined (HAVE_DEV_PPBUS_PPI_H)
- lp_ptt (fd, 0);
-#endif
- return(0);
-}
-
-/* SSB PTT keying - /INIT bit (pin 16) (inverted) */
-int
-lp_ptt (int fd, int onoff)
-{
-#ifdef HAVE_LINUX_PPDEV_H
- if (onoff == 1)
- parport_control (fd, PARPORT_CONTROL_INIT,
- PARPORT_CONTROL_INIT);
- else
- parport_control (fd, PARPORT_CONTROL_INIT, 0);
-#endif
-#ifdef HAVE_DEV_PPBUS_PPI_H
- if (onoff == 1)
- parport_control (fd, nINIT,
- nINIT);
- else
- parport_control (fd, nINIT, 0);
-#endif
- return(0);
-}
-
-/*
- * ptt_parallel
- *
- * generic parallel unix PTT routine called indirectly from Fortran
- *
- * fd - already opened file descriptor
- * ntx - pointer to fortran command on or off
- * iptt - pointer to fortran command status on or off
- */
-
-int
-ptt_parallel(int fd, int *ntx, int *iptt)
-{
- if(*ntx) {
- lp_ptt(fd, 1);
- *iptt=1;
- } else {
- lp_ptt(fd, 0);
- *iptt=0;
- }
- return(0);
-}
+/* + * WSJT is Copyright (c) 2001-2006 by Joseph H. Taylor, Jr., K1JT, + * and is licensed under the GNU General Public License (GPL). + * + * Code used from cwdaemon for parallel port ptt only. + * + * cwdaemon - morse sounding daemon for the parallel or serial port + * Copyright (C) 2002 -2005 Joop Stakenborg <pg4i@amsat.org> + * and many authors, see the AUTHORS file. + * + * 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +# if HAVE_STDIO_H +# include <stdio.h> +#endif +#if STDC_HEADERS +# include <stdlib.h> +# include <stddef.h> +#else +# if HAVE_STDLIB_H +# include <stdlib.h> +# endif +#endif +#if HAVE_UNISTD_H +# include <unistd.h> +#endif +#if HAVE_SYS_STAT_H +# include <sys/stat.h> +#endif +#if HAVE_SYS_IOCTL_H +# include <sys/ioctl.h> +#endif +#if HAVE_FCNTL_H +# include <fcntl.h> +#endif + +#ifdef HAVE_LINUX_PPDEV_H +# include <linux/ppdev.h> +# include <linux/parport.h> +#endif +#ifdef HAVE_DEV_PPBUS_PPI_H +# include <dev/ppbus/ppi.h> +# include <dev/ppbus/ppbconf.h> +#endif + +int lp_reset (int fd); +int lp_ptt (int fd, int onoff); + +#ifdef HAVE_SYS_STAT_H +# include <sys/stat.h> +#endif +#if (defined(__unix__) || defined(unix)) && !defined(USG) +# include <sys/param.h> +#endif + +#include <string.h> +/* parport functions */ + +int dev_is_parport(int fd); +int ptt_parallel(int fd, int *ntx, int *iptt); +int ptt_serial(int fd, int *ntx, int *iptt); + +int fd=-1; /* Used for both serial and parallel */ + +/* + * ptt_ + * + * generic unix PTT routine called from Fortran + * + * Inputs + * unused Unused, to satisfy old windows calling convention + * ptt_port device name serial or parallel + * ntx pointer to fortran command on or off + * iptt pointer to fortran command status on or off + * Returns - non 0 if error +*/ + +/* Tiny state machine */ +#define STATE_PORT_CLOSED 0 +#define STATE_PORT_OPEN_PARALLEL 1 +#define STATE_PORT_OPEN_SERIAL 2 + +//int ptt_(int *unused, char *ptt_port, int *ntx, int *iptt) +int ptt_(int *unused, int *ntx, int *iptt) +{ + static int state=0; + char *p; + +// ### Temporary: + char* ptt_port; + if(*unused != -99) { + *iptt=*ntx; + return 0; + } +// ### + + /* In the very unlikely event of a NULL pointer, just return. + * Yes, I realise this should not be possible in WSJT. + */ + if (ptt_port == NULL) { + *iptt = *ntx; + return (0); + } + + switch (state) { + case STATE_PORT_CLOSED: + + /* Remove trailing ' ' */ + if ((p = strchr(ptt_port, ' ')) != NULL) + *p = '\0'; + + /* If all that is left is a '\0' then also just return */ + if (*ptt_port == '\0') { + *iptt = *ntx; + return(0); + } + + if ((fd = open(ptt_port, O_RDWR|O_NONBLOCK)) < 0) { + fprintf(stderr, "Can't open %s.\n", ptt_port); + return (1); + } + + if (dev_is_parport(fd)) { + state = STATE_PORT_OPEN_PARALLEL; + lp_reset(fd); + ptt_parallel(fd, ntx, iptt); + } else { + state = STATE_PORT_OPEN_SERIAL; + ptt_serial(fd, ntx, iptt); + } + break; + + case STATE_PORT_OPEN_PARALLEL: + ptt_parallel(fd, ntx, iptt); + break; + + case STATE_PORT_OPEN_SERIAL: + ptt_serial(fd, ntx, iptt); + break; + + default: + close(fd); + fd = -1; + state = STATE_PORT_CLOSED; + break; + } + return(0); +} + +/* + * ptt_serial + * + * generic serial unix PTT routine called indirectly from Fortran + * + * fd - already opened file descriptor + * ntx - pointer to fortran command on or off + * iptt - pointer to fortran command status on or off + */ + +int +ptt_serial(int fd, int *ntx, int *iptt) +{ + int control = TIOCM_RTS | TIOCM_DTR; + +#if defined (TIOCMBIS) && defined (TIOCMBIS) + if(*ntx) { + ioctl(fd, TIOCMBIS, &control); /* Set DTR and RTS */ + *iptt = 1; + } else { + ioctl(fd, TIOCMBIC, &control); + *iptt = 0; + } +#else + unsigned y; + ioctl(fd, TIOCMGET, &y); + if (*ntx) { + y |= control; + } else { + y &= ~control; + } + ioctl(fd, TIOCMSET, &y); +#endif + return(0); +} + + +/* parport functions */ + +/* + * dev_is_parport(fd): + * + * inputs - Already open fd + * output - 1 if parallel port, 0 if not + * side effects - Unfortunately, this is platform specific. + */ + +#if defined(HAVE_LINUX_PPDEV_H) /* Linux (ppdev) */ + +int +dev_is_parport(int fd) +{ + struct stat st; + int m; + + if ((fstat(fd, &st) == -1) || + ((st.st_mode & S_IFMT) != S_IFCHR) || + (ioctl(fd, PPGETMODE, &m) == -1)) + return(0); + + return(1); +} + +#elif defined(HAVE_DEV_PPBUS_PPI_H) /* FreeBSD (ppbus/ppi) */ + +int +dev_is_parport(int fd) +{ + struct stat st; + unsigned char c; + + if ((fstat(fd, &st) == -1) || + ((st.st_mode & S_IFMT) != S_IFCHR) || + (ioctl(fd, PPISSTATUS, &c) == -1)) + return(0); + + return(1); +} + +#else /* Fallback (nothing) */ + +int +dev_is_parport(int fd) +{ + return(0); +} + +#endif +/* Linux wrapper around PPFCONTROL */ +#ifdef HAVE_LINUX_PPDEV_H +static void +parport_control (int fd, unsigned char controlbits, int values) +{ + struct ppdev_frob_struct frob; + frob.mask = controlbits; + frob.val = values; + + if (ioctl (fd, PPFCONTROL, &frob) == -1) + { + fprintf(stderr, "Parallel port PPFCONTROL"); + exit (1); + } +} +#endif + +/* FreeBSD wrapper around PPISCTRL */ +#ifdef HAVE_DEV_PPBUS_PPI_H +static void +parport_control (int fd, unsigned char controlbits, int values) +{ + unsigned char val; + + if (ioctl (fd, PPIGCTRL, &val) == -1) + { + fprintf(stderr, "Parallel port PPIGCTRL"); + exit (1); + } + + val &= ~controlbits; + val |= values; + + if (ioctl (fd, PPISCTRL, &val) == -1) + { + fprintf(stderr, "Parallel port PPISCTRL"); + exit (1); + } +} +#endif + +/* Initialise a parallel port, given open fd */ +int +lp_init (int fd) +{ +#ifdef HAVE_LINUX_PPDEV_H + int mode; +#endif + +#ifdef HAVE_LINUX_PPDEV_H + mode = PARPORT_MODE_PCSPP; + + if (ioctl (fd, PPSETMODE, &mode) == -1) + { + fprintf(stderr, "Setting parallel port mode"); + close (fd); + return(-1); + } + + if (ioctl (fd, PPEXCL, NULL) == -1) + { + fprintf(stderr, "Parallel port is already in use.\n"); + close (fd); + return(-1); + } + if (ioctl (fd, PPCLAIM, NULL) == -1) + { + fprintf(stderr, "Claiming parallel port.\n"); + fprintf(stderr, "HINT: did you unload the lp kernel module?"); + close (fd); + return(-1); + } + + /* Enable CW & PTT - /STROBE bit (pin 1) */ + parport_control (fd, PARPORT_CONTROL_STROBE, PARPORT_CONTROL_STROBE); +#endif +#ifdef HAVE_DEV_PPBUS_PPI_H + parport_control (fd, STROBE, STROBE); +#endif + lp_reset (fd); + return(0); +} + +/* release ppdev and close port */ +int +lp_free (int fd) +{ +#ifdef HAVE_LINUX_PPDEV_H + lp_reset (fd); + + /* Disable CW & PTT - /STROBE bit (pin 1) */ + parport_control (fd, PARPORT_CONTROL_STROBE, 0); + + ioctl (fd, PPRELEASE); +#endif +#ifdef HAVE_DEV_PPBUS_PPI_H + /* Disable CW & PTT - /STROBE bit (pin 1) */ + parport_control (fd, STROBE, 0); +#endif + close (fd); + return(0); +} + +/* set to a known state */ +int +lp_reset (int fd) +{ +#if defined (HAVE_LINUX_PPDEV_H) || defined (HAVE_DEV_PPBUS_PPI_H) + lp_ptt (fd, 0); +#endif + return(0); +} + +/* SSB PTT keying - /INIT bit (pin 16) (inverted) */ +int +lp_ptt (int fd, int onoff) +{ +#ifdef HAVE_LINUX_PPDEV_H + if (onoff == 1) + parport_control (fd, PARPORT_CONTROL_INIT, + PARPORT_CONTROL_INIT); + else + parport_control (fd, PARPORT_CONTROL_INIT, 0); +#endif +#ifdef HAVE_DEV_PPBUS_PPI_H + if (onoff == 1) + parport_control (fd, nINIT, + nINIT); + else + parport_control (fd, nINIT, 0); +#endif + return(0); +} + +/* + * ptt_parallel + * + * generic parallel unix PTT routine called indirectly from Fortran + * + * fd - already opened file descriptor + * ntx - pointer to fortran command on or off + * iptt - pointer to fortran command status on or off + */ + +int +ptt_parallel(int fd, int *ntx, int *iptt) +{ + if(*ntx) { + lp_ptt(fd, 1); + *iptt=1; + } else { + lp_ptt(fd, 0); + *iptt=0; + } + return(0); +} diff --git a/map65/libm65/q65b.f90 b/map65/libm65/q65b.f90 index 20b37d0e..77367b8f 100755..100644 --- a/map65/libm65/q65b.f90 +++ b/map65/libm65/q65b.f90 @@ -1,205 +1,205 @@ -subroutine q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf,ntol,xpol, &
- mycall0,mygrid,hiscall0,hisgrid,mode_q65,f0,fqso,newdat,nagain, &
- max_drift,nhsym,ndop00,idec)
-
-! This routine provides an interface between MAP65 and the Q65 decoder
-! in WSJT-X. All arguments are input data obtained from the MAP65 GUI.
-! Raw Rx data are available as the 96 kHz complex spectrum ca(MAXFFT1)
-! in common/cacb. If xpol is true, we also have cb(MAXFFT1) for the
-! orthogonal polarization. Decoded messages are sent back to the GUI
-! on stdout.
-
-! use wavhdr
- use q65_decode
- use wideband_sync
- use timer_module, only: timer
-
- parameter (MAXFFT1=5376000) !56*96000
- parameter (MAXFFT2=336000) !56*6000 (downsampled by 1/16)
- parameter (NMAX=60*12000)
- parameter (RAD=57.2957795)
-! type(hdr) h !Header for the .wav file
- integer*2 iwave(60*12000)
- complex ca(MAXFFT1),cb(MAXFFT1) !FFTs of raw x,y data
- complex cx(0:MAXFFT2-1),cy(0:MAXFFT2-1),cz(0:MAXFFT2)
- logical xpol,ldecoded
- integer ipk1(1)
- real*8 fcenter,freq0,freq1
- character*12 mycall0,hiscall0
- character*12 mycall,hiscall
- character*6 mygrid,hisgrid
- character*4 grid4
- character*28 msg00
- character*80 line
- character*80 wsjtx_dir
- character*1 cp,cmode*2
- common/cacb/ca,cb
- common/early/nhsym1,nhsym2,ldecoded(32768)
- common/decodes/ndecodes
- data nutc00/-1/,msg00/' '/
- save
-
- if(newdat.eq.1) nutc00=-1
- open(9,file='wsjtx_dir.txt',status='old')
- read(9,'(a)') wsjtx_dir !Establish the working directory
- close(9)
-
- if(mycall0(1:1).ne.' ') mycall=mycall0
- if(hiscall0(1:1).ne.' ') hiscall=hiscall0
- if(hisgrid(1:4).ne.' ') grid4=hisgrid(1:4)
-
-! Find best frequency and ipol from sync_dat, the "orange sync curve".
- df3=96000.0/32768.0
- ifreq=nint((1000.0*f0)/df3)
- ia=nint(ifreq-ntol/df3)
- ib=nint(ifreq+ntol/df3)
- ipk1=maxloc(sync(ia:ib)%ccfmax)
- ipk=ia+ipk1(1)-1
- if(ldecoded(ipk)) go to 900
- snr1=sync(ipk)%ccfmax
- ipol=1
- if(xpol) ipol=sync(ipk)%ipol
-
- nfft1=MAXFFT1
- nfft2=MAXFFT2
- df=96000.0/NFFT1
- if(nfsample.eq.95238) then
- nfft1=5120000
- nfft2=322560
- df=96000.0/nfft1
- endif
- nh=nfft2/2
- f_mouse=1000.0*(fqso+48.0) + mousedf
- f_ipk=ipk*df3
- k0=nint((ipk*df3-1000.0)/df)
- if(nagain.eq.1) k0=nint((f_mouse-1000.0)/df)
-
- if(k0.lt.nh .or. k0.gt.MAXFFT1-nfft2+1) go to 900
- if(snr1.lt.1.5) go to 900 !### Threshold needs work? ###
-
- fac=1.0/nfft2
- cx(0:nfft2-1)=ca(k0:k0+nfft2-1)
- cx=fac*cx
- if(xpol) then
- cy(0:nfft2-1)=cb(k0:k0+nfft2-1)
- cy=fac*cy
- endif
-
-! Here cx and cy (if xpol) are frequency-domain data around the selected
-! QSO frequency, taken from the full-length FFT computed in filbig().
-! Values for fsample, nfft1, nfft2, df, and the downsampled data rate
-! are as follows:
-
-! fSample nfft1 df nfft2 fDownSampled
-! (Hz) (Hz) (Hz)
-!----------------------------------------------------
-! 96000 5376000 0.017857143 336000 6000.000
-! 95238 5120000 0.018601172 322560 5999.994
-
- poldeg=0.
- if(xpol) then
- poldeg=sync(ipk)%pol
- cz(0:MAXFFT2-1)=cos(poldeg/RAD)*cx + sin(poldeg/RAD)*cy
- else
- cz(0:MAXFFT2-1)=cx
- endif
-
- cz(MAXFFT2)=0.
-! Roll off below 500 Hz and above 2500 Hz.
- ja=nint(500.0/df)
- jb=nint(2500.0/df)
- do i=0,ja
- r=0.5*(1.0+cos(i*3.14159/ja))
- cz(ja-i)=r*cz(ja-i)
- cz(jb+i)=r*cz(jb+i)
- enddo
- cz(ja+jb+1:)=0.
-
-!Transform to time domain (real), fsample=12000 Hz
- call four2a(cz,2*nfft2,1,1,-1)
- do i=0,nfft2-1
- j=nfft2-1-i
- iwave(2*i+2)=nint(real(cz(j))) !Note the reversed order!
- iwave(2*i+1)=nint(aimag(cz(j)))
- enddo
- iwave(2*nfft2+1:)=0
-
-! open(30,file='000000_0001.wav',status='unknown',access='stream')
-! h=default_header(12000,NMAX)
-! write(30) h,iwave
-! close(30)
-
- nsubmode=mode_q65-1
- nfa=990 !Tight limits around ipk for the wideband decode
- nfb=1010
- if(nagain.eq.1) then !For nagain=1, use limits of +/- ntol
- nfa=max(100,1000-ntol)
- nfb=min(2500,1000+ntol)
- endif
- nsnr0=-99 !Default snr for no decode
- ndpth=3
-
-! NB: Frequency of ipk is now shifted to 1000 Hz.
- call map65_mmdec(nutc,iwave,nqd,60,nsubmode,nfa,nfb,1000,ntol, &
- newdat,nagain,max_drift,ndepth,mycall,hiscall0,hisgrid)
-
- MHz=fcenter
- freq0=MHz + 0.001d0*ikhz
-
- if(nsnr0.gt.-99) then
- ldecoded(ipk)=.true.
- nq65df=nint(1000*(0.001*k0*df+nkhz_center-48.0+1.000-1.27046-ikhz))-nfcal
- nq65df=nq65df + nfreq0 - 1000
- npol=nint(poldeg)
- if(nxant.ne.0) then
- npol=npol-45
- if(npol.lt.0) npol=npol+180
- endif
- call txpol(xpol,msg0(1:28),mygrid,npol,nxant,ntxpol,cp) ! was 1:22
- ikhz1=ikhz
- ndf=nq65df
- if(ndf.gt.500) ikhz1=ikhz + (nq65df+500)/1000
- if(ndf.lt.-500) ikhz1=ikhz + (nq65df-500)/1000
- ndf=nq65df - 1000*(ikhz1-ikhz)
- if(nqd.eq.1 .and. abs(nq65df-mousedf).lt.ntol) then
- write(line,1020) ikhz1,ndf,npol,nutc,xdt0,nsnr0,msg0(1:28),cq0, &
- ntxpol,cp
-1020 format('!',i3.3,i5,i4,i6.4,f5.1,i5,' : ',a28,a3,i4,1x,a1)
- write(*,1100) trim(line)
-1100 format(a)
- endif
-
-! Write to lu 26, for Messages and Band Map windows
- cmode=': '
- cmode(2:2)=char(ichar('A') + mode_q65-1)
- freq1=freq0 + 0.001d0*(ikhz1-ikhz)
- write(26,1014) freq1,ndf,0,0,0,xdt0,npol,0,nsnr0,nutc,msg0(1:28), &
- ':',cp,cmode ! was 1:22
-1014 format(f8.3,i5,3i3,f5.1,i4,i3,i4,i5.4,4x,a28,1x,2a1,2x,a2) ! was a22
-
-! Suppress writing duplicates (same time, decoded message, and frequency)
-! to map65_rx.log
- if(nutc.ne.nutc00 .or. msg0(1:28).ne.msg00 .or. freq1.ne.freq1_00) then
-! Write to file map65_rx.log:
- ndecodes=ndecodes+1
- write(21,1110) freq1,ndf,xdt0,npol,nsnr0,nutc,msg0(1:28), &
- cmode(2:2),cq0
-1110 format(f8.3,i5,f5.1,2i4,i5.4,2x,a28,': ',a1,2x,a3)
- nutc00=nutc
- msg00=msg0(1:28)
- freq1_00=freq1
- frx=0.001*k0*df+nkhz_center-48.0+1.0 - 0.001*nfcal
- fsked=frx - 0.001*ndop00/2.0 - 1.5
- write(12,1120) nutc,fsked,xdt0,nsnr0,trim(msg0)
-1120 format(i4.4,f9.3,f7.2,i5,2x,a,i6)
- endif
- endif
-
-900 close(13)
- close(17)
- call flush(6)
- idec=-1
- read(cq0(2:2),*) idec
-
- return
-end subroutine q65b
+subroutine q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf,ntol,xpol, & + mycall0,mygrid,hiscall0,hisgrid,mode_q65,f0,fqso,newdat,nagain, & + max_drift,nhsym,ndop00,idec) + +! This routine provides an interface between MAP65 and the Q65 decoder +! in WSJT-X. All arguments are input data obtained from the MAP65 GUI. +! Raw Rx data are available as the 96 kHz complex spectrum ca(MAXFFT1) +! in common/cacb. If xpol is true, we also have cb(MAXFFT1) for the +! orthogonal polarization. Decoded messages are sent back to the GUI +! on stdout. + +! use wavhdr + use q65_decode + use wideband_sync + use timer_module, only: timer + + parameter (MAXFFT1=5376000) !56*96000 + parameter (MAXFFT2=336000) !56*6000 (downsampled by 1/16) + parameter (NMAX=60*12000) + parameter (RAD=57.2957795) +! type(hdr) h !Header for the .wav file + integer*2 iwave(60*12000) + complex ca(MAXFFT1),cb(MAXFFT1) !FFTs of raw x,y data + complex cx(0:MAXFFT2-1),cy(0:MAXFFT2-1),cz(0:MAXFFT2) + logical xpol,ldecoded + integer ipk1(1) + real*8 fcenter,freq0,freq1 + character*12 mycall0,hiscall0 + character*12 mycall,hiscall + character*6 mygrid,hisgrid + character*4 grid4 + character*28 msg00 + character*80 line + character*80 wsjtx_dir + character*1 cp,cmode*2 + common/cacb/ca,cb + common/early/nhsym1,nhsym2,ldecoded(32768) + common/decodes/ndecodes + data nutc00/-1/,msg00/' '/ + save + + if(newdat.eq.1) nutc00=-1 + open(9,file='wsjtx_dir.txt',status='old') + read(9,'(a)') wsjtx_dir !Establish the working directory + close(9) + + if(mycall0(1:1).ne.' ') mycall=mycall0 + if(hiscall0(1:1).ne.' ') hiscall=hiscall0 + if(hisgrid(1:4).ne.' ') grid4=hisgrid(1:4) + +! Find best frequency and ipol from sync_dat, the "orange sync curve". + df3=96000.0/32768.0 + ifreq=nint((1000.0*f0)/df3) + ia=nint(ifreq-ntol/df3) + ib=nint(ifreq+ntol/df3) + ipk1=maxloc(sync(ia:ib)%ccfmax) + ipk=ia+ipk1(1)-1 + if(ldecoded(ipk)) go to 900 + snr1=sync(ipk)%ccfmax + ipol=1 + if(xpol) ipol=sync(ipk)%ipol + + nfft1=MAXFFT1 + nfft2=MAXFFT2 + df=96000.0/NFFT1 + if(nfsample.eq.95238) then + nfft1=5120000 + nfft2=322560 + df=96000.0/nfft1 + endif + nh=nfft2/2 + f_mouse=1000.0*(fqso+48.0) + mousedf + f_ipk=ipk*df3 + k0=nint((ipk*df3-1000.0)/df) + if(nagain.eq.1) k0=nint((f_mouse-1000.0)/df) + + if(k0.lt.nh .or. k0.gt.MAXFFT1-nfft2+1) go to 900 + if(snr1.lt.1.5) go to 900 !### Threshold needs work? ### + + fac=1.0/nfft2 + cx(0:nfft2-1)=ca(k0:k0+nfft2-1) + cx=fac*cx + if(xpol) then + cy(0:nfft2-1)=cb(k0:k0+nfft2-1) + cy=fac*cy + endif + +! Here cx and cy (if xpol) are frequency-domain data around the selected +! QSO frequency, taken from the full-length FFT computed in filbig(). +! Values for fsample, nfft1, nfft2, df, and the downsampled data rate +! are as follows: + +! fSample nfft1 df nfft2 fDownSampled +! (Hz) (Hz) (Hz) +!---------------------------------------------------- +! 96000 5376000 0.017857143 336000 6000.000 +! 95238 5120000 0.018601172 322560 5999.994 + + poldeg=0. + if(xpol) then + poldeg=sync(ipk)%pol + cz(0:MAXFFT2-1)=cos(poldeg/RAD)*cx + sin(poldeg/RAD)*cy + else + cz(0:MAXFFT2-1)=cx + endif + + cz(MAXFFT2)=0. +! Roll off below 500 Hz and above 2500 Hz. + ja=nint(500.0/df) + jb=nint(2500.0/df) + do i=0,ja + r=0.5*(1.0+cos(i*3.14159/ja)) + cz(ja-i)=r*cz(ja-i) + cz(jb+i)=r*cz(jb+i) + enddo + cz(ja+jb+1:)=0. + +!Transform to time domain (real), fsample=12000 Hz + call four2a(cz,2*nfft2,1,1,-1) + do i=0,nfft2-1 + j=nfft2-1-i + iwave(2*i+2)=nint(real(cz(j))) !Note the reversed order! + iwave(2*i+1)=nint(aimag(cz(j))) + enddo + iwave(2*nfft2+1:)=0 + +! open(30,file='000000_0001.wav',status='unknown',access='stream') +! h=default_header(12000,NMAX) +! write(30) h,iwave +! close(30) + + nsubmode=mode_q65-1 + nfa=990 !Tight limits around ipk for the wideband decode + nfb=1010 + if(nagain.eq.1) then !For nagain=1, use limits of +/- ntol + nfa=max(100,1000-ntol) + nfb=min(2500,1000+ntol) + endif + nsnr0=-99 !Default snr for no decode + ndpth=3 + +! NB: Frequency of ipk is now shifted to 1000 Hz. + call map65_mmdec(nutc,iwave,nqd,60,nsubmode,nfa,nfb,1000,ntol, & + newdat,nagain,max_drift,ndepth,mycall,hiscall0,hisgrid) + + MHz=fcenter + freq0=MHz + 0.001d0*ikhz + + if(nsnr0.gt.-99) then + ldecoded(ipk)=.true. + nq65df=nint(1000*(0.001*k0*df+nkhz_center-48.0+1.000-1.27046-ikhz))-nfcal + nq65df=nq65df + nfreq0 - 1000 + npol=nint(poldeg) + if(nxant.ne.0) then + npol=npol-45 + if(npol.lt.0) npol=npol+180 + endif + call txpol(xpol,msg0(1:28),mygrid,npol,nxant,ntxpol,cp) ! was 1:22 + ikhz1=ikhz + ndf=nq65df + if(ndf.gt.500) ikhz1=ikhz + (nq65df+500)/1000 + if(ndf.lt.-500) ikhz1=ikhz + (nq65df-500)/1000 + ndf=nq65df - 1000*(ikhz1-ikhz) + if(nqd.eq.1 .and. abs(nq65df-mousedf).lt.ntol) then + write(line,1020) ikhz1,ndf,npol,nutc,xdt0,nsnr0,msg0(1:28),cq0, & + ntxpol,cp +1020 format('!',i3.3,i5,i4,i6.4,f5.1,i5,' : ',a28,a3,i4,1x,a1) + write(*,1100) trim(line) +1100 format(a) + endif + +! Write to lu 26, for Messages and Band Map windows + cmode=': ' + cmode(2:2)=char(ichar('A') + mode_q65-1) + freq1=freq0 + 0.001d0*(ikhz1-ikhz) + write(26,1014) freq1,ndf,0,0,0,xdt0,npol,0,nsnr0,nutc,msg0(1:28), & + ':',cp,cmode ! was 1:22 +1014 format(f8.3,i5,3i3,f5.1,i4,i3,i4,i5.4,4x,a28,1x,2a1,2x,a2) ! was a22 + +! Suppress writing duplicates (same time, decoded message, and frequency) +! to map65_rx.log + if(nutc.ne.nutc00 .or. msg0(1:28).ne.msg00 .or. freq1.ne.freq1_00) then +! Write to file map65_rx.log: + ndecodes=ndecodes+1 + write(21,1110) freq1,ndf,xdt0,npol,nsnr0,nutc,msg0(1:28), & + cmode(2:2),cq0 +1110 format(f8.3,i5,f5.1,2i4,i5.4,2x,a28,': ',a1,2x,a3) + nutc00=nutc + msg00=msg0(1:28) + freq1_00=freq1 + frx=0.001*k0*df+nkhz_center-48.0+1.0 - 0.001*nfcal + fsked=frx - 0.001*ndop00/2.0 - 1.5 + write(12,1120) nutc,fsked,xdt0,nsnr0,trim(msg0) +1120 format(i4.4,f9.3,f7.2,i5,2x,a,i6) + endif + endif + +900 close(13) + close(17) + call flush(6) + idec=-1 + read(cq0(2:2),*) idec + + return +end subroutine q65b diff --git a/map65/libm65/q65b_for_Linux.f90 b/map65/libm65/q65b_for_Linux.f90 index d4e829f7..0e5ae27c 100755..100644 --- a/map65/libm65/q65b_for_Linux.f90 +++ b/map65/libm65/q65b_for_Linux.f90 @@ -1,205 +1,205 @@ -subroutine q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf,ntol,xpol, &
- mycall0,mygrid,hiscall0,hisgrid,mode_q65,f0,fqso,newdat,nagain, &
- max_drift,nhsym,ndop00,idec)
-
-! This routine provides an interface between MAP65 and the Q65 decoder
-! in WSJT-X. All arguments are input data obtained from the MAP65 GUI.
-! Raw Rx data are available as the 96 kHz complex spectrum ca(MAXFFT1)
-! in common/cacb. If xpol is true, we also have cb(MAXFFT1) for the
-! orthogonal polarization. Decoded messages are sent back to the GUI
-! on stdout.
-
-! use wavhdr
- use q65_decode
- use wideband_sync
- use timer_module, only: timer
-
- parameter (MAXFFT1=5376000) !56*96000
- parameter (MAXFFT2=336000) !56*6000 (downsampled by 1/16)
- parameter (NMAX=60*12000)
- parameter (RAD=57.2957795)
-! type(hdr) h !Header for the .wav file
- integer*2 iwave(60*12000)
- complex ca(MAXFFT1),cb(MAXFFT1) !FFTs of raw x,y data
- complex cx(0:MAXFFT2-1),cy(0:MAXFFT2-1),cz(0:MAXFFT2)
- logical xpol,ldecoded
- integer ipk1(1)
- real*8 fcenter,freq0,freq1
- character*12 mycall0,hiscall0
- character*12 mycall,hiscall
- character*6 mygrid,hisgrid
- character*4 grid4
- character*28 msg00
- character*80 line
- character*80 wsjtx_dir
- character*1 cp,cmode*2
- common/cacb/ca,cb
- common/early/nhsym1,nhsym2,ldecoded(32768)
- common/decodes/ndecodes
- data nutc00/-1/,msg00/' '/
- save
-
- if(newdat.eq.1) nutc00=-1
-! open(9,file='wsjtx_dir.txt',status='old')
-! read(9,'(a)') wsjtx_dir !Establish the working directory
-! close(9)
-
- if(mycall0(1:1).ne.' ') mycall=mycall0
- if(hiscall0(1:1).ne.' ') hiscall=hiscall0
- if(hisgrid(1:4).ne.' ') grid4=hisgrid(1:4)
-
-! Find best frequency and ipol from sync_dat, the "orange sync curve".
- df3=96000.0/32768.0
- ifreq=nint((1000.0*f0)/df3)
- ia=nint(ifreq-ntol/df3)
- ib=nint(ifreq+ntol/df3)
- ipk1=maxloc(sync(ia:ib)%ccfmax)
- ipk=ia+ipk1(1)-1
- if(ldecoded(ipk)) go to 900
- snr1=sync(ipk)%ccfmax
- ipol=1
- if(xpol) ipol=sync(ipk)%ipol
-
- nfft1=MAXFFT1
- nfft2=MAXFFT2
- df=96000.0/NFFT1
- if(nfsample.eq.95238) then
- nfft1=5120000
- nfft2=322560
- df=96000.0/nfft1
- endif
- nh=nfft2/2
- f_mouse=1000.0*(fqso+48.0) + mousedf
- f_ipk=ipk*df3
- k0=nint((ipk*df3-1000.0)/df)
- if(nagain.eq.1) k0=nint((f_mouse-1000.0)/df)
-
- if(k0.lt.nh .or. k0.gt.MAXFFT1-nfft2+1) go to 900
- if(snr1.lt.1.5) go to 900 !### Threshold needs work? ###
-
- fac=1.0/nfft2
- cx(0:nfft2-1)=ca(k0:k0+nfft2-1)
- cx=fac*cx
- if(xpol) then
- cy(0:nfft2-1)=cb(k0:k0+nfft2-1)
- cy=fac*cy
- endif
-
-! Here cx and cy (if xpol) are frequency-domain data around the selected
-! QSO frequency, taken from the full-length FFT computed in filbig().
-! Values for fsample, nfft1, nfft2, df, and the downsampled data rate
-! are as follows:
-
-! fSample nfft1 df nfft2 fDownSampled
-! (Hz) (Hz) (Hz)
-!----------------------------------------------------
-! 96000 5376000 0.017857143 336000 6000.000
-! 95238 5120000 0.018601172 322560 5999.994
-
- poldeg=0.
- if(xpol) then
- poldeg=sync(ipk)%pol
- cz(0:MAXFFT2-1)=cos(poldeg/RAD)*cx + sin(poldeg/RAD)*cy
- else
- cz(0:MAXFFT2-1)=cx
- endif
-
- cz(MAXFFT2)=0.
-! Roll off below 500 Hz and above 2500 Hz.
- ja=nint(500.0/df)
- jb=nint(2500.0/df)
- do i=0,ja
- r=0.5*(1.0+cos(i*3.14159/ja))
- cz(ja-i)=r*cz(ja-i)
- cz(jb+i)=r*cz(jb+i)
- enddo
- cz(ja+jb+1:)=0.
-
-!Transform to time domain (real), fsample=12000 Hz
- call four2a(cz,2*nfft2,1,1,-1)
- do i=0,nfft2-1
- j=nfft2-1-i
- iwave(2*i+2)=nint(real(cz(j))) !Note the reversed order!
- iwave(2*i+1)=nint(aimag(cz(j)))
- enddo
- iwave(2*nfft2+1:)=0
-
-! open(30,file='000000_0001.wav',status='unknown',access='stream')
-! h=default_header(12000,NMAX)
-! write(30) h,iwave
-! close(30)
-
- nsubmode=mode_q65-1
- nfa=990 !Tight limits around ipk for the wideband decode
- nfb=1010
- if(nagain.eq.1) then !For nagain=1, use limits of +/- ntol
- nfa=max(100,1000-ntol)
- nfb=min(2500,1000+ntol)
- endif
- nsnr0=-99 !Default snr for no decode
- ndpth=3
-
-! NB: Frequency of ipk is now shifted to 1000 Hz.
- call map65_mmdec(nutc,iwave,nqd,nsubmode,nfa,nfb,1000,ntol, &
- newdat,nagain,max_drift,ndepth,mycall,hiscall0,hisgrid)
-
- MHz=fcenter
- freq0=MHz + 0.001d0*ikhz
-
- if(nsnr0.gt.-99) then
- ldecoded(ipk)=.true.
- nq65df=nint(1000*(0.001*k0*df+nkhz_center-48.0+1.000-1.27046-ikhz))-nfcal
- nq65df=nq65df + nfreq0 - 1000
- npol=nint(poldeg)
- if(nxant.ne.0) then
- npol=npol-45
- if(npol.lt.0) npol=npol+180
- endif
- call txpol(xpol,msg0(1:28),mygrid,npol,nxant,ntxpol,cp)
- ikhz1=ikhz
- ndf=nq65df
- if(ndf.gt.500) ikhz1=ikhz + (nq65df+500)/1000
- if(ndf.lt.-500) ikhz1=ikhz + (nq65df-500)/1000
- ndf=nq65df - 1000*(ikhz1-ikhz)
- if(nqd.eq.1 .and. abs(nq65df-mousedf).lt.ntol) then
- write(line,1020) ikhz1,ndf,npol,nutc,xdt0,nsnr0,msg0(1:28),cq0, &
- ntxpol,cp
-1020 format('!',i3.3,i5,i4,i6.4,f5.1,i5,' : ',a28,a3,i4,1x,a1)
- write(*,1100) trim(line)
-1100 format(a)
- endif
-
-! Write to lu 26, for Messages and Band Map windows
- cmode=': '
- cmode(2:2)=char(ichar('A') + mode_q65-1)
- freq1=freq0 + 0.001d0*(ikhz1-ikhz)
- write(26,1014) freq1,ndf,0,0,0,xdt0,npol,0,nsnr0,nutc,msg0(1:28), &
- ':',cp,cmode ! was 1:22
-1014 format(f8.3,i5,3i3,f5.1,i4,i3,i4,i5.4,4x,a28,1x,2a1,2x,a2) ! was a22
-
-! Suppress writing duplicates (same time, decoded message, and frequency)
-! to map65_rx.log
- if(nutc.ne.nutc00 .or. msg0(1:28).ne.msg00 .or. freq1.ne.freq1_00) then
-! Write to file map65_rx.log:
- ndecodes=ndecodes+1
- write(21,1110) freq1,ndf,xdt0,npol,nsnr0,nutc,msg0(1:28), &
- cmode(2:2),cq0
-1110 format(f8.3,i5,f5.1,2i4,i5.4,2x,a28,': ',a1,2x,a3)
- nutc00=nutc
- msg00=msg0(1:28)
- freq1_00=freq1
- frx=0.001*k0*df+nkhz_center-48.0+1.0 - 0.001*nfcal
- fsked=frx - 0.001*ndop00/2.0 - 1.5
- write(12,1120) nutc,fsked,xdt0,nsnr0,trim(msg0)
-1120 format(i4.4,f9.3,f7.2,i5,2x,a,i6)
- endif
- endif
-
-900 close(13)
- close(17)
- call flush(6)
- idec=-1
- read(cq0(2:2),*) idec
-
- return
-end subroutine q65b
+subroutine q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf,ntol,xpol, & + mycall0,mygrid,hiscall0,hisgrid,mode_q65,f0,fqso,newdat,nagain, & + max_drift,nhsym,ndop00,idec) + +! This routine provides an interface between MAP65 and the Q65 decoder +! in WSJT-X. All arguments are input data obtained from the MAP65 GUI. +! Raw Rx data are available as the 96 kHz complex spectrum ca(MAXFFT1) +! in common/cacb. If xpol is true, we also have cb(MAXFFT1) for the +! orthogonal polarization. Decoded messages are sent back to the GUI +! on stdout. + +! use wavhdr + use q65_decode + use wideband_sync + use timer_module, only: timer + + parameter (MAXFFT1=5376000) !56*96000 + parameter (MAXFFT2=336000) !56*6000 (downsampled by 1/16) + parameter (NMAX=60*12000) + parameter (RAD=57.2957795) +! type(hdr) h !Header for the .wav file + integer*2 iwave(60*12000) + complex ca(MAXFFT1),cb(MAXFFT1) !FFTs of raw x,y data + complex cx(0:MAXFFT2-1),cy(0:MAXFFT2-1),cz(0:MAXFFT2) + logical xpol,ldecoded + integer ipk1(1) + real*8 fcenter,freq0,freq1 + character*12 mycall0,hiscall0 + character*12 mycall,hiscall + character*6 mygrid,hisgrid + character*4 grid4 + character*28 msg00 + character*80 line + character*80 wsjtx_dir + character*1 cp,cmode*2 + common/cacb/ca,cb + common/early/nhsym1,nhsym2,ldecoded(32768) + common/decodes/ndecodes + data nutc00/-1/,msg00/' '/ + save + + if(newdat.eq.1) nutc00=-1 +! open(9,file='wsjtx_dir.txt',status='old') +! read(9,'(a)') wsjtx_dir !Establish the working directory +! close(9) + + if(mycall0(1:1).ne.' ') mycall=mycall0 + if(hiscall0(1:1).ne.' ') hiscall=hiscall0 + if(hisgrid(1:4).ne.' ') grid4=hisgrid(1:4) + +! Find best frequency and ipol from sync_dat, the "orange sync curve". + df3=96000.0/32768.0 + ifreq=nint((1000.0*f0)/df3) + ia=nint(ifreq-ntol/df3) + ib=nint(ifreq+ntol/df3) + ipk1=maxloc(sync(ia:ib)%ccfmax) + ipk=ia+ipk1(1)-1 + if(ldecoded(ipk)) go to 900 + snr1=sync(ipk)%ccfmax + ipol=1 + if(xpol) ipol=sync(ipk)%ipol + + nfft1=MAXFFT1 + nfft2=MAXFFT2 + df=96000.0/NFFT1 + if(nfsample.eq.95238) then + nfft1=5120000 + nfft2=322560 + df=96000.0/nfft1 + endif + nh=nfft2/2 + f_mouse=1000.0*(fqso+48.0) + mousedf + f_ipk=ipk*df3 + k0=nint((ipk*df3-1000.0)/df) + if(nagain.eq.1) k0=nint((f_mouse-1000.0)/df) + + if(k0.lt.nh .or. k0.gt.MAXFFT1-nfft2+1) go to 900 + if(snr1.lt.1.5) go to 900 !### Threshold needs work? ### + + fac=1.0/nfft2 + cx(0:nfft2-1)=ca(k0:k0+nfft2-1) + cx=fac*cx + if(xpol) then + cy(0:nfft2-1)=cb(k0:k0+nfft2-1) + cy=fac*cy + endif + +! Here cx and cy (if xpol) are frequency-domain data around the selected +! QSO frequency, taken from the full-length FFT computed in filbig(). +! Values for fsample, nfft1, nfft2, df, and the downsampled data rate +! are as follows: + +! fSample nfft1 df nfft2 fDownSampled +! (Hz) (Hz) (Hz) +!---------------------------------------------------- +! 96000 5376000 0.017857143 336000 6000.000 +! 95238 5120000 0.018601172 322560 5999.994 + + poldeg=0. + if(xpol) then + poldeg=sync(ipk)%pol + cz(0:MAXFFT2-1)=cos(poldeg/RAD)*cx + sin(poldeg/RAD)*cy + else + cz(0:MAXFFT2-1)=cx + endif + + cz(MAXFFT2)=0. +! Roll off below 500 Hz and above 2500 Hz. + ja=nint(500.0/df) + jb=nint(2500.0/df) + do i=0,ja + r=0.5*(1.0+cos(i*3.14159/ja)) + cz(ja-i)=r*cz(ja-i) + cz(jb+i)=r*cz(jb+i) + enddo + cz(ja+jb+1:)=0. + +!Transform to time domain (real), fsample=12000 Hz + call four2a(cz,2*nfft2,1,1,-1) + do i=0,nfft2-1 + j=nfft2-1-i + iwave(2*i+2)=nint(real(cz(j))) !Note the reversed order! + iwave(2*i+1)=nint(aimag(cz(j))) + enddo + iwave(2*nfft2+1:)=0 + +! open(30,file='000000_0001.wav',status='unknown',access='stream') +! h=default_header(12000,NMAX) +! write(30) h,iwave +! close(30) + + nsubmode=mode_q65-1 + nfa=990 !Tight limits around ipk for the wideband decode + nfb=1010 + if(nagain.eq.1) then !For nagain=1, use limits of +/- ntol + nfa=max(100,1000-ntol) + nfb=min(2500,1000+ntol) + endif + nsnr0=-99 !Default snr for no decode + ndpth=3 + +! NB: Frequency of ipk is now shifted to 1000 Hz. + call map65_mmdec(nutc,iwave,nqd,nsubmode,nfa,nfb,1000,ntol, & + newdat,nagain,max_drift,ndepth,mycall,hiscall0,hisgrid) + + MHz=fcenter + freq0=MHz + 0.001d0*ikhz + + if(nsnr0.gt.-99) then + ldecoded(ipk)=.true. + nq65df=nint(1000*(0.001*k0*df+nkhz_center-48.0+1.000-1.27046-ikhz))-nfcal + nq65df=nq65df + nfreq0 - 1000 + npol=nint(poldeg) + if(nxant.ne.0) then + npol=npol-45 + if(npol.lt.0) npol=npol+180 + endif + call txpol(xpol,msg0(1:28),mygrid,npol,nxant,ntxpol,cp) + ikhz1=ikhz + ndf=nq65df + if(ndf.gt.500) ikhz1=ikhz + (nq65df+500)/1000 + if(ndf.lt.-500) ikhz1=ikhz + (nq65df-500)/1000 + ndf=nq65df - 1000*(ikhz1-ikhz) + if(nqd.eq.1 .and. abs(nq65df-mousedf).lt.ntol) then + write(line,1020) ikhz1,ndf,npol,nutc,xdt0,nsnr0,msg0(1:28),cq0, & + ntxpol,cp +1020 format('!',i3.3,i5,i4,i6.4,f5.1,i5,' : ',a28,a3,i4,1x,a1) + write(*,1100) trim(line) +1100 format(a) + endif + +! Write to lu 26, for Messages and Band Map windows + cmode=': ' + cmode(2:2)=char(ichar('A') + mode_q65-1) + freq1=freq0 + 0.001d0*(ikhz1-ikhz) + write(26,1014) freq1,ndf,0,0,0,xdt0,npol,0,nsnr0,nutc,msg0(1:28), & + ':',cp,cmode ! was 1:22 +1014 format(f8.3,i5,3i3,f5.1,i4,i3,i4,i5.4,4x,a28,1x,2a1,2x,a2) ! was a22 + +! Suppress writing duplicates (same time, decoded message, and frequency) +! to map65_rx.log + if(nutc.ne.nutc00 .or. msg0(1:28).ne.msg00 .or. freq1.ne.freq1_00) then +! Write to file map65_rx.log: + ndecodes=ndecodes+1 + write(21,1110) freq1,ndf,xdt0,npol,nsnr0,nutc,msg0(1:28), & + cmode(2:2),cq0 +1110 format(f8.3,i5,f5.1,2i4,i5.4,2x,a28,': ',a1,2x,a3) + nutc00=nutc + msg00=msg0(1:28) + freq1_00=freq1 + frx=0.001*k0*df+nkhz_center-48.0+1.0 - 0.001*nfcal + fsked=frx - 0.001*ndop00/2.0 - 1.5 + write(12,1120) nutc,fsked,xdt0,nsnr0,trim(msg0) +1120 format(i4.4,f9.3,f7.2,i5,2x,a,i6) + endif + endif + +900 close(13) + close(17) + call flush(6) + idec=-1 + read(cq0(2:2),*) idec + + return +end subroutine q65b diff --git a/map65/libm65/recvpkt.f90 b/map65/libm65/recvpkt.f90 index cea9c9de..88d51cc5 100755..100644 --- a/map65/libm65/recvpkt.f90 +++ b/map65/libm65/recvpkt.f90 @@ -1,73 +1,73 @@ -subroutine recvpkt(nsam,nblock2,userx_no,k,buf4,buf8,buf16)
-
-! Reformat timf2 data from Linrad and stuff data into r*4 array dd().
-
- include 'njunk.f90'
- parameter (NSMAX=60*96000) !Total sample intervals per minute
- parameter (NFFT=32768)
- integer*1 userx_no
- real*4 d4,buf4(*) !(348)
- real*8 d8,buf8(*) !(174)
- complex*16 c16,buf16(*) !(87)
- integer*2 jd(4),kd(2),nblock2
- real*4 xd(4),yd(2)
- real*8 fcenter
- common/datcom/dd(4,5760000),ss(4,322,NFFT),savg(4,NFFT),fcenter,nutc, &
- junk(NJUNK)
- equivalence (kd,d4)
- equivalence (jd,d8,yd)
- equivalence (xd,c16)
-
- if(nblock2.eq.-9999) nblock2=-9998 !Silence a compiler warning
- if(nsam.eq.-1) then
-! Move data from the UDP packet buffer into array dd().
- if(userx_no.eq.-1) then
- do i=1,174 !One RF channel, r*4 data
- k=k+1
- d8=buf8(i)
- dd(1,k)=yd(1)
- dd(2,k)=yd(2)
- enddo
- else if(userx_no.eq.1) then
- do i=1,348 !One RF channel, i*2 data
- k=k+1
- d4=buf4(i)
- dd(1,k)=kd(1)
- dd(2,k)=kd(2)
- enddo
- else if(userx_no.eq.-2) then
- do i=1,87 !Two RF channels, r*4 data
- k=k+1
- c16=buf16(i)
- dd(1,k)=xd(1)
- dd(2,k)=xd(2)
- dd(3,k)=xd(3)
- dd(4,k)=xd(4)
- enddo
- else if(userx_no.eq.2) then
- do i=1,174 !Two RF channels, i*2 data
- k=k+1
- d8=buf8(i)
- dd(1,k)=jd(1)
- dd(2,k)=jd(2)
- dd(3,k)=jd(3)
- dd(4,k)=jd(4)
- enddo
- endif
- else
- if(userx_no.eq.1) then
- do i=1,nsam !One RF channel, r*4 data
- k=k+1
- d4=buf4(i)
- dd(1,k)=kd(1)
- dd(2,k)=kd(2)
-
- k=k+1
- dd(1,k)=kd(1)
- dd(2,k)=kd(2)
- enddo
- endif
- endif
-
- return
-end subroutine recvpkt
+subroutine recvpkt(nsam,nblock2,userx_no,k,buf4,buf8,buf16) + +! Reformat timf2 data from Linrad and stuff data into r*4 array dd(). + + include 'njunk.f90' + parameter (NSMAX=60*96000) !Total sample intervals per minute + parameter (NFFT=32768) + integer*1 userx_no + real*4 d4,buf4(*) !(348) + real*8 d8,buf8(*) !(174) + complex*16 c16,buf16(*) !(87) + integer*2 jd(4),kd(2),nblock2 + real*4 xd(4),yd(2) + real*8 fcenter + common/datcom/dd(4,5760000),ss(4,322,NFFT),savg(4,NFFT),fcenter,nutc, & + junk(NJUNK) + equivalence (kd,d4) + equivalence (jd,d8,yd) + equivalence (xd,c16) + + if(nblock2.eq.-9999) nblock2=-9998 !Silence a compiler warning + if(nsam.eq.-1) then +! Move data from the UDP packet buffer into array dd(). + if(userx_no.eq.-1) then + do i=1,174 !One RF channel, r*4 data + k=k+1 + d8=buf8(i) + dd(1,k)=yd(1) + dd(2,k)=yd(2) + enddo + else if(userx_no.eq.1) then + do i=1,348 !One RF channel, i*2 data + k=k+1 + d4=buf4(i) + dd(1,k)=kd(1) + dd(2,k)=kd(2) + enddo + else if(userx_no.eq.-2) then + do i=1,87 !Two RF channels, r*4 data + k=k+1 + c16=buf16(i) + dd(1,k)=xd(1) + dd(2,k)=xd(2) + dd(3,k)=xd(3) + dd(4,k)=xd(4) + enddo + else if(userx_no.eq.2) then + do i=1,174 !Two RF channels, i*2 data + k=k+1 + d8=buf8(i) + dd(1,k)=jd(1) + dd(2,k)=jd(2) + dd(3,k)=jd(3) + dd(4,k)=jd(4) + enddo + endif + else + if(userx_no.eq.1) then + do i=1,nsam !One RF channel, r*4 data + k=k+1 + d4=buf4(i) + dd(1,k)=kd(1) + dd(2,k)=kd(2) + + k=k+1 + dd(1,k)=kd(1) + dd(2,k)=kd(2) + enddo + endif + endif + + return +end subroutine recvpkt diff --git a/map65/libm65/rfile3a.f90 b/map65/libm65/rfile3a.f90 index db12e4df..7e226651 100755..100644 --- a/map65/libm65/rfile3a.f90 +++ b/map65/libm65/rfile3a.f90 @@ -1,14 +1,14 @@ -subroutine rfile3a(infile,ibuf,n,fcenter,ierr)
-
- character*(*) infile
- integer*8 ibuf(n)
- real*8 fcenter
-
- open(10,file=infile,access='stream',status='old',err=998)
- read(10,end=998) (ibuf(i),i=1,n/8),fcenter
- ierr=0
- go to 999
-998 ierr=1002
-999 close(10)
- return
-end subroutine rfile3a
+subroutine rfile3a(infile,ibuf,n,fcenter,ierr) + + character*(*) infile + integer*8 ibuf(n) + real*8 fcenter + + open(10,file=infile,access='stream',status='old',err=998) + read(10,end=998) (ibuf(i),i=1,n/8),fcenter + ierr=0 + go to 999 +998 ierr=1002 +999 close(10) + return +end subroutine rfile3a diff --git a/map65/libm65/rs.h b/map65/libm65/rs.h index 6f153146..06cbe344 100755..100644 --- a/map65/libm65/rs.h +++ b/map65/libm65/rs.h @@ -1,35 +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[];
+/* 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/map65/libm65/rs2.h b/map65/libm65/rs2.h index ab65fb01..c2b807d1 100755..100644 --- a/map65/libm65/rs2.h +++ b/map65/libm65/rs2.h @@ -1,16 +1,16 @@ -/* 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, 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, int calc_syn);
-void *init_rs_int(int symsize,int gfpoly,int fcr,
- int prim,int nroots,int pad);
-void free_rs_int(void *rs);
-
-/* Tables to map from conventional->dual (Taltab) and
- * dual->conventional (Tal1tab) bases
- */
-extern unsigned char Taltab[],Tal1tab[];
+/* 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, 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, int calc_syn); +void *init_rs_int(int symsize,int gfpoly,int fcr, + int prim,int nroots,int pad); +void free_rs_int(void *rs); + +/* Tables to map from conventional->dual (Taltab) and + * dual->conventional (Tal1tab) bases + */ +extern unsigned char Taltab[],Tal1tab[]; diff --git a/map65/libm65/s3avg.f90 b/map65/libm65/s3avg.f90 index f8f68ac5..9d76637c 100755..100644 --- a/map65/libm65/s3avg.f90 +++ b/map65/libm65/s3avg.f90 @@ -1,60 +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
+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/map65/libm65/sec_midn.f90 b/map65/libm65/sec_midn.f90 index db6328e8..0bbe62c2 100755..100644 --- a/map65/libm65/sec_midn.f90 +++ b/map65/libm65/sec_midn.f90 @@ -1,11 +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
+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/map65/libm65/set.f90 b/map65/libm65/set.f90 index 8b2e5760..ff767988 100755..100644 --- a/map65/libm65/set.f90 +++ b/map65/libm65/set.f90 @@ -1,31 +1,31 @@ -subroutine set(a,y,n)
- real y(n)
- do i=1,n
- y(i)=a
- enddo
- return
-end subroutine set
-
-subroutine move(x,y,n)
- real x(n),y(n)
- do i=1,n
- y(i)=x(i)
- enddo
- return
-end subroutine move
-
-subroutine zero(x,n)
- real x(n)
- do i=1,n
- x(i)=0.0
- enddo
- return
-end subroutine zero
-
-subroutine add(a,b,c,n)
- real a(n),b(n),c(n)
- do i=1,n
- c(i)=a(i)+b(i)
- enddo
- return
-end subroutine add
+subroutine set(a,y,n) + real y(n) + do i=1,n + y(i)=a + enddo + return +end subroutine set + +subroutine move(x,y,n) + real x(n),y(n) + do i=1,n + y(i)=x(i) + enddo + return +end subroutine move + +subroutine zero(x,n) + real x(n) + do i=1,n + x(i)=0.0 + enddo + return +end subroutine zero + +subroutine add(a,b,c,n) + real a(n),b(n),c(n) + do i=1,n + c(i)=a(i)+b(i) + enddo + return +end subroutine add diff --git a/map65/libm65/setup65.f90 b/map65/libm65/setup65.f90 index e3a5fdd6..b1a867d1 100755..100644 --- a/map65/libm65/setup65.f90 +++ b/map65/libm65/setup65.f90 @@ -1,96 +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
- go to 22
-20 mref(k,2)=m+n
-22 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
- go to 122
-120 mref2(k,2)=m+n
-122 enddo
-
- return
-end subroutine setup65
+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 + go to 22 +20 mref(k,2)=m+n +22 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 + go to 122 +120 mref2(k,2)=m+n +122 enddo + + return +end subroutine setup65 diff --git a/map65/libm65/shell.f90 b/map65/libm65/shell.f90 index 1e9b4488..d7365bfc 100755..100644 --- a/map65/libm65/shell.f90 +++ b/map65/libm65/shell.f90 @@ -1,27 +1,27 @@ -subroutine shell(n,a)
- integer n
- real a(n)
- integer i,j,inc
- real v
-
- inc=1
-1 inc=3*inc+1
- if(inc.le.n) go to 1
-2 inc=inc/3
-
- do i=inc+1,n
- v=a(i)
- j=i
-3 if(a(j-inc).gt.v) then
- a(j)=a(j-inc)
- j=j-inc
- if(j.le.inc) go to 4
- go to 3
- endif
-4 a(j)=v
- enddo
-
- if(inc.gt.1) go to 2
-
- return
-end subroutine shell
+subroutine shell(n,a) + integer n + real a(n) + integer i,j,inc + real v + + inc=1 +1 inc=3*inc+1 + if(inc.le.n) go to 1 +2 inc=inc/3 + + do i=inc+1,n + v=a(i) + j=i +3 if(a(j-inc).gt.v) then + a(j)=a(j-inc) + j=j-inc + if(j.le.inc) go to 4 + go to 3 + endif +4 a(j)=v + enddo + + if(inc.gt.1) go to 2 + + return +end subroutine shell diff --git a/map65/libm65/sleep.h b/map65/libm65/sleep.h index c111cef0..df60bc92 100755..100644 --- a/map65/libm65/sleep.h +++ b/map65/libm65/sleep.h @@ -1,32 +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 */
+/* + * 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/map65/libm65/sleep_msec.f90 b/map65/libm65/sleep_msec.f90 index 21ab6182..1a8dbe4f 100755..100644 --- a/map65/libm65/sleep_msec.f90 +++ b/map65/libm65/sleep_msec.f90 @@ -1,4 +1,4 @@ -subroutine sleep_msec(n)
- call usleep(n*1000)
- return
-end subroutine sleep_msec
+subroutine sleep_msec(n) + call usleep(n*1000) + return +end subroutine sleep_msec diff --git a/map65/libm65/smo.f90 b/map65/libm65/smo.f90 index 87994310..c42de7c6 100755..100644 --- a/map65/libm65/smo.f90 +++ b/map65/libm65/smo.f90 @@ -1,19 +1,19 @@ -subroutine smo(x,npts,y,nadd)
-
- real x(npts)
- real y(npts)
-
- nh=nadd/2
- do i=1+nh,npts-nh
- sum=0.
- do j=-nh,nh
- sum=sum + x(i+j)
- enddo
- y(i)=sum
- enddo
- x=y
- x(:nh)=0.
- x(npts-nh+1:)=0.
-
- return
-end subroutine smo
+subroutine smo(x,npts,y,nadd) + + real x(npts) + real y(npts) + + nh=nadd/2 + do i=1+nh,npts-nh + sum=0. + do j=-nh,nh + sum=sum + x(i+j) + enddo + y(i)=sum + enddo + x=y + x(:nh)=0. + x(npts-nh+1:)=0. + + return +end subroutine smo diff --git a/map65/libm65/sort.f90 b/map65/libm65/sort.f90 index eadf6939..8a05da28 100755..100644 --- a/map65/libm65/sort.f90 +++ b/map65/libm65/sort.f90 @@ -1,6 +1,6 @@ -subroutine sort(n,arr)
-
- call ssort(arr,tmp,n,1)
-
- return
-end subroutine sort
+subroutine sort(n,arr) + + call ssort(arr,tmp,n,1) + + return +end subroutine sort diff --git a/map65/libm65/ssort.f b/map65/libm65/ssort.f index cea0c2d4..fa508ace 100755..100644 --- a/map65/libm65/ssort.f +++ b/map65/libm65/ssort.f @@ -1,287 +1,287 @@ - subroutine ssort (x,y,n,kflag)
-c***purpose sort an array and optionally make the same interchanges in
-c an auxiliary array. the array may be sorted in increasing
-c or decreasing order. a slightly modified quicksort
-c algorithm is used.
-c
-c ssort sorts array x and optionally makes the same interchanges in
-c array y. the array x may be sorted in increasing order or
-c decreasing order. a slightly modified quicksort algorithm is used.
-c
-c description of parameters
-c x - array of values to be sorted
-c y - array to be (optionally) carried along
-c n - number of values in array x to be sorted
-c kflag - control parameter
-c = 2 means sort x in increasing order and carry y along.
-c = 1 means sort x in increasing order (ignoring y)
-c = -1 means sort x in decreasing order (ignoring y)
-c = -2 means sort x in decreasing order and carry y along.
-
- integer kflag, n
-! real x(n), y(n)
-! real r, t, tt, tty, ty
- integer x(n), y(n)
- integer r, 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
-c
- 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
-c
-c alter array x to get decreasing order if needed
-c
- if (kflag .le. -1) then
- do 10 i=1,nn
- x(i) = -x(i)
- 10 continue
- endif
-c
- if (kk .eq. 2) go to 100
-c
-c sort x only
-c
- m = 1
- i = 1
- j = nn
- r = 0.375e0
-c
- 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
-c
- 30 k = i
-c
-c select a central element of the array and save it in location t
-c
- ij = i + int((j-i)*r)
- t = x(ij)
-c
-c if first element of array is greater than t, interchange with t
-c
- if (x(i) .gt. t) then
- x(ij) = x(i)
- x(i) = t
- t = x(ij)
- endif
- l = j
-c
-c if last element of array is less than than t, interchange with t
-c
- if (x(j) .lt. t) then
- x(ij) = x(j)
- x(j) = t
- t = x(ij)
-c
-c if first element of array is greater than t, interchange with t
-c
- if (x(i) .gt. t) then
- x(ij) = x(i)
- x(i) = t
- t = x(ij)
- endif
- endif
-c
-c find an element in the second half of the array which is smaller
-c than t
-c
- 40 l = l-1
- if (x(l) .gt. t) go to 40
-c
-c find an element in the first half of the array which is greater
-c than t
-c
- 50 k = k+1
- if (x(k) .lt. t) go to 50
-c
-c interchange these elements
-c
- if (k .le. l) then
- tt = x(l)
- x(l) = x(k)
- x(k) = tt
- go to 40
- endif
-c
-c save upper and lower subscripts of the array yet to be sorted
-c
- 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
-c
-c begin again on another portion of the unsorted array
-c
- 60 m = m-1
- if (m .eq. 0) go to 190
- i = il(m)
- j = iu(m)
-c
- 70 if (j-i .ge. 1) go to 30
- if (i .eq. 1) go to 20
- i = i-1
-c
- 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
-c
- 90 x(k+1) = x(k)
- k = k-1
- if (t .lt. x(k)) go to 90
- x(k+1) = t
- go to 80
-c
-c sort x and carry y along
-c
- 100 m = 1
- i = 1
- j = nn
- r = 0.375e0
-c
- 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
-c
- 120 k = i
-c
-c select a central element of the array and save it in location t
-c
- ij = i + int((j-i)*r)
- t = x(ij)
- ty = y(ij)
-c
-c if first element of array is greater than t, interchange with t
-c
- 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
-c
-c if last element of array is less than t, interchange with t
-c
- 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)
-c
-c if first element of array is greater than t, interchange with t
-c
- 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
-c
-c find an element in the second half of the array which is smaller
-c than t
-c
- 130 l = l-1
- if (x(l) .gt. t) go to 130
-c
-c find an element in the first half of the array which is greater
-c than t
-c
- 140 k = k+1
- if (x(k) .lt. t) go to 140
-c
-c interchange these elements
-c
- 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
-c
-c save upper and lower subscripts of the array yet to be sorted
-c
- 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
-c
-c begin again on another portion of the unsorted array
-c
- 150 m = m-1
- if (m .eq. 0) go to 190
- i = il(m)
- j = iu(m)
-c
- 160 if (j-i .ge. 1) go to 120
- if (i .eq. 1) go to 110
- i = i-1
-c
- 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
-c
- 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
-c
-c clean up
-c
- 190 if (kflag .le. -1) then
- do 200 i=1,nn
- x(i) = -x(i)
- 200 continue
- endif
- return
- end
+ subroutine ssort (x,y,n,kflag) +c***purpose sort an array and optionally make the same interchanges in +c an auxiliary array. the array may be sorted in increasing +c or decreasing order. a slightly modified quicksort +c algorithm is used. +c +c ssort sorts array x and optionally makes the same interchanges in +c array y. the array x may be sorted in increasing order or +c decreasing order. a slightly modified quicksort algorithm is used. +c +c description of parameters +c x - array of values to be sorted +c y - array to be (optionally) carried along +c n - number of values in array x to be sorted +c kflag - control parameter +c = 2 means sort x in increasing order and carry y along. +c = 1 means sort x in increasing order (ignoring y) +c = -1 means sort x in decreasing order (ignoring y) +c = -2 means sort x in decreasing order and carry y along. + + integer kflag, n +! real x(n), y(n) +! real r, t, tt, tty, ty + integer x(n), y(n) + integer r, 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 +c + 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 +c +c alter array x to get decreasing order if needed +c + if (kflag .le. -1) then + do 10 i=1,nn + x(i) = -x(i) + 10 continue + endif +c + if (kk .eq. 2) go to 100 +c +c sort x only +c + m = 1 + i = 1 + j = nn + r = 0.375e0 +c + 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 +c + 30 k = i +c +c select a central element of the array and save it in location t +c + ij = i + int((j-i)*r) + t = x(ij) +c +c if first element of array is greater than t, interchange with t +c + if (x(i) .gt. t) then + x(ij) = x(i) + x(i) = t + t = x(ij) + endif + l = j +c +c if last element of array is less than than t, interchange with t +c + if (x(j) .lt. t) then + x(ij) = x(j) + x(j) = t + t = x(ij) +c +c if first element of array is greater than t, interchange with t +c + if (x(i) .gt. t) then + x(ij) = x(i) + x(i) = t + t = x(ij) + endif + endif +c +c find an element in the second half of the array which is smaller +c than t +c + 40 l = l-1 + if (x(l) .gt. t) go to 40 +c +c find an element in the first half of the array which is greater +c than t +c + 50 k = k+1 + if (x(k) .lt. t) go to 50 +c +c interchange these elements +c + if (k .le. l) then + tt = x(l) + x(l) = x(k) + x(k) = tt + go to 40 + endif +c +c save upper and lower subscripts of the array yet to be sorted +c + 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 +c +c begin again on another portion of the unsorted array +c + 60 m = m-1 + if (m .eq. 0) go to 190 + i = il(m) + j = iu(m) +c + 70 if (j-i .ge. 1) go to 30 + if (i .eq. 1) go to 20 + i = i-1 +c + 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 +c + 90 x(k+1) = x(k) + k = k-1 + if (t .lt. x(k)) go to 90 + x(k+1) = t + go to 80 +c +c sort x and carry y along +c + 100 m = 1 + i = 1 + j = nn + r = 0.375e0 +c + 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 +c + 120 k = i +c +c select a central element of the array and save it in location t +c + ij = i + int((j-i)*r) + t = x(ij) + ty = y(ij) +c +c if first element of array is greater than t, interchange with t +c + 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 +c +c if last element of array is less than t, interchange with t +c + 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) +c +c if first element of array is greater than t, interchange with t +c + 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 +c +c find an element in the second half of the array which is smaller +c than t +c + 130 l = l-1 + if (x(l) .gt. t) go to 130 +c +c find an element in the first half of the array which is greater +c than t +c + 140 k = k+1 + if (x(k) .lt. t) go to 140 +c +c interchange these elements +c + 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 +c +c save upper and lower subscripts of the array yet to be sorted +c + 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 +c +c begin again on another portion of the unsorted array +c + 150 m = m-1 + if (m .eq. 0) go to 190 + i = il(m) + j = iu(m) +c + 160 if (j-i .ge. 1) go to 120 + if (i .eq. 1) go to 110 + i = i-1 +c + 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 +c + 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 +c +c clean up +c + 190 if (kflag .le. -1) then + do 200 i=1,nn + x(i) = -x(i) + 200 continue + endif + return + end diff --git a/map65/libm65/sun.f90 b/map65/libm65/sun.f90 index e74ac0b8..ec011b66 100755..100644 --- a/map65/libm65/sun.f90 +++ b/map65/libm65/sun.f90 @@ -1,88 +1,88 @@ -subroutine sun(y,m,DD,UT,lon,lat,RA,Dec,LST,Az,El,mjd,day)
-
- implicit none
-
- integer y !Year
- integer m !Month
- integer DD !Day
- integer mjd !Modified Julian Date
- real UT !UTC in hours
- real RA,Dec !RA and Dec of sun
-
-! NB: Double caps here are single caps in the writeup.
-
-! Orbital elements of the Sun (also N=0, i=0, a=1):
- real w !Argument of perihelion
- real e !Eccentricity
- real MM !Mean anomaly
- real Ls !Mean longitude
-
-! Other standard variables:
- real v !True anomaly
- real EE !Eccentric anomaly
- real ecl !Obliquity of the ecliptic
- real d !Ephemeris time argument in days
- real r !Distance to sun, AU
- real xv,yv !x and y coords in ecliptic
- real lonsun !Ecliptic long and lat of sun
-! Ecliptic coords of sun (geocentric)
- real xs,ys
-! Equatorial coords of sun (geocentric)
- real xe,ye,ze
- real lon,lat
- real GMST0,LST,HA
- real xx,yy,zz
- real xhor,yhor,zhor
- real Az,El
-
- real day
- real rad
- data rad/57.2957795/
-
-! Time in days, with Jan 0, 2000 equal to 0.0:
- d=367*y - 7*(y+(m+9)/12)/4 + 275*m/9 + DD - 730530 + UT/24.0
- mjd=d + 51543
- ecl = 23.4393 - 3.563e-7 * d
-
-! Compute updated orbital elements for Sun:
- w = 282.9404 + 4.70935e-5 * d
- e = 0.016709 - 1.151e-9 * d
- MM = mod(356.0470d0 + 0.9856002585d0 * d + 360000.d0,360.d0)
- Ls = mod(w+MM+720.0,360.0)
-
- EE = MM + e*rad*sin(MM/rad) * (1.0 + e*cos(M/rad))
- EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.0 - e*cos(EE/rad))
-
- xv = cos(EE/rad) - e
- yv = sqrt(1.0-e*e) * sin(EE/rad)
- v = rad*atan2(yv,xv)
- r = sqrt(xv*xv + yv*yv)
- lonsun = mod(v + w + 720.0,360.0)
-! Ecliptic coordinates of sun (rectangular):
- xs = r * cos(lonsun/rad)
- ys = r * sin(lonsun/rad)
-
-! Equatorial coordinates of sun (rectangular):
- xe = xs
- ye = ys * cos(ecl/rad)
- ze = ys * sin(ecl/rad)
-
-! RA and Dec in degrees:
- RA = rad*atan2(ye,xe)
- Dec = rad*atan2(ze,sqrt(xe*xe + ye*ye))
-
- GMST0 = (Ls + 180.0)/15.0
- LST = mod(GMST0+UT+lon/15.0+48.0,24.0) !LST in hours
- HA = 15.0*LST - RA !HA in degrees
- xx = cos(HA/rad)*cos(Dec/rad)
- yy = sin(HA/rad)*cos(Dec/rad)
- zz = sin(Dec/rad)
- xhor = xx*sin(lat/rad) - zz*cos(lat/rad)
- yhor = yy
- zhor = xx*cos(lat/rad) + zz*sin(lat/rad)
- Az = mod(rad*atan2(yhor,xhor) + 180.0 + 360.0,360.0)
- El = rad*asin(zhor)
- day=d-1.5
-
- return
-end subroutine sun
+subroutine sun(y,m,DD,UT,lon,lat,RA,Dec,LST,Az,El,mjd,day) + + implicit none + + integer y !Year + integer m !Month + integer DD !Day + integer mjd !Modified Julian Date + real UT !UTC in hours + real RA,Dec !RA and Dec of sun + +! NB: Double caps here are single caps in the writeup. + +! Orbital elements of the Sun (also N=0, i=0, a=1): + real w !Argument of perihelion + real e !Eccentricity + real MM !Mean anomaly + real Ls !Mean longitude + +! Other standard variables: + real v !True anomaly + real EE !Eccentric anomaly + real ecl !Obliquity of the ecliptic + real d !Ephemeris time argument in days + real r !Distance to sun, AU + real xv,yv !x and y coords in ecliptic + real lonsun !Ecliptic long and lat of sun +! Ecliptic coords of sun (geocentric) + real xs,ys +! Equatorial coords of sun (geocentric) + real xe,ye,ze + real lon,lat + real GMST0,LST,HA + real xx,yy,zz + real xhor,yhor,zhor + real Az,El + + real day + real rad + data rad/57.2957795/ + +! Time in days, with Jan 0, 2000 equal to 0.0: + d=367*y - 7*(y+(m+9)/12)/4 + 275*m/9 + DD - 730530 + UT/24.0 + mjd=d + 51543 + ecl = 23.4393 - 3.563e-7 * d + +! Compute updated orbital elements for Sun: + w = 282.9404 + 4.70935e-5 * d + e = 0.016709 - 1.151e-9 * d + MM = mod(356.0470d0 + 0.9856002585d0 * d + 360000.d0,360.d0) + Ls = mod(w+MM+720.0,360.0) + + EE = MM + e*rad*sin(MM/rad) * (1.0 + e*cos(M/rad)) + EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.0 - e*cos(EE/rad)) + + xv = cos(EE/rad) - e + yv = sqrt(1.0-e*e) * sin(EE/rad) + v = rad*atan2(yv,xv) + r = sqrt(xv*xv + yv*yv) + lonsun = mod(v + w + 720.0,360.0) +! Ecliptic coordinates of sun (rectangular): + xs = r * cos(lonsun/rad) + ys = r * sin(lonsun/rad) + +! Equatorial coordinates of sun (rectangular): + xe = xs + ye = ys * cos(ecl/rad) + ze = ys * sin(ecl/rad) + +! RA and Dec in degrees: + RA = rad*atan2(ye,xe) + Dec = rad*atan2(ze,sqrt(xe*xe + ye*ye)) + + GMST0 = (Ls + 180.0)/15.0 + LST = mod(GMST0+UT+lon/15.0+48.0,24.0) !LST in hours + HA = 15.0*LST - RA !HA in degrees + xx = cos(HA/rad)*cos(Dec/rad) + yy = sin(HA/rad)*cos(Dec/rad) + zz = sin(Dec/rad) + xhor = xx*sin(lat/rad) - zz*cos(lat/rad) + yhor = yy + zhor = xx*cos(lat/rad) + zz*sin(lat/rad) + Az = mod(rad*atan2(yhor,xhor) + 180.0 + 360.0,360.0) + El = rad*asin(zhor) + day=d-1.5 + + return +end subroutine sun diff --git a/map65/libm65/symspec.f90 b/map65/libm65/symspec.f90 index cae89b70..e4160cfd 100755..100644 --- a/map65/libm65/symspec.f90 +++ b/map65/libm65/symspec.f90 @@ -1,224 +1,224 @@ -subroutine symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, &
- fgreen,iqadjust,iqapply,gainx,gainy,phasex,phasey,rejectx,rejecty, &
- pxdb,pydb,ssz5a,nkhz,ihsym,nzap,slimit,lstrong)
-
-! k pointer to the most recent new data
-! nxpol 0/1 to indicate single- or dual-polarization
-! ndiskdat 0/1 to indicate if data from disk
-! nb 0/1 status of noise blanker
-! idphi Phase correction for Y channel, degrees
-! nfsample sample rate (Hz)
-! fgreen Frequency of green marker in I/Q calibrate mode (-48.0 to +48.0 kHz)
-! iqadjust 0/1 to indicate whether IQ adjustment is active
-! iqapply 0/1 to indicate whether to apply I/Q calibration
-! pxdb power in x channel (0-60 dB)
-! pydb power in y channel (0-60 dB)
-! ssz5a polarized spectrum, for waterfall display
-! nkhz integer kHz portion of center frequency, e.g., 125 for 144.125
-! ihsym index number of this half-symbol (1-322)
-! nzap number of samples zero'ed by noise blanker
-
- include 'njunk.f90'
- parameter (NSMAX=60*96000) !Total sample intervals per minute
- parameter (NFFT=32768) !Length of FFTs
- real*8 ts,hsym
- real*8 fcenter
- common/datcom/dd(4,5760000),ss(4,322,NFFT),savg(4,NFFT),fcenter,nutc, &
- junk(NJUNK)
- real*4 ssz5a(NFFT),w(NFFT),w2a(NFFT),w2b(NFFT)
- complex z,zfac
- complex zsumx,zsumy
- complex cx(NFFT),cy(NFFT)
- complex cx00(NFFT),cy00(NFFT)
- complex cx0(0:1023),cx1(0:1023)
- complex cy0(0:1023),cy1(0:1023)
- logical*1 lstrong(0:1023)
- data rms/999.0/,k0/99999999/,nadjx/0/,nadjy/0/
- save
-
- nfast=1
- if(k.gt.5751000) go to 999
- if(k.lt.NFFT) then
- ihsym=0
- go to 999 !Wait for enough samples to start
- endif
- if(k0.eq.99999999) then
- pi=4.0*atan(1.0)
- w2a=0.
- w2b=0.
- do i=1,NFFT
- w(i)=(sin(i*pi/NFFT))**2 !Window for nfast=1
- if(i.lt.17833) w2a(i)=(sin(i*pi/17832.925))**2 !Window a for nfast=2
- j=i-8916
- if(j.gt.0 .and. j.lt.17833) w2b(i)=(sin(j*pi/17832.925))**2 ! b
- enddo
- w2a=sqrt(2.0)*w2a
- w2b=sqrt(2.0)*w2b
- endif
-
- hsym=2048.d0*96000.d0/11025.d0 !Samples per JT65 half-symbol
- if(nfsample.eq.95238) hsym=2048.d0*95238.1d0/11025.d0
-
- if(k.lt.k0) then
- ts=1.d0 - hsym
- savg=0.
- ihsym=0
- k1=0
- if(ndiskdat.eq.0) dd(1:4,k+1:5760000)=0. !### Should not be needed ??? ###
- endif
- k0=k
-
- nzap=0
- sigmas=1.5*(10.0**(0.01*nbslider)) + 0.7
- peaklimit=sigmas*max(10.0,rms)
- faclim=3.0
- px=0.
- py=0.
-
- iqapply0=0
- iqadjust0=0
- if(iqadjust.ne.0) iqapply0=0
- nwindow=2
-! nwindow=0 !### No windowing ###
- nfft2=1024
- kstep=nfft2
- if(nwindow.ne.0) kstep=nfft2/2
- nblks=(k-k1)/kstep
- do nblk=1,nblks
- j=k1+1
- do i=0,nfft2-1
- cx0(i)=cmplx(dd(1,j+i),dd(2,j+i))
- if(nxpol.ne.0) cy0(i)=cmplx(dd(3,j+i),dd(4,j+i))
- enddo
- call timf2(k,nxpol,nfft2,nwindow,nb,peaklimit,iqadjust0,iqapply0, &
- faclim,cx0,cy0,gainx,gainy,phasex,phasey,cx1,cy1,slimit,lstrong, &
- px,py,nzap)
-
- do i=0,kstep-1
- dd(1,j+i)=real(cx1(i))
- dd(2,j+i)=aimag(cx1(i))
- if(nxpol.ne.0) then
- dd(3,j+i)=real(cy1(i))
- dd(4,j+i)=aimag(cy1(i))
- endif
- enddo
- k1=k1+kstep
- enddo
-
- npts=NFFT !Samples used in each half-symbol FFT
-
- ts=ts+hsym
- ja=ts !Index of first sample
- jb=ja+npts-1 !Last sample
-
- i=0
- fac=0.0002
- dphi=idphi/57.2957795
- zfac=fac*cmplx(cos(dphi),sin(dphi))
- do j=ja,jb !Copy data into cx, cy
- x1=dd(1,j)
- x2=dd(2,j)
- if(nxpol.ne.0) then
- x3=dd(3,j)
- x4=dd(4,j)
- else
- x3=0.
- x4=0.
- endif
- i=i+1
- cx(i)=fac*cmplx(x1,x2)
- cy(i)=zfac*cmplx(x3,x4) !NB: cy includes dphi correction
- enddo
-
- if(nzap/178.lt.50 .and. (ndiskdat.eq.0 .or. ihsym.lt.280)) then
- nsum=nblks*kstep - nzap
- if(nsum.le.0) nsum=1
- rmsx=sqrt(0.5*px/nsum)
- rmsy=sqrt(0.5*py/nsum)
- rms=rmsx
- if(nxpol.ne.0) rms=sqrt((px+py)/(4.0*nsum))
- endif
- pxdb=0.
- pydb=0.
- if(rmsx.gt.1.0) pxdb=20.0*log10(rmsx)
- if(rmsy.gt.1.0) pydb=20.0*log10(rmsy)
- if(pxdb.gt.60.0) pxdb=60.0
- if(pydb.gt.60.0) pydb=60.0
-
- cx00=cx
- if(nxpol.ne.0) cy00=cy
-
- do mm=1,nfast
- ihsym=ihsym+1
- if(nfast.eq.1) then
- cx=w*cx00 !Apply window for 2nd forward FFT
- if(nxpol.ne.0) cy=w*cy00
- else
- if(mm.eq.1) then
- cx=w2a*cx00
- if(nxpol.ne.0) cy=w2a*cy00
- else
- cx=w2b*cx00
- if(nxpol.ne.0) cy=w2b*cy00
- endif
- endif
-
- call four2a(cx,NFFT,1,1,1) !Second forward FFT (X)
- if(iqadjust.eq.0) nadjx=0
- if(iqadjust.ne.0 .and. nadjx.lt.50) call iqcal(nadjx,cx,NFFT, &
- gainx,phasex,zsumx,ipkx,rejectx0)
- if(iqapply.ne.0) call iqfix(cx,NFFT,gainx,phasex)
-
- if(nxpol.ne.0) then
- call four2a(cy,NFFT,1,1,1) !Second forward FFT (Y)
- if(iqadjust.eq.0) nadjy=0
- if(iqadjust.ne.0 .and. nadjy.lt.50) call iqcal(nadjy,cy,NFFT, &
- gainy,phasey,zsumy,ipky,rejecty)
- if(iqapply.ne.0) call iqfix(cy,NFFT,gainy,phasey)
- endif
-
- n=min(322,ihsym)
- do i=1,NFFT
- sx=real(cx(i))**2 + aimag(cx(i))**2
- ss(1,n,i)=sx ! Pol = 0
- savg(1,i)=savg(1,i) + sx
-
- if(nxpol.ne.0) then
- z=cx(i) + cy(i)
- s45=0.5*(real(z)**2 + aimag(z)**2)
- ss(2,n,i)=s45 ! Pol = 45
- savg(2,i)=savg(2,i) + s45
-
- sy=real(cy(i))**2 + aimag(cy(i))**2
- ss(3,n,i)=sy ! Pol = 90
- savg(3,i)=savg(3,i) + sy
-
- z=cx(i) - cy(i)
- s135=0.5*(real(z)**2 + aimag(z)**2)
- ss(4,n,i)=s135 ! Pol = 135
- savg(4,i)=savg(4,i) + s135
-
- z=cx(i)*conjg(cy(i))
- q=sx - sy
- u=2.0*real(z)
- ssz5a(i)=0.707*sqrt(q*q + u*u) !Spectrum of linear polarization
-! Leif's formula:
-! ssz5a(i)=0.5*(sx+sy) + (real(z)**2 + aimag(z)**2 - sx*sy)/(sx+sy)
- else
- ssz5a(i)=sx
- endif
- enddo
- enddo
-
- if(ihsym.eq.278) then
- if(iqadjust.ne.0 .and. ipkx.ne.0 .and. ipky.ne.0) then
- rejectx=10.0*log10(savg(1,1+nfft-ipkx)/savg(1,1+ipkx))
- rejecty=10.0*log10(savg(3,1+nfft-ipky)/savg(3,1+ipky))
- endif
- endif
-
- nkhz=nint(1000.d0*(fcenter-int(fcenter)))
- if(fcenter.eq.0.d0) nkhz=125
-
-999 return
-end subroutine symspec
+subroutine symspec(k,nxpol,ndiskdat,nb,nbslider,idphi,nfsample, & + fgreen,iqadjust,iqapply,gainx,gainy,phasex,phasey,rejectx,rejecty, & + pxdb,pydb,ssz5a,nkhz,ihsym,nzap,slimit,lstrong) + +! k pointer to the most recent new data +! nxpol 0/1 to indicate single- or dual-polarization +! ndiskdat 0/1 to indicate if data from disk +! nb 0/1 status of noise blanker +! idphi Phase correction for Y channel, degrees +! nfsample sample rate (Hz) +! fgreen Frequency of green marker in I/Q calibrate mode (-48.0 to +48.0 kHz) +! iqadjust 0/1 to indicate whether IQ adjustment is active +! iqapply 0/1 to indicate whether to apply I/Q calibration +! pxdb power in x channel (0-60 dB) +! pydb power in y channel (0-60 dB) +! ssz5a polarized spectrum, for waterfall display +! nkhz integer kHz portion of center frequency, e.g., 125 for 144.125 +! ihsym index number of this half-symbol (1-322) +! nzap number of samples zero'ed by noise blanker + + include 'njunk.f90' + parameter (NSMAX=60*96000) !Total sample intervals per minute + parameter (NFFT=32768) !Length of FFTs + real*8 ts,hsym + real*8 fcenter + common/datcom/dd(4,5760000),ss(4,322,NFFT),savg(4,NFFT),fcenter,nutc, & + junk(NJUNK) + real*4 ssz5a(NFFT),w(NFFT),w2a(NFFT),w2b(NFFT) + complex z,zfac + complex zsumx,zsumy + complex cx(NFFT),cy(NFFT) + complex cx00(NFFT),cy00(NFFT) + complex cx0(0:1023),cx1(0:1023) + complex cy0(0:1023),cy1(0:1023) + logical*1 lstrong(0:1023) + data rms/999.0/,k0/99999999/,nadjx/0/,nadjy/0/ + save + + nfast=1 + if(k.gt.5751000) go to 999 + if(k.lt.NFFT) then + ihsym=0 + go to 999 !Wait for enough samples to start + endif + if(k0.eq.99999999) then + pi=4.0*atan(1.0) + w2a=0. + w2b=0. + do i=1,NFFT + w(i)=(sin(i*pi/NFFT))**2 !Window for nfast=1 + if(i.lt.17833) w2a(i)=(sin(i*pi/17832.925))**2 !Window a for nfast=2 + j=i-8916 + if(j.gt.0 .and. j.lt.17833) w2b(i)=(sin(j*pi/17832.925))**2 ! b + enddo + w2a=sqrt(2.0)*w2a + w2b=sqrt(2.0)*w2b + endif + + hsym=2048.d0*96000.d0/11025.d0 !Samples per JT65 half-symbol + if(nfsample.eq.95238) hsym=2048.d0*95238.1d0/11025.d0 + + if(k.lt.k0) then + ts=1.d0 - hsym + savg=0. + ihsym=0 + k1=0 + if(ndiskdat.eq.0) dd(1:4,k+1:5760000)=0. !### Should not be needed ??? ### + endif + k0=k + + nzap=0 + sigmas=1.5*(10.0**(0.01*nbslider)) + 0.7 + peaklimit=sigmas*max(10.0,rms) + faclim=3.0 + px=0. + py=0. + + iqapply0=0 + iqadjust0=0 + if(iqadjust.ne.0) iqapply0=0 + nwindow=2 +! nwindow=0 !### No windowing ### + nfft2=1024 + kstep=nfft2 + if(nwindow.ne.0) kstep=nfft2/2 + nblks=(k-k1)/kstep + do nblk=1,nblks + j=k1+1 + do i=0,nfft2-1 + cx0(i)=cmplx(dd(1,j+i),dd(2,j+i)) + if(nxpol.ne.0) cy0(i)=cmplx(dd(3,j+i),dd(4,j+i)) + enddo + call timf2(k,nxpol,nfft2,nwindow,nb,peaklimit,iqadjust0,iqapply0, & + faclim,cx0,cy0,gainx,gainy,phasex,phasey,cx1,cy1,slimit,lstrong, & + px,py,nzap) + + do i=0,kstep-1 + dd(1,j+i)=real(cx1(i)) + dd(2,j+i)=aimag(cx1(i)) + if(nxpol.ne.0) then + dd(3,j+i)=real(cy1(i)) + dd(4,j+i)=aimag(cy1(i)) + endif + enddo + k1=k1+kstep + enddo + + npts=NFFT !Samples used in each half-symbol FFT + + ts=ts+hsym + ja=ts !Index of first sample + jb=ja+npts-1 !Last sample + + i=0 + fac=0.0002 + dphi=idphi/57.2957795 + zfac=fac*cmplx(cos(dphi),sin(dphi)) + do j=ja,jb !Copy data into cx, cy + x1=dd(1,j) + x2=dd(2,j) + if(nxpol.ne.0) then + x3=dd(3,j) + x4=dd(4,j) + else + x3=0. + x4=0. + endif + i=i+1 + cx(i)=fac*cmplx(x1,x2) + cy(i)=zfac*cmplx(x3,x4) !NB: cy includes dphi correction + enddo + + if(nzap/178.lt.50 .and. (ndiskdat.eq.0 .or. ihsym.lt.280)) then + nsum=nblks*kstep - nzap + if(nsum.le.0) nsum=1 + rmsx=sqrt(0.5*px/nsum) + rmsy=sqrt(0.5*py/nsum) + rms=rmsx + if(nxpol.ne.0) rms=sqrt((px+py)/(4.0*nsum)) + endif + pxdb=0. + pydb=0. + if(rmsx.gt.1.0) pxdb=20.0*log10(rmsx) + if(rmsy.gt.1.0) pydb=20.0*log10(rmsy) + if(pxdb.gt.60.0) pxdb=60.0 + if(pydb.gt.60.0) pydb=60.0 + + cx00=cx + if(nxpol.ne.0) cy00=cy + + do mm=1,nfast + ihsym=ihsym+1 + if(nfast.eq.1) then + cx=w*cx00 !Apply window for 2nd forward FFT + if(nxpol.ne.0) cy=w*cy00 + else + if(mm.eq.1) then + cx=w2a*cx00 + if(nxpol.ne.0) cy=w2a*cy00 + else + cx=w2b*cx00 + if(nxpol.ne.0) cy=w2b*cy00 + endif + endif + + call four2a(cx,NFFT,1,1,1) !Second forward FFT (X) + if(iqadjust.eq.0) nadjx=0 + if(iqadjust.ne.0 .and. nadjx.lt.50) call iqcal(nadjx,cx,NFFT, & + gainx,phasex,zsumx,ipkx,rejectx0) + if(iqapply.ne.0) call iqfix(cx,NFFT,gainx,phasex) + + if(nxpol.ne.0) then + call four2a(cy,NFFT,1,1,1) !Second forward FFT (Y) + if(iqadjust.eq.0) nadjy=0 + if(iqadjust.ne.0 .and. nadjy.lt.50) call iqcal(nadjy,cy,NFFT, & + gainy,phasey,zsumy,ipky,rejecty) + if(iqapply.ne.0) call iqfix(cy,NFFT,gainy,phasey) + endif + + n=min(322,ihsym) + do i=1,NFFT + sx=real(cx(i))**2 + aimag(cx(i))**2 + ss(1,n,i)=sx ! Pol = 0 + savg(1,i)=savg(1,i) + sx + + if(nxpol.ne.0) then + z=cx(i) + cy(i) + s45=0.5*(real(z)**2 + aimag(z)**2) + ss(2,n,i)=s45 ! Pol = 45 + savg(2,i)=savg(2,i) + s45 + + sy=real(cy(i))**2 + aimag(cy(i))**2 + ss(3,n,i)=sy ! Pol = 90 + savg(3,i)=savg(3,i) + sy + + z=cx(i) - cy(i) + s135=0.5*(real(z)**2 + aimag(z)**2) + ss(4,n,i)=s135 ! Pol = 135 + savg(4,i)=savg(4,i) + s135 + + z=cx(i)*conjg(cy(i)) + q=sx - sy + u=2.0*real(z) + ssz5a(i)=0.707*sqrt(q*q + u*u) !Spectrum of linear polarization +! Leif's formula: +! ssz5a(i)=0.5*(sx+sy) + (real(z)**2 + aimag(z)**2 - sx*sy)/(sx+sy) + else + ssz5a(i)=sx + endif + enddo + enddo + + if(ihsym.eq.278) then + if(iqadjust.ne.0 .and. ipkx.ne.0 .and. ipky.ne.0) then + rejectx=10.0*log10(savg(1,1+nfft-ipkx)/savg(1,1+ipkx)) + rejecty=10.0*log10(savg(3,1+nfft-ipky)/savg(3,1+ipky)) + endif + endif + + nkhz=nint(1000.d0*(fcenter-int(fcenter))) + if(fcenter.eq.0.d0) nkhz=125 + +999 return +end subroutine symspec diff --git a/map65/libm65/synctest.f90 b/map65/libm65/synctest.f90 index 518fc8f6..a710daa1 100755..100644 --- a/map65/libm65/synctest.f90 +++ b/map65/libm65/synctest.f90 @@ -1,57 +1,57 @@ -program synctest
-
- ! Program to test an algorithm for detecting sync signals for both
- ! JT65 and Q65-60x signals and rejecting birdies in MAP65 data.
- ! The important work is done in module wideband_sync.
-
- use timer_module, only: timer
- use timer_impl, only: init_timer, fini_timer
- use wideband_sync
-
- real ss(4,322,NFFT),savg(4,NFFT)
-! real candidate(MAX_CANDIDATES,5) !snr1,f0,xdt0,ipol,flip
- character*8 arg
- type(candidate) :: cand(MAX_CANDIDATES)
-
- nargs=iargc()
- if(nargs.ne.5) then
- print*,'Usage: synctest iutc nfa nfb nts_jt65 nts_q65'
- print*,'Example: synctest 1814 23 83 2 1'
- go to 999
- endif
- call getarg(1,arg)
- read (arg,*) iutc
- call getarg(2,arg)
- read (arg,*) nfa
- call getarg(3,arg)
- read (arg,*) nfb
- call getarg(4,arg)
- read (arg,*) nts_jt65
- call getarg(5,arg)
- read (arg,*) nts_q65
-
- open(50,file='50.a',form='unformatted',status='old')
- do ifile=1,9999
- read(50,end=998) nutc,npol,ss(1:npol,:,:),savg(1:npol,:)
- if(nutc.eq.iutc) exit
- enddo
- close(50)
-
- call init_timer('timer.out')
- call timer('synctest',0)
-
- call timer('get_cand',0)
- call get_candidates(ss,savg,302,.true.,nfa,nfb,nts_jt65,nts_q65,cand,ncand)
- call timer('get_cand',1)
-
- do k=1,ncand
- write(*,1010) k,cand(k)%snr,cand(k)%f,cand(k)%f+77,cand(k)%xdt, &
- cand(k)%ipol,cand(k)%iflip
-1010 format(i3,4f10.3,2i3)
- enddo
-
-998 call timer('synctest',1)
- call timer('synctest',101)
- call fini_timer()
-
-999 end program synctest
+program synctest + + ! Program to test an algorithm for detecting sync signals for both + ! JT65 and Q65-60x signals and rejecting birdies in MAP65 data. + ! The important work is done in module wideband_sync. + + use timer_module, only: timer + use timer_impl, only: init_timer, fini_timer + use wideband_sync + + real ss(4,322,NFFT),savg(4,NFFT) +! real candidate(MAX_CANDIDATES,5) !snr1,f0,xdt0,ipol,flip + character*8 arg + type(candidate) :: cand(MAX_CANDIDATES) + + nargs=iargc() + if(nargs.ne.5) then + print*,'Usage: synctest iutc nfa nfb nts_jt65 nts_q65' + print*,'Example: synctest 1814 23 83 2 1' + go to 999 + endif + call getarg(1,arg) + read (arg,*) iutc + call getarg(2,arg) + read (arg,*) nfa + call getarg(3,arg) + read (arg,*) nfb + call getarg(4,arg) + read (arg,*) nts_jt65 + call getarg(5,arg) + read (arg,*) nts_q65 + + open(50,file='50.a',form='unformatted',status='old') + do ifile=1,9999 + read(50,end=998) nutc,npol,ss(1:npol,:,:),savg(1:npol,:) + if(nutc.eq.iutc) exit + enddo + close(50) + + call init_timer('timer.out') + call timer('synctest',0) + + call timer('get_cand',0) + call get_candidates(ss,savg,302,.true.,nfa,nfb,nts_jt65,nts_q65,cand,ncand) + call timer('get_cand',1) + + do k=1,ncand + write(*,1010) k,cand(k)%snr,cand(k)%f,cand(k)%f+77,cand(k)%xdt, & + cand(k)%ipol,cand(k)%iflip +1010 format(i3,4f10.3,2i3) + enddo + +998 call timer('synctest',1) + call timer('synctest',101) + call fini_timer() + +999 end program synctest diff --git a/map65/libm65/synctst.f90 b/map65/libm65/synctst.f90 index b9137300..248c7e19 100755..100644 --- a/map65/libm65/synctst.f90 +++ b/map65/libm65/synctst.f90 @@ -1,84 +1,84 @@ -program synctst
-
-! Tests JT65B2 sync patterns
-
- parameter (LAGMAX=20)
- real ccf0(0:LAGMAX),ccf2(0:LAGMAX),ccf3(0:LAGMAX)
- character*12 arg
- integer npr(126),np0(126),np1(126),npr2(126)
- 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/
-
- nargs=iargc()
- if(nargs.ne.1) then
- print*,'Usage: synctst iters'
- go to 999
- endif
- call getarg(1,arg)
- read(arg,*) iters
-
- worst=0.
- do lag=0,LAGMAX
- nsum=0
- do i=1,126-lag
- nsum=nsum + npr(i)*npr(lag+i)
- enddo
- ccf0(lag)=2.0*nsum/(126.0-lag)
- if(lag.ge.1 .and. ccf0(lag).gt.worst) worst=ccf0(lag)
- enddo
-
- best2=1.0
- do iter=1,iters
-
-10 np0=0
- np1=0
- n0=0
- do i=1,126
- if(npr(i).eq.1) then
- call random_number(r)
- if(r.lt.0.5) then
- np0(i)=1
- n0=n0+1
- else
- np1(i)=1
- endif
- endif
- enddo
- if(n0.ne.31 .and. n0.ne.32) go to 10
-
- worst2=0.
- do lag=0,LAGMAX
- nsum=0
- do i=1,126-lag
- nsum=nsum + np0(i)*np0(lag+i) + np1(i)*np1(lag+i)
- enddo
- ccf2(lag)=2.0*nsum/(126.0-lag)
- if(lag.ge.1 .and. ccf2(lag).gt.worst2) then
- worst2=ccf2(lag)
- lagbad=lag
- endif
- enddo
- if(worst2.lt.best2) then
- best2=worst2
- lagbest=lagbad
- n0best=n0
- ccf3=ccf2
- npr2=np0 + 2*np1
- endif
- enddo
-
- do lag=0,LAGMAX
- write(13,1100) lag,ccf0(lag),ccf3(lag)
-1100 format(i3,2f10.3)
- enddo
-
- print*,worst,best2,n0best,lagbest
- write(*,1110) npr2
-1110 format((8x,20(i1,',')))
-
-999 end program synctst
+program synctst + +! Tests JT65B2 sync patterns + + parameter (LAGMAX=20) + real ccf0(0:LAGMAX),ccf2(0:LAGMAX),ccf3(0:LAGMAX) + character*12 arg + integer npr(126),np0(126),np1(126),npr2(126) + 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/ + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: synctst iters' + go to 999 + endif + call getarg(1,arg) + read(arg,*) iters + + worst=0. + do lag=0,LAGMAX + nsum=0 + do i=1,126-lag + nsum=nsum + npr(i)*npr(lag+i) + enddo + ccf0(lag)=2.0*nsum/(126.0-lag) + if(lag.ge.1 .and. ccf0(lag).gt.worst) worst=ccf0(lag) + enddo + + best2=1.0 + do iter=1,iters + +10 np0=0 + np1=0 + n0=0 + do i=1,126 + if(npr(i).eq.1) then + call random_number(r) + if(r.lt.0.5) then + np0(i)=1 + n0=n0+1 + else + np1(i)=1 + endif + endif + enddo + if(n0.ne.31 .and. n0.ne.32) go to 10 + + worst2=0. + do lag=0,LAGMAX + nsum=0 + do i=1,126-lag + nsum=nsum + np0(i)*np0(lag+i) + np1(i)*np1(lag+i) + enddo + ccf2(lag)=2.0*nsum/(126.0-lag) + if(lag.ge.1 .and. ccf2(lag).gt.worst2) then + worst2=ccf2(lag) + lagbad=lag + endif + enddo + if(worst2.lt.best2) then + best2=worst2 + lagbest=lagbad + n0best=n0 + ccf3=ccf2 + npr2=np0 + 2*np1 + endif + enddo + + do lag=0,LAGMAX + write(13,1100) lag,ccf0(lag),ccf3(lag) +1100 format(i3,2f10.3) + enddo + + print*,worst,best2,n0best,lagbest + write(*,1110) npr2 +1110 format((8x,20(i1,','))) + +999 end program synctst diff --git a/map65/libm65/synctst2.f90 b/map65/libm65/synctst2.f90 index 34893f96..8ff4971a 100755..100644 --- a/map65/libm65/synctst2.f90 +++ b/map65/libm65/synctst2.f90 @@ -1,91 +1,91 @@ -program synctst2
-
-! Tests JT65B2 sync patterns
-
- parameter (LAGMAX=20)
- real ccf0(0:LAGMAX),ccf1(0:LAGMAX),ccf2(0:LAGMAX),ccf3(0:LAGMAX)
- character arg*12,line*64
- integer*8 n8
- integer npr(126),np0(126),np1(126),npr1(126),npr2(126)
- 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/
-
- data npr2/1,0,0,1,2,0,0,0,2,1,1,2,2,2,0,2,0,2,0,0, &
- 0,1,0,2,1,0,0,1,0,0,0,2,1,1,0,0,1,1,2,2, &
- 0,2,2,0,2,1,1,1,0,0,0,1,2,0,1,0,2,0,1,1, &
- 0,0,2,2,0,1,0,1,0,2,0,0,2,0,0,0,0,0,0,1, &
- 1,0,0,0,0,0,0,0,1,2,0,2,0,0,2,0,2,1,0,1, &
- 0,2,0,1,0,0,2,2,0,0,1,0,0,2,0,0,0,0,1,1, &
- 1,2,1,2,1,2/
-
- data n8/x'4314f4725bb357e0'/
-
- write(*,1102) n8
- write(line,1102) n8
-1102 format(b63)
- read(line,1104) npr1(1:63)
-1104 format(63i1)
- npr1(64:126)=npr1(1:63)
-
- worst=0.
- do lag=0,LAGMAX
- nsum=0
- do i=1,126-lag
- nsum=nsum + npr(i)*npr(lag+i)
- enddo
- ccf0(lag)=2.0*nsum/(126.0-lag)
- if(lag.ge.1 .and. ccf0(lag).gt.worst) worst=ccf0(lag)
- enddo
-
-
- worst1=0.
- do lag=0,LAGMAX
- nsum=0
- do i=1,126-lag
- nsum=nsum + npr1(i)*npr1(lag+i)
- enddo
- ccf1(lag)=(63.0/64.0)*2.0*nsum/(126.0-lag)
- if(lag.ge.1 .and. ccf1(lag).gt.worst1) worst1=ccf1(lag)
- enddo
- ccf1=ccf1/ccf1(0)
- worst1=worst1/ccf1(0)
-
- np0=0
- np1=0
- n0=0
- do i=1,126
- if(npr2(i).eq.1) then
- np0(i)=1
- n0=n0+1
- else if(npr2(i).eq.2) then
- np1(i)=1
- endif
- enddo
-
- worst2=0.
- do lag=0,LAGMAX
- nsum=0
- do i=1,126-lag
- nsum=nsum + np0(i)*np0(lag+i) + np1(i)*np1(lag+i)
- enddo
- ccf2(lag)=2.0*nsum/(126.0-lag)
- if(lag.ge.1 .and. ccf2(lag).gt.worst2) then
- worst2=ccf2(lag)
- lagbad=lag
- endif
- enddo
-
- do lag=0,LAGMAX
- write(13,1100) lag,ccf0(lag),ccf1(lag),ccf2(lag)
-1100 format(i3,3f10.3)
- enddo
-
- print*,worst,worst1,worst2,n0,lagbad
-
-
-999 end program synctst2
+program synctst2 + +! Tests JT65B2 sync patterns + + parameter (LAGMAX=20) + real ccf0(0:LAGMAX),ccf1(0:LAGMAX),ccf2(0:LAGMAX),ccf3(0:LAGMAX) + character arg*12,line*64 + integer*8 n8 + integer npr(126),np0(126),np1(126),npr1(126),npr2(126) + 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/ + + data npr2/1,0,0,1,2,0,0,0,2,1,1,2,2,2,0,2,0,2,0,0, & + 0,1,0,2,1,0,0,1,0,0,0,2,1,1,0,0,1,1,2,2, & + 0,2,2,0,2,1,1,1,0,0,0,1,2,0,1,0,2,0,1,1, & + 0,0,2,2,0,1,0,1,0,2,0,0,2,0,0,0,0,0,0,1, & + 1,0,0,0,0,0,0,0,1,2,0,2,0,0,2,0,2,1,0,1, & + 0,2,0,1,0,0,2,2,0,0,1,0,0,2,0,0,0,0,1,1, & + 1,2,1,2,1,2/ + + data n8/x'4314f4725bb357e0'/ + + write(*,1102) n8 + write(line,1102) n8 +1102 format(b63) + read(line,1104) npr1(1:63) +1104 format(63i1) + npr1(64:126)=npr1(1:63) + + worst=0. + do lag=0,LAGMAX + nsum=0 + do i=1,126-lag + nsum=nsum + npr(i)*npr(lag+i) + enddo + ccf0(lag)=2.0*nsum/(126.0-lag) + if(lag.ge.1 .and. ccf0(lag).gt.worst) worst=ccf0(lag) + enddo + + + worst1=0. + do lag=0,LAGMAX + nsum=0 + do i=1,126-lag + nsum=nsum + npr1(i)*npr1(lag+i) + enddo + ccf1(lag)=(63.0/64.0)*2.0*nsum/(126.0-lag) + if(lag.ge.1 .and. ccf1(lag).gt.worst1) worst1=ccf1(lag) + enddo + ccf1=ccf1/ccf1(0) + worst1=worst1/ccf1(0) + + np0=0 + np1=0 + n0=0 + do i=1,126 + if(npr2(i).eq.1) then + np0(i)=1 + n0=n0+1 + else if(npr2(i).eq.2) then + np1(i)=1 + endif + enddo + + worst2=0. + do lag=0,LAGMAX + nsum=0 + do i=1,126-lag + nsum=nsum + np0(i)*np0(lag+i) + np1(i)*np1(lag+i) + enddo + ccf2(lag)=2.0*nsum/(126.0-lag) + if(lag.ge.1 .and. ccf2(lag).gt.worst2) then + worst2=ccf2(lag) + lagbad=lag + endif + enddo + + do lag=0,LAGMAX + write(13,1100) lag,ccf0(lag),ccf1(lag),ccf2(lag) +1100 format(i3,3f10.3) + enddo + + print*,worst,worst1,worst2,n0,lagbad + + +999 end program synctst2 diff --git a/map65/libm65/tastro.f90 b/map65/libm65/tastro.f90 index d9ede4a6..fac5c800 100755..100644 --- a/map65/libm65/tastro.f90 +++ b/map65/libm65/tastro.f90 @@ -1,35 +1,35 @@ -program tastro
-
- implicit real*8 (a-h,o-z)
-
- character grid*6
- character*9 cauxra,cauxdec
-
- character*12 clock(3)
- integer nt(8)
- equivalence (nt(1),nyear)
-
- grid='FN20qi'
- nfreq=144
- cauxra='00:00:00'
-
-10 call date_and_time(clock(1),clock(2),clock(3),nt)
- ih=ihour-ntz/60
- if(ih.le.0) then
- ih=ih+24
- nday=nday+1
- endif
- uth8=ih + imin/60.d0 + isec/3600.d0 + ims/3600000.d0
- call astro0(nyear,month,nday,uth8,nfreq,grid,cauxra,cauxdec, &
- AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, &
- dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, &
- RaAux8,DecAux8,AzAux8,ElAux8,width1,width2,w501,w502,xlst8)
-
- write(*,1010) nyear,month,nday,ih,imin,isec,AzMoon8,ElMoon8, &
- AzSun8,ElSun8,ndop,dgrd8,ntsky
-1010 format(i4,i3,i3,i4.2,':',i2.2,':',i2.2,4f8.1,i6,f6.1,i6)
-
- call system('sleep 1')
- go to 10
-
-end program tastro
+program tastro + + implicit real*8 (a-h,o-z) + + character grid*6 + character*9 cauxra,cauxdec + + character*12 clock(3) + integer nt(8) + equivalence (nt(1),nyear) + + grid='FN20qi' + nfreq=144 + cauxra='00:00:00' + +10 call date_and_time(clock(1),clock(2),clock(3),nt) + ih=ihour-ntz/60 + if(ih.le.0) then + ih=ih+24 + nday=nday+1 + endif + uth8=ih + imin/60.d0 + isec/3600.d0 + ims/3600000.d0 + call astro0(nyear,month,nday,uth8,nfreq,grid,cauxra,cauxdec, & + AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & + dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, & + RaAux8,DecAux8,AzAux8,ElAux8,width1,width2,w501,w502,xlst8) + + write(*,1010) nyear,month,nday,ih,imin,isec,AzMoon8,ElMoon8, & + AzSun8,ElSun8,ndop,dgrd8,ntsky +1010 format(i4,i3,i3,i4.2,':',i2.2,':',i2.2,4f8.1,i6,f6.1,i6) + + call system('sleep 1') + go to 10 + +end program tastro diff --git a/map65/libm65/timeval.h b/map65/libm65/timeval.h index 9f8199e2..83c77d5a 100755..100644 --- a/map65/libm65/timeval.h +++ b/map65/libm65/timeval.h @@ -1,76 +1,76 @@ -/*
- * 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 */
+/* + * 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/map65/libm65/timf2.f90 b/map65/libm65/timf2.f90 index d5afef72..4873d0e9 100755..100644 --- a/map65/libm65/timf2.f90 +++ b/map65/libm65/timf2.f90 @@ -1,215 +1,215 @@ -subroutine timf2(k,nxpol,nfft,nwindow,nb,peaklimit,iqadjust,iqapply,faclim, &
- cx0,cy0,gainx,gainy,phasex,phasey,cx1,cy1,slimit,lstrong,px,py,nzap)
-
-! Sequential processing of time-domain I/Q data, using Linrad-like
-! "first FFT" and "first backward FFT".
-
-! cx0,cy0 - complex input data
-! nfft - length of FFTs
-! nwindow - 0 for no window, 2 for sin^2 window
-! iqapply - 0/1 determines if I/Q phase and amplitude corrections applied
-! gainx,y - gain error in Q channel, relative to I
-! phasex,y - phase error
-! cx1,cy1 - output data
-
-! Non-windowed processing means no overlap, so kstep=nfft.
-! Sin^2 window has 50% overlap, kstep=nfft/2.
-
-! Frequencies with strong signals are identified and separated. The back
-! transforms are done separately for weak and strong signals, so that
-! noise blanking can be applied to the weak-signal portion. Strong and
-! weak are finally re-combined in the time domain.
-
- parameter (MAXFFT=1024,MAXNH=MAXFFT/2)
- parameter (MAXSIGS=100)
- complex cx0(0:nfft-1),cx1(0:nfft-1)
- complex cy0(0:nfft-1),cy1(0:nfft-1)
- complex cx(0:MAXFFT-1),cxt(0:MAXFFT-1)
- complex cy(0:MAXFFT-1),cyt(0:MAXFFT-1)
- complex cxs(0:MAXFFT-1),covxs(0:MAXNH-1) !Strong X signals
- complex cys(0:MAXFFT-1),covys(0:MAXNH-1) !Strong Y signals
- complex cxw(0:MAXFFT-1),covxw(0:MAXNH-1) !Weak X signals
- complex cyw(0:MAXFFT-1),covyw(0:MAXNH-1) !Weak Y signals
- real*4 w(0:MAXFFT-1)
- real*4 s(0:MAXFFT-1)
- logical*1 lstrong(0:MAXFFT-1),lprev
- integer ia(MAXSIGS),ib(MAXSIGS)
- complex h,u,v
- logical first
- data first/.true./
- data k0/99999999/
- save
-
- if(faclim+iqadjust.eq.-9999.0) iqadjust=0 !Silence compiler warning.
- if(first) then
- pi=4.0*atan(1.0)
- do i=0,nfft-1
- w(i)=(sin(i*pi/nfft))**2
- enddo
- s=0.
- nh=nfft/2
- kstep=nfft
- if(nwindow.eq.2) kstep=nh
- fac=1.0/nfft
- slimit=1.e30
- first=.false.
- endif
-
- if(k.lt.k0) then
- covxs=0.
- covxw=0.
- covys=0.
- covyw=0.
- endif
- k0=k
-
- cx(0:nfft-1)=cx0
- if(nwindow.eq.2) cx(0:nfft-1)=w(0:nfft-1)*cx(0:nfft-1)
- call four2a(cx,nfft,1,1,1) !First forward FFT (X)
-
- if(nxpol.ne.0) then
- cy(0:nfft-1)=cy0
- if(nwindow.eq.2) cy(0:nfft-1)=w(0:nfft-1)*cy(0:nfft-1)
- call four2a(cy,nfft,1,1,1) !First forward FFT (Y)
- endif
-
- if(iqapply.ne.0) then !Apply I/Q corrections (X)
- h=gainx*cmplx(cos(phasex),sin(phasex))
- v=0.
- do i=0,nfft-1
- u=cx(i)
- if(i.gt.0) v=cx(nfft-i)
- x=real(u) + real(v) - (aimag(u) + aimag(v))*aimag(h) + &
- (real(u) - real(v))*real(h)
- y=aimag(u) - aimag(v) + (aimag(u) + aimag(v))*real(h) + &
- (real(u) - real(v))*aimag(h)
- cxt(i)=0.5*cmplx(x,y)
- enddo
- else
- cxt(0:nfft-1)=cx(0:nfft-1)
- endif
-
- if(nxpol.ne.0) then
- if(iqapply.ne.0) then !Apply I/Q corrections (Y)
- h=gainy*cmplx(cos(phasey),sin(phasey))
- v=0.
- do i=0,nfft-1
- u=cy(i)
- if(i.gt.0) v=cy(nfft-i)
- x=real(u) + real(v) - (aimag(u) + aimag(v))*aimag(h) + &
- (real(u) - real(v))*real(h)
- y=aimag(u) - aimag(v) + (aimag(u) + aimag(v))*real(h) + &
- (real(u) - real(v))*aimag(h)
- cyt(i)=0.5*cmplx(x,y)
- enddo
- else
- cyt(0:nfft-1)=cy(0:nfft-1)
- endif
- endif
-
-! Identify frequencies with strong signals, copy frequency-domain
-! data into array cs (strong) or cw (weak).
-
- do i=0,nfft-1
- p=real(cxt(i))**2 + aimag(cxt(i))**2
- if(nxpol.ne.0) p=p + real(cyt(i))**2 + aimag(cyt(i))**2
- s(i)=p
- enddo
- ave=sum(s(0:nfft-1))/nfft
- lstrong(0:nfft-1)=s(0:nfft-1).gt.10.0*ave
-
- nsigs=0
- lprev=.false.
- iwid=1
- ib=-99
- do i=0,nfft-1
- if(lstrong(i) .and. (.not.lprev)) then
- if(nsigs.lt.MAXSIGS) nsigs=nsigs+1
- ia(nsigs)=i-iwid
- if(ia(nsigs).lt.0) ia(nsigs)=0
- endif
- if(.not.lstrong(i) .and. lprev) then
- ib(nsigs)=i-1+iwid
- if(ib(nsigs).gt.nfft-1) ib(nsigs)=nfft-1
- endif
- lprev=lstrong(i)
- enddo
-
- if(nsigs.gt.0) then
- do i=1,nsigs
- ja=ia(i)
- jb=ib(i)
- if(ja.lt.0 .or. ja.gt.nfft-1 .or. jb.lt.0 .or. jb.gt.nfft-1) then
- cycle
- endif
- if(jb.eq.-99) jb=ja + min(2*iwid,nfft-1)
- lstrong(ja:jb)=.true.
- enddo
- endif
-
- do i=0,nfft-1
- if(lstrong(i)) then
- cxs(i)=fac*cxt(i)
- cxw(i)=0.
- if(nxpol.ne.0) then
- cys(i)=fac*cyt(i)
- cyw(i)=0.
- endif
- else
- cxw(i)=fac*cxt(i)
- cxs(i)=0.
- if(nxpol.ne.0) then
- cyw(i)=fac*cyt(i)
- cys(i)=0.
- endif
- endif
- enddo
-
- call four2a(cxw,nfft,1,-1,1) !Transform weak and strong X
- call four2a(cxs,nfft,1,-1,1) !back to time domain, separately
-
- if(nxpol.ne.0) then
- call four2a(cyw,nfft,1,-1,1) !Transform weak and strong Y
- call four2a(cys,nfft,1,-1,1) !back to time domain, separately
- endif
-
- if(nwindow.eq.2) then
- cxw(0:nh-1)=cxw(0:nh-1)+covxw(0:nh-1) !Add previous segment's 2nd half
- covxw(0:nh-1)=cxw(nh:nfft-1) !Save 2nd half
- cxs(0:nh-1)=cxs(0:nh-1)+covxs(0:nh-1) !Ditto for strong signals
- covxs(0:nh-1)=cxs(nh:nfft-1)
-
- if(nxpol.ne.0) then
- cyw(0:nh-1)=cyw(0:nh-1)+covyw(0:nh-1) !Add previous segment's 2nd half
- covyw(0:nh-1)=cyw(nh:nfft-1) !Save 2nd half
- cys(0:nh-1)=cys(0:nh-1)+covys(0:nh-1) !Ditto for strong signals
- covys(0:nh-1)=cys(nh:nfft-1)
- endif
- endif
-
-! Apply noise blanking to weak data
- if(nb.ne.0) then
- do i=0,kstep-1
- peak=abs(cxw(i))
- if(nxpol.ne.0) peak=max(peak,abs(cyw(i)))
- if(peak.gt.peaklimit) then
- cxw(i)=0.
- if(nxpol.ne.0) cyw(i)=0.
- nzap=nzap+1
- endif
- enddo
- endif
-
-! Compute power levels from weak data only
- do i=0,kstep-1
- px=px + real(cxw(i))**2 + aimag(cxw(i))**2
- if(nxpol.ne.0) py=py + real(cyw(i))**2 + aimag(cyw(i))**2
- enddo
-
- cx1(0:kstep-1)=cxw(0:kstep-1) + cxs(0:kstep-1) !Weak + strong (X)
- if(nxpol.ne.0) then
- cy1(0:kstep-1)=cyw(0:kstep-1) + cys(0:kstep-1) !Weak + strong (Y)
- endif
-
- return
-end subroutine timf2
+subroutine timf2(k,nxpol,nfft,nwindow,nb,peaklimit,iqadjust,iqapply,faclim, & + cx0,cy0,gainx,gainy,phasex,phasey,cx1,cy1,slimit,lstrong,px,py,nzap) + +! Sequential processing of time-domain I/Q data, using Linrad-like +! "first FFT" and "first backward FFT". + +! cx0,cy0 - complex input data +! nfft - length of FFTs +! nwindow - 0 for no window, 2 for sin^2 window +! iqapply - 0/1 determines if I/Q phase and amplitude corrections applied +! gainx,y - gain error in Q channel, relative to I +! phasex,y - phase error +! cx1,cy1 - output data + +! Non-windowed processing means no overlap, so kstep=nfft. +! Sin^2 window has 50% overlap, kstep=nfft/2. + +! Frequencies with strong signals are identified and separated. The back +! transforms are done separately for weak and strong signals, so that +! noise blanking can be applied to the weak-signal portion. Strong and +! weak are finally re-combined in the time domain. + + parameter (MAXFFT=1024,MAXNH=MAXFFT/2) + parameter (MAXSIGS=100) + complex cx0(0:nfft-1),cx1(0:nfft-1) + complex cy0(0:nfft-1),cy1(0:nfft-1) + complex cx(0:MAXFFT-1),cxt(0:MAXFFT-1) + complex cy(0:MAXFFT-1),cyt(0:MAXFFT-1) + complex cxs(0:MAXFFT-1),covxs(0:MAXNH-1) !Strong X signals + complex cys(0:MAXFFT-1),covys(0:MAXNH-1) !Strong Y signals + complex cxw(0:MAXFFT-1),covxw(0:MAXNH-1) !Weak X signals + complex cyw(0:MAXFFT-1),covyw(0:MAXNH-1) !Weak Y signals + real*4 w(0:MAXFFT-1) + real*4 s(0:MAXFFT-1) + logical*1 lstrong(0:MAXFFT-1),lprev + integer ia(MAXSIGS),ib(MAXSIGS) + complex h,u,v + logical first + data first/.true./ + data k0/99999999/ + save + + if(faclim+iqadjust.eq.-9999.0) iqadjust=0 !Silence compiler warning. + if(first) then + pi=4.0*atan(1.0) + do i=0,nfft-1 + w(i)=(sin(i*pi/nfft))**2 + enddo + s=0. + nh=nfft/2 + kstep=nfft + if(nwindow.eq.2) kstep=nh + fac=1.0/nfft + slimit=1.e30 + first=.false. + endif + + if(k.lt.k0) then + covxs=0. + covxw=0. + covys=0. + covyw=0. + endif + k0=k + + cx(0:nfft-1)=cx0 + if(nwindow.eq.2) cx(0:nfft-1)=w(0:nfft-1)*cx(0:nfft-1) + call four2a(cx,nfft,1,1,1) !First forward FFT (X) + + if(nxpol.ne.0) then + cy(0:nfft-1)=cy0 + if(nwindow.eq.2) cy(0:nfft-1)=w(0:nfft-1)*cy(0:nfft-1) + call four2a(cy,nfft,1,1,1) !First forward FFT (Y) + endif + + if(iqapply.ne.0) then !Apply I/Q corrections (X) + h=gainx*cmplx(cos(phasex),sin(phasex)) + v=0. + do i=0,nfft-1 + u=cx(i) + if(i.gt.0) v=cx(nfft-i) + x=real(u) + real(v) - (aimag(u) + aimag(v))*aimag(h) + & + (real(u) - real(v))*real(h) + y=aimag(u) - aimag(v) + (aimag(u) + aimag(v))*real(h) + & + (real(u) - real(v))*aimag(h) + cxt(i)=0.5*cmplx(x,y) + enddo + else + cxt(0:nfft-1)=cx(0:nfft-1) + endif + + if(nxpol.ne.0) then + if(iqapply.ne.0) then !Apply I/Q corrections (Y) + h=gainy*cmplx(cos(phasey),sin(phasey)) + v=0. + do i=0,nfft-1 + u=cy(i) + if(i.gt.0) v=cy(nfft-i) + x=real(u) + real(v) - (aimag(u) + aimag(v))*aimag(h) + & + (real(u) - real(v))*real(h) + y=aimag(u) - aimag(v) + (aimag(u) + aimag(v))*real(h) + & + (real(u) - real(v))*aimag(h) + cyt(i)=0.5*cmplx(x,y) + enddo + else + cyt(0:nfft-1)=cy(0:nfft-1) + endif + endif + +! Identify frequencies with strong signals, copy frequency-domain +! data into array cs (strong) or cw (weak). + + do i=0,nfft-1 + p=real(cxt(i))**2 + aimag(cxt(i))**2 + if(nxpol.ne.0) p=p + real(cyt(i))**2 + aimag(cyt(i))**2 + s(i)=p + enddo + ave=sum(s(0:nfft-1))/nfft + lstrong(0:nfft-1)=s(0:nfft-1).gt.10.0*ave + + nsigs=0 + lprev=.false. + iwid=1 + ib=-99 + do i=0,nfft-1 + if(lstrong(i) .and. (.not.lprev)) then + if(nsigs.lt.MAXSIGS) nsigs=nsigs+1 + ia(nsigs)=i-iwid + if(ia(nsigs).lt.0) ia(nsigs)=0 + endif + if(.not.lstrong(i) .and. lprev) then + ib(nsigs)=i-1+iwid + if(ib(nsigs).gt.nfft-1) ib(nsigs)=nfft-1 + endif + lprev=lstrong(i) + enddo + + if(nsigs.gt.0) then + do i=1,nsigs + ja=ia(i) + jb=ib(i) + if(ja.lt.0 .or. ja.gt.nfft-1 .or. jb.lt.0 .or. jb.gt.nfft-1) then + cycle + endif + if(jb.eq.-99) jb=ja + min(2*iwid,nfft-1) + lstrong(ja:jb)=.true. + enddo + endif + + do i=0,nfft-1 + if(lstrong(i)) then + cxs(i)=fac*cxt(i) + cxw(i)=0. + if(nxpol.ne.0) then + cys(i)=fac*cyt(i) + cyw(i)=0. + endif + else + cxw(i)=fac*cxt(i) + cxs(i)=0. + if(nxpol.ne.0) then + cyw(i)=fac*cyt(i) + cys(i)=0. + endif + endif + enddo + + call four2a(cxw,nfft,1,-1,1) !Transform weak and strong X + call four2a(cxs,nfft,1,-1,1) !back to time domain, separately + + if(nxpol.ne.0) then + call four2a(cyw,nfft,1,-1,1) !Transform weak and strong Y + call four2a(cys,nfft,1,-1,1) !back to time domain, separately + endif + + if(nwindow.eq.2) then + cxw(0:nh-1)=cxw(0:nh-1)+covxw(0:nh-1) !Add previous segment's 2nd half + covxw(0:nh-1)=cxw(nh:nfft-1) !Save 2nd half + cxs(0:nh-1)=cxs(0:nh-1)+covxs(0:nh-1) !Ditto for strong signals + covxs(0:nh-1)=cxs(nh:nfft-1) + + if(nxpol.ne.0) then + cyw(0:nh-1)=cyw(0:nh-1)+covyw(0:nh-1) !Add previous segment's 2nd half + covyw(0:nh-1)=cyw(nh:nfft-1) !Save 2nd half + cys(0:nh-1)=cys(0:nh-1)+covys(0:nh-1) !Ditto for strong signals + covys(0:nh-1)=cys(nh:nfft-1) + endif + endif + +! Apply noise blanking to weak data + if(nb.ne.0) then + do i=0,kstep-1 + peak=abs(cxw(i)) + if(nxpol.ne.0) peak=max(peak,abs(cyw(i))) + if(peak.gt.peaklimit) then + cxw(i)=0. + if(nxpol.ne.0) cyw(i)=0. + nzap=nzap+1 + endif + enddo + endif + +! Compute power levels from weak data only + do i=0,kstep-1 + px=px + real(cxw(i))**2 + aimag(cxw(i))**2 + if(nxpol.ne.0) py=py + real(cyw(i))**2 + aimag(cyw(i))**2 + enddo + + cx1(0:kstep-1)=cxw(0:kstep-1) + cxs(0:kstep-1) !Weak + strong (X) + if(nxpol.ne.0) then + cy1(0:kstep-1)=cyw(0:kstep-1) + cys(0:kstep-1) !Weak + strong (Y) + endif + + return +end subroutine timf2 diff --git a/map65/libm65/tm2.f90 b/map65/libm65/tm2.f90 index cf110783..fb831fab 100755..100644 --- a/map65/libm65/tm2.f90 +++ b/map65/libm65/tm2.f90 @@ -1,14 +1,14 @@ -subroutine tm2(day,xlat4,xlon4,xl4,b4)
-
- implicit real*8 (a-h,o-z)
- parameter (RADS=0.0174532925199433d0)
-
- real*4 xlat4,xlon4,xl4,b4
-
- glat=xlat4*RADS
- glong=xlon4*RADS
- call tmoonsub(day,glat,glong,el,rv,xl,b,pax)
- xl4=xl
- b4=b
-
-end subroutine tm2
+subroutine tm2(day,xlat4,xlon4,xl4,b4) + + implicit real*8 (a-h,o-z) + parameter (RADS=0.0174532925199433d0) + + real*4 xlat4,xlon4,xl4,b4 + + glat=xlat4*RADS + glong=xlon4*RADS + call tmoonsub(day,glat,glong,el,rv,xl,b,pax) + xl4=xl + b4=b + +end subroutine tm2 diff --git a/map65/libm65/tmoonsub.c b/map65/libm65/tmoonsub.c index 3b171b54..29ac28b4 100755..100644 --- a/map65/libm65/tmoonsub.c +++ b/map65/libm65/tmoonsub.c @@ -1,514 +1,514 @@ -#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-
-#define RADS 0.0174532925199433
-#define DEGS 57.2957795130823
-#define TPI 6.28318530717959
-#define PI 3.1415927
-
-/* ratio of earth radius to astronomical unit */
-#define ER_OVER_AU 0.0000426352325194252
-
-/* all prototypes here */
-
-double getcoord(int coord);
-void getargs(int argc, char *argv[], int *y, int *m, double *tz, double *glong, double *glat);
-double range(double y);
-double rangerad(double y);
-double days(int y, int m, int dn, double hour);
-double days_(int *y, int *m, int *dn, double *hour);
-void moonpos(double, double *, double *, double *);
-void sunpos(double , double *, double *, double *);
-double moontransit(int y, int m, int d, double timezone, double glat, double glong, int *nt);
-double atan22(double y, double x);
-double epsilon(double d);
-void equatorial(double d, double *lon, double *lat, double *r);
-void ecliptic(double d, double *lon, double *lat, double *r);
-double gst(double d);
-void topo(double lst, double glat, double *alp, double *dec, double *r);
-double alt(double glat, double ha, double dec);
-void libration(double day, double lambda, double beta, double alpha, double *l, double *b, double *p);
-void illumination(double day, double lra, double ldec, double dr, double sra, double sdec, double *pabl, double *ill);
-int daysinmonth(int y, int m);
-int isleap(int y);
-void tmoonsub_(double *day, double *glat, double *glong, double *moonalt,
- double *mrv, double *l, double *b, double *paxis);
-
-static const char
-*usage = " Usage: tmoon date[yyyymm] timz[+/-h.hh] long[+/-dddmm] lat[+/-ddmm]\n"
- "example: tmoon 200009 0 -00155 5230\n";
-
-/*
- getargs() gets the arguments from the command line, does some basic error
- checking, and converts arguments into numerical form. Arguments are passed
- back in pointers. Error messages print to stderr so re-direction of output
- to file won't leave users blind. Error checking prints list of all errors
- in a command line before quitting.
-*/
-void getargs(int argc, char *argv[], int *y, int *m, double *tz,
- double *glong, double *glat) {
-
- int date, latitude, longitude;
- int mflag = 0, yflag = 0, longflag = 0, latflag = 0, tzflag = 0;
- int longminflag = 0, latminflag = 0, dflag = 0;
-
- /* if not right number of arguments, then print example command line */
-
- if (argc !=5) {
- fprintf(stderr, usage);
- exit(EXIT_FAILURE);
- }
-
- date = atoi(argv[1]);
- *y = date / 100;
- *m = date - *y * 100;
- *tz = (double) atof(argv[2]);
- longitude = atoi(argv[3]);
- latitude = atoi(argv[4]);
- *glong = RADS * getcoord(longitude);
- *glat = RADS * getcoord(latitude);
-
- /* set a flag for each error found */
-
- if (*m > 12 || *m < 1) mflag = 1;
- if (*y > 2500) yflag = 1;
- if (date < 150001) dflag = 1;
- if (fabs((float) *glong) > 180 * RADS) longflag = 1;
- if (abs(longitude) % 100 > 59) longminflag = 1;
- if (fabs((float) *glat) > 90 * RADS) latflag = 1;
- if (abs(latitude) % 100 > 59) latminflag = 1;
- if (fabs((float) *tz) > 12) tzflag = 1;
-
- /* print all the errors found */
-
- if (dflag == 1) {
- fprintf(stderr, "date: dates must be in form yyyymm, gregorian, and later than 1500 AD\n");
- }
- if (yflag == 1) {
- fprintf(stderr, "date: too far in future - accurate from 1500 to 2500\n");
- }
- if (mflag == 1) {
- fprintf(stderr, "date: month must be in range 0 to 12, eg - August 2000 is entered as 200008\n");
- }
- if (tzflag == 1) {
- fprintf(stderr, "timz: must be in range +/- 12 hours, eg -6 for Chicago\n");
- }
- if (longflag == 1) {
- fprintf(stderr, "long: must be in range +/- 180 degrees\n");
- }
- if (longminflag == 1) {
- fprintf(stderr, "long: last two digits are arcmin - max 59\n");
- }
- if (latflag == 1) {
- fprintf(stderr, " lat: must be in range +/- 90 degrees\n");
- }
- if (latminflag == 1) {
- fprintf(stderr, " lat: last two digits are arcmin - max 59\n");
- }
-
- /* quits if one or more flags set */
-
- if (dflag + mflag + yflag + longflag + latflag + tzflag + longminflag + latminflag > 0) {
- exit(EXIT_FAILURE);
- }
-
-}
-
-/*
- returns coordinates in decimal degrees given the
- coord as a ddmm value stored in an integer.
-*/
-double getcoord(int coord) {
- int west = 1;
- double glg, deg;
- if (coord < 0) west = -1;
- glg = fabs((double) coord/100);
- deg = floor(glg);
- glg = west* (deg + (glg - deg)*100 / 60);
- return(glg);
-}
-
-/*
- days() takes the year, month, day in the month and decimal hours
- in the day and returns the number of days since J2000.0.
- Assumes Gregorian calendar.
-*/
-double days(int y, int m, int d, double h) {
- int a, b;
- double day;
-
- /*
- The lines below work from 1900 march to feb 2100
- a = 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d;
- day = (double)a - 730531.5 + hour / 24;
- */
-
- /* These lines work for any Gregorian date since 0 AD */
- if (m ==1 || m==2) {
- m +=12;
- y -= 1;
- }
- a = y / 100;
- b = 2 - a + a/4;
- day = floor(365.25*(y + 4716)) + floor(30.6001*(m + 1))
- + d + b - 1524.5 - 2451545 + h/24;
- return(day);
-}
-double days_(int *y0, int *m0, int *d0, double *h0)
-{
- return days(*y0,*m0,*d0,*h0);
-}
-
-/*
-Returns 1 if y a leap year, and 0 otherwise, according
-to the Gregorian calendar
-*/
-int isleap(int y) {
- int a = 0;
- if(y % 4 == 0) a = 1;
- if(y % 100 == 0) a = 0;
- if(y % 400 == 0) a = 1;
- return(a);
-}
-
-/*
-Given the year and the month, function returns the
-number of days in the month. Valid for Gregorian
-calendar.
-*/
-int daysinmonth(int y, int m) {
- int b = 31;
- if(m == 2) {
- if(isleap(y) == 1) b= 29;
- else b = 28;
- }
- if(m == 4 || m == 6 || m == 9 || m == 11) b = 30;
- return(b);
-}
-
-/*
-moonpos() takes days from J2000.0 and returns ecliptic coordinates
-of moon in the pointers. Note call by reference.
-This function is within a couple of arcminutes most of the time,
-and is truncated from the Meeus Ch45 series, themselves truncations of
-ELP-2000. Returns moon distance in earth radii.
-Terms have been written out explicitly rather than using the
-table based method as only a small number of terms is
-retained.
-*/
-void moonpos(double d, double *lambda, double *beta, double *rvec) {
- double dl, dB, dR, L, D, M, M1, F, e, lm, bm, rm, t;
-
- t = d / 36525;
-
- L = range(218.3164591 + 481267.88134236 * t) * RADS;
- D = range(297.8502042 + 445267.1115168 * t) * RADS;
- M = range(357.5291092 + 35999.0502909 * t) * RADS;
- M1 = range(134.9634114 + 477198.8676313 * t - .008997 * t * t) * RADS;
- F = range(93.27209929999999 + 483202.0175273 * t - .0034029*t*t)*RADS;
- e = 1 - .002516 * t;
-
- dl = 6288774 * sin(M1);
- dl += 1274027 * sin(2 * D - M1);
- dl += 658314 * sin(2 * D);
- dl += 213618 * sin(2 * M1);
- dl -= e * 185116 * sin(M);
- dl -= 114332 * sin(2 * F) ;
- dl += 58793 * sin(2 * D - 2 * M1);
- dl += e * 57066 * sin(2 * D - M - M1) ;
- dl += 53322 * sin(2 * D + M1);
- dl += e * 45758 * sin(2 * D - M);
- dl -= e * 40923 * sin(M - M1);
- dl -= 34720 * sin(D) ;
- dl -= e * 30383 * sin(M + M1) ;
- dl += 15327 * sin(2 * D - 2 * F) ;
- dl -= 12528 * sin(M1 + 2 * F);
- dl += 10980 * sin(M1 - 2 * F);
- lm = rangerad(L + dl / 1000000 * RADS);
-
- dB = 5128122 * sin(F);
- dB += 280602 * sin(M1 + F);
- dB += 277693 * sin(M1 - F);
- dB += 173237 * sin(2 * D - F);
- dB += 55413 * sin(2 * D - M1 + F);
- dB += 46271 * sin(2 * D - M1 - F);
- dB += 32573 * sin(2 * D + F);
- dB += 17198 * sin(2 * M1 + F);
- dB += 9266 * sin(2 * D + M1 - F);
- dB += 8822 * sin(2 * M1 - F);
- dB += e * 8216 * sin(2 * D - M - F);
- dB += 4324 * sin(2 * D - 2 * M1 - F);
- bm = dB / 1000000 * RADS;
-
- dR = -20905355 * cos(M1);
- dR -= 3699111 * cos(2 * D - M1);
- dR -= 2955968 * cos(2 * D);
- dR -= 569925 * cos(2 * M1);
- dR += e * 48888 * cos(M);
- dR -= 3149 * cos(2 * F);
- dR += 246158 * cos(2 * D - 2 * M1);
- dR -= e * 152138 * cos(2 * D - M - M1) ;
- dR -= 170733 * cos(2 * D + M1);
- dR -= e * 204586 * cos(2 * D - M);
- dR -= e * 129620 * cos(M - M1);
- dR += 108743 * cos(D);
- dR += e * 104755 * cos(M + M1);
- dR += 79661 * cos(M1 - 2 * F);
- rm = 385000.56 + dR / 1000;
-
- *lambda = lm;
- *beta = bm;
- /* distance to Moon must be in Earth radii */
- *rvec = rm / 6378.14;
-}
-
-/*
-topomoon() takes the local siderial time, the geographical
-latitude of the observer, and pointers to the geocentric
-equatorial coordinates. The function overwrites the geocentric
-coordinates with topocentric coordinates on a simple spherical
-earth model (no polar flattening). Expects Moon-Earth distance in
-Earth radii. Formulas scavenged from Astronomical Almanac 'low
-precision formulae for Moon position' page D46.
-*/
-
-void topo(double lst, double glat, double *alp, double *dec, double *r) {
- double x, y, z, r1;
- x = *r * cos(*dec) * cos(*alp) - cos(glat) * cos(lst);
- y = *r * cos(*dec) * sin(*alp) - cos(glat) * sin(lst);
- z = *r * sin(*dec) - sin(glat);
- r1 = sqrt(x*x + y*y + z*z);
- *alp = atan22(y, x);
- *dec = asin(z / r1);
- *r = r1;
-}
-
-/*
-moontransit() takes date, the time zone and geographic longitude
-of observer and returns the time (decimal hours) of lunar transit
-on that day if there is one, and sets the notransit flag if there
-isn't. See Explanatory Supplement to Astronomical Almanac
-section 9.32 and 9.31 for the method.
-*/
-
-double moontransit(int y, int m, int d, double tz, double glat, double glong, int *notransit) {
- double hm, ht, ht1, lon, lat, rv, dnew, lst;
- int itcount;
-
- ht1 = 180 * RADS;
- ht = 0;
- itcount = 0;
- *notransit = 0;
- do {
- ht = ht1;
- itcount++;
- dnew = days(y, m, d, ht * DEGS/15) - tz/24;
- lst = gst(dnew) + glong;
- /* find the topocentric Moon ra (hence hour angle) and dec */
- moonpos(dnew, &lon, &lat, &rv);
- equatorial(dnew, &lon, &lat, &rv);
- topo(lst, glat, &lon, &lat, &rv);
- hm = rangerad(lst - lon);
- ht1 = rangerad(ht - hm);
- /* if no convergence, then no transit on that day */
- if (itcount > 30) {
- *notransit = 1;
- break;
- }
- }
- while (fabs(ht - ht1) > 0.04 * RADS);
- return(ht1);
-}
-
-/*
- Calculates the selenographic coordinates of either the sub Earth point
- (optical libration) or the sub-solar point (selen. coords of centre of
- bright hemisphere). Based on Meeus chapter 51 but neglects physical
- libration and nutation, with some simplification of the formulas.
-*/
-void libration(double day, double lambda, double beta, double alpha, double *l, double *b, double *p) {
- double i, f, omega, w, y, x, a, t, eps;
- t = day / 36525;
- i = 1.54242 * RADS;
- eps = epsilon(day);
- f = range(93.2720993 + 483202.0175273 * t - .0034029 * t * t) * RADS;
- omega = range(125.044555 - 1934.1361849 * t + .0020762 * t * t) * RADS;
- w = lambda - omega;
- y = sin(w) * cos(beta) * cos(i) - sin(beta) * sin(i);
- x = cos(w) * cos(beta);
- a = atan22(y, x);
- *l = a - f;
-
- /* kludge to catch cases of 'round the back' angles */
- if (*l < -90 * RADS) *l += TPI;
- if (*l > 90 * RADS) *l -= TPI;
- *b = asin(-sin(w) * cos(beta) * sin(i) - sin(beta) * cos(i));
-
- /* pa pole axis - not used for Sun stuff */
- x = sin(i) * sin(omega);
- y = sin(i) * cos(omega) * cos(eps) - cos(i) * sin(eps);
- w = atan22(x, y);
- *p = rangerad(asin(sqrt(x*x + y*y) * cos(alpha - w) / cos(*b)));
-}
-
-/*
- Takes: days since J2000.0, eq coords Moon, ratio of moon to sun distance,
- eq coords Sun
- Returns: position angle of bright limb wrt NCP, percentage illumination
- of Sun
-*/
-void illumination(double day, double lra, double ldec, double dr, double sra, double sdec, double *pabl, double *ill) {
- double x, y, phi, i;
- y = cos(sdec) * sin(sra - lra);
- x = sin(sdec) * cos(ldec) - cos(sdec) * sin(ldec) * cos (sra - lra);
- *pabl = atan22(y, x);
- phi = acos(sin(sdec) * sin(ldec) + cos(sdec) * cos(ldec) * cos(sra-lra));
- i = atan22(sin(phi) , (dr - cos(phi)));
- *ill = 0.5*(1 + cos(i));
-}
-
-/*
-sunpos() takes days from J2000.0 and returns ecliptic longitude
-of Sun in the pointers. Latitude is zero at this level of precision,
-but pointer left in for consistency in number of arguments.
-This function is within 0.01 degree (1 arcmin) almost all the time
-for a century either side of J2000.0. This is from the 'low precision
-fomulas for the Sun' from C24 of Astronomical Alamanac
-*/
-void sunpos(double d, double *lambda, double *beta, double *rvec) {
- double L, g, ls, bs, rs;
-
- L = range(280.461 + .9856474 * d) * RADS;
- g = range(357.528 + .9856003 * d) * RADS;
- ls = L + (1.915 * sin(g) + .02 * sin(2 * g)) * RADS;
- bs = 0;
- rs = 1.00014 - .01671 * cos(g) - .00014 * cos(2 * g);
- *lambda = ls;
- *beta = bs;
- *rvec = rs;
-}
-
-/*
-this routine returns the altitude given the days since J2000.0
-the hour angle and declination of the object and the latitude
-of the observer. Used to find the Sun's altitude to put a letter
-code on the transit time, and to find the Moon's altitude at
-transit just to make sure that the Moon is visible.
-*/
-double alt(double glat, double ha, double dec) {
- return(asin(sin(dec) * sin(glat) + cos(dec) * cos(glat) * cos(ha)));
-}
-
-/* returns an angle in degrees in the range 0 to 360 */
-double range(double x) {
- double a, b;
- b = x / 360;
- a = 360 * (b - floor(b));
- if (a < 0)
- a = 360 + a;
- return(a);
-}
-
-/* returns an angle in rads in the range 0 to two pi */
-double rangerad(double x) {
- double a, b;
- b = x / TPI;
- a = TPI * (b - floor(b));
- if (a < 0)
- a = TPI + a;
- return(a);
-}
-
-/*
-gets the atan2 function returning angles in the right
-order and range
-*/
-double atan22(double y, double x) {
- double a;
-
- a = atan2(y, x);
- if (a < 0) a += TPI;
- return(a);
-}
-
-/*
-returns mean obliquity of ecliptic in radians given days since
-J2000.0.
-*/
-double epsilon(double d) {
- double t = d/ 36525;
- return((23.4392911111111 - (t* (46.8150 + 0.00059*t)/3600)) *RADS);
-}
-
-/*
-replaces ecliptic coordinates with equatorial coordinates
-note: call by reference destroys original values
-R is unchanged.
-*/
-void equatorial(double d, double *lon, double *lat, double *r) {
- double eps, ceps, seps, l, b;
-
- l = *lon;
- b = * lat;
- eps = epsilon(d);
- ceps = cos(eps);
- seps = sin(eps);
- *lon = atan22(sin(l)*ceps - tan(b)*seps, cos(l));
- *lat = asin(sin(b)*ceps + cos(b)*seps*sin(l));
-}
-
-/*
-replaces equatorial coordinates with ecliptic ones. Inverse
-of above, but used to find topocentric ecliptic coords.
-*/
-void ecliptic(double d, double *lon, double *lat, double *r) {
- double eps, ceps, seps, alp, dec;
- alp = *lon;
- dec = *lat;
- eps = epsilon(d);
- ceps = cos(eps);
- seps = sin(eps);
- *lon = atan22(sin(alp)*ceps + tan(dec)*seps, cos(alp));
- *lat = asin(sin(dec)*ceps - cos(dec)*seps*sin(alp));
-}
-
-/*
-returns the siderial time at greenwich meridian as
-an angle in radians given the days since J2000.0
-*/
-double gst( double d) {
- double t = d / 36525;
- double theta;
- theta = range(280.46061837 + 360.98564736629 * d + 0.000387933 * t * t);
- return(theta * RADS);
-}
-
-void tmoonsub_(double *day, double *glat, double *glong, double *moonalt,
- double *mrv, double *l, double *b, double *paxis)
-{
- double mlambda, mbeta;
- double malpha, mdelta;
- double lst, mhr;
- double tlambda, tbeta, trv;
-
- lst = gst(*day) + *glong;
-
- /* find Moon topocentric coordinates for libration calculations */
-
- moonpos(*day, &mlambda, &mbeta, mrv);
- malpha = mlambda;
- mdelta = mbeta;
- equatorial(*day, &malpha, &mdelta, mrv);
- topo(lst, *glat, &malpha, &mdelta, mrv);
- mhr = rangerad(lst - malpha);
- *moonalt = alt(*glat, mhr, mdelta);
-
- /* Optical libration and Position angle of the Pole */
-
- tlambda = malpha;
- tbeta = mdelta;
- trv = *mrv;
- ecliptic(*day, &tlambda, &tbeta, &trv);
- libration(*day, tlambda, tbeta, malpha, l, b, paxis);
-}
+#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#define RADS 0.0174532925199433 +#define DEGS 57.2957795130823 +#define TPI 6.28318530717959 +#define PI 3.1415927 + +/* ratio of earth radius to astronomical unit */ +#define ER_OVER_AU 0.0000426352325194252 + +/* all prototypes here */ + +double getcoord(int coord); +void getargs(int argc, char *argv[], int *y, int *m, double *tz, double *glong, double *glat); +double range(double y); +double rangerad(double y); +double days(int y, int m, int dn, double hour); +double days_(int *y, int *m, int *dn, double *hour); +void moonpos(double, double *, double *, double *); +void sunpos(double , double *, double *, double *); +double moontransit(int y, int m, int d, double timezone, double glat, double glong, int *nt); +double atan22(double y, double x); +double epsilon(double d); +void equatorial(double d, double *lon, double *lat, double *r); +void ecliptic(double d, double *lon, double *lat, double *r); +double gst(double d); +void topo(double lst, double glat, double *alp, double *dec, double *r); +double alt(double glat, double ha, double dec); +void libration(double day, double lambda, double beta, double alpha, double *l, double *b, double *p); +void illumination(double day, double lra, double ldec, double dr, double sra, double sdec, double *pabl, double *ill); +int daysinmonth(int y, int m); +int isleap(int y); +void tmoonsub_(double *day, double *glat, double *glong, double *moonalt, + double *mrv, double *l, double *b, double *paxis); + +static const char +*usage = " Usage: tmoon date[yyyymm] timz[+/-h.hh] long[+/-dddmm] lat[+/-ddmm]\n" + "example: tmoon 200009 0 -00155 5230\n"; + +/* + getargs() gets the arguments from the command line, does some basic error + checking, and converts arguments into numerical form. Arguments are passed + back in pointers. Error messages print to stderr so re-direction of output + to file won't leave users blind. Error checking prints list of all errors + in a command line before quitting. +*/ +void getargs(int argc, char *argv[], int *y, int *m, double *tz, + double *glong, double *glat) { + + int date, latitude, longitude; + int mflag = 0, yflag = 0, longflag = 0, latflag = 0, tzflag = 0; + int longminflag = 0, latminflag = 0, dflag = 0; + + /* if not right number of arguments, then print example command line */ + + if (argc !=5) { + fprintf(stderr, usage); + exit(EXIT_FAILURE); + } + + date = atoi(argv[1]); + *y = date / 100; + *m = date - *y * 100; + *tz = (double) atof(argv[2]); + longitude = atoi(argv[3]); + latitude = atoi(argv[4]); + *glong = RADS * getcoord(longitude); + *glat = RADS * getcoord(latitude); + + /* set a flag for each error found */ + + if (*m > 12 || *m < 1) mflag = 1; + if (*y > 2500) yflag = 1; + if (date < 150001) dflag = 1; + if (fabs((float) *glong) > 180 * RADS) longflag = 1; + if (abs(longitude) % 100 > 59) longminflag = 1; + if (fabs((float) *glat) > 90 * RADS) latflag = 1; + if (abs(latitude) % 100 > 59) latminflag = 1; + if (fabs((float) *tz) > 12) tzflag = 1; + + /* print all the errors found */ + + if (dflag == 1) { + fprintf(stderr, "date: dates must be in form yyyymm, gregorian, and later than 1500 AD\n"); + } + if (yflag == 1) { + fprintf(stderr, "date: too far in future - accurate from 1500 to 2500\n"); + } + if (mflag == 1) { + fprintf(stderr, "date: month must be in range 0 to 12, eg - August 2000 is entered as 200008\n"); + } + if (tzflag == 1) { + fprintf(stderr, "timz: must be in range +/- 12 hours, eg -6 for Chicago\n"); + } + if (longflag == 1) { + fprintf(stderr, "long: must be in range +/- 180 degrees\n"); + } + if (longminflag == 1) { + fprintf(stderr, "long: last two digits are arcmin - max 59\n"); + } + if (latflag == 1) { + fprintf(stderr, " lat: must be in range +/- 90 degrees\n"); + } + if (latminflag == 1) { + fprintf(stderr, " lat: last two digits are arcmin - max 59\n"); + } + + /* quits if one or more flags set */ + + if (dflag + mflag + yflag + longflag + latflag + tzflag + longminflag + latminflag > 0) { + exit(EXIT_FAILURE); + } + +} + +/* + returns coordinates in decimal degrees given the + coord as a ddmm value stored in an integer. +*/ +double getcoord(int coord) { + int west = 1; + double glg, deg; + if (coord < 0) west = -1; + glg = fabs((double) coord/100); + deg = floor(glg); + glg = west* (deg + (glg - deg)*100 / 60); + return(glg); +} + +/* + days() takes the year, month, day in the month and decimal hours + in the day and returns the number of days since J2000.0. + Assumes Gregorian calendar. +*/ +double days(int y, int m, int d, double h) { + int a, b; + double day; + + /* + The lines below work from 1900 march to feb 2100 + a = 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d; + day = (double)a - 730531.5 + hour / 24; + */ + + /* These lines work for any Gregorian date since 0 AD */ + if (m ==1 || m==2) { + m +=12; + y -= 1; + } + a = y / 100; + b = 2 - a + a/4; + day = floor(365.25*(y + 4716)) + floor(30.6001*(m + 1)) + + d + b - 1524.5 - 2451545 + h/24; + return(day); +} +double days_(int *y0, int *m0, int *d0, double *h0) +{ + return days(*y0,*m0,*d0,*h0); +} + +/* +Returns 1 if y a leap year, and 0 otherwise, according +to the Gregorian calendar +*/ +int isleap(int y) { + int a = 0; + if(y % 4 == 0) a = 1; + if(y % 100 == 0) a = 0; + if(y % 400 == 0) a = 1; + return(a); +} + +/* +Given the year and the month, function returns the +number of days in the month. Valid for Gregorian +calendar. +*/ +int daysinmonth(int y, int m) { + int b = 31; + if(m == 2) { + if(isleap(y) == 1) b= 29; + else b = 28; + } + if(m == 4 || m == 6 || m == 9 || m == 11) b = 30; + return(b); +} + +/* +moonpos() takes days from J2000.0 and returns ecliptic coordinates +of moon in the pointers. Note call by reference. +This function is within a couple of arcminutes most of the time, +and is truncated from the Meeus Ch45 series, themselves truncations of +ELP-2000. Returns moon distance in earth radii. +Terms have been written out explicitly rather than using the +table based method as only a small number of terms is +retained. +*/ +void moonpos(double d, double *lambda, double *beta, double *rvec) { + double dl, dB, dR, L, D, M, M1, F, e, lm, bm, rm, t; + + t = d / 36525; + + L = range(218.3164591 + 481267.88134236 * t) * RADS; + D = range(297.8502042 + 445267.1115168 * t) * RADS; + M = range(357.5291092 + 35999.0502909 * t) * RADS; + M1 = range(134.9634114 + 477198.8676313 * t - .008997 * t * t) * RADS; + F = range(93.27209929999999 + 483202.0175273 * t - .0034029*t*t)*RADS; + e = 1 - .002516 * t; + + dl = 6288774 * sin(M1); + dl += 1274027 * sin(2 * D - M1); + dl += 658314 * sin(2 * D); + dl += 213618 * sin(2 * M1); + dl -= e * 185116 * sin(M); + dl -= 114332 * sin(2 * F) ; + dl += 58793 * sin(2 * D - 2 * M1); + dl += e * 57066 * sin(2 * D - M - M1) ; + dl += 53322 * sin(2 * D + M1); + dl += e * 45758 * sin(2 * D - M); + dl -= e * 40923 * sin(M - M1); + dl -= 34720 * sin(D) ; + dl -= e * 30383 * sin(M + M1) ; + dl += 15327 * sin(2 * D - 2 * F) ; + dl -= 12528 * sin(M1 + 2 * F); + dl += 10980 * sin(M1 - 2 * F); + lm = rangerad(L + dl / 1000000 * RADS); + + dB = 5128122 * sin(F); + dB += 280602 * sin(M1 + F); + dB += 277693 * sin(M1 - F); + dB += 173237 * sin(2 * D - F); + dB += 55413 * sin(2 * D - M1 + F); + dB += 46271 * sin(2 * D - M1 - F); + dB += 32573 * sin(2 * D + F); + dB += 17198 * sin(2 * M1 + F); + dB += 9266 * sin(2 * D + M1 - F); + dB += 8822 * sin(2 * M1 - F); + dB += e * 8216 * sin(2 * D - M - F); + dB += 4324 * sin(2 * D - 2 * M1 - F); + bm = dB / 1000000 * RADS; + + dR = -20905355 * cos(M1); + dR -= 3699111 * cos(2 * D - M1); + dR -= 2955968 * cos(2 * D); + dR -= 569925 * cos(2 * M1); + dR += e * 48888 * cos(M); + dR -= 3149 * cos(2 * F); + dR += 246158 * cos(2 * D - 2 * M1); + dR -= e * 152138 * cos(2 * D - M - M1) ; + dR -= 170733 * cos(2 * D + M1); + dR -= e * 204586 * cos(2 * D - M); + dR -= e * 129620 * cos(M - M1); + dR += 108743 * cos(D); + dR += e * 104755 * cos(M + M1); + dR += 79661 * cos(M1 - 2 * F); + rm = 385000.56 + dR / 1000; + + *lambda = lm; + *beta = bm; + /* distance to Moon must be in Earth radii */ + *rvec = rm / 6378.14; +} + +/* +topomoon() takes the local siderial time, the geographical +latitude of the observer, and pointers to the geocentric +equatorial coordinates. The function overwrites the geocentric +coordinates with topocentric coordinates on a simple spherical +earth model (no polar flattening). Expects Moon-Earth distance in +Earth radii. Formulas scavenged from Astronomical Almanac 'low +precision formulae for Moon position' page D46. +*/ + +void topo(double lst, double glat, double *alp, double *dec, double *r) { + double x, y, z, r1; + x = *r * cos(*dec) * cos(*alp) - cos(glat) * cos(lst); + y = *r * cos(*dec) * sin(*alp) - cos(glat) * sin(lst); + z = *r * sin(*dec) - sin(glat); + r1 = sqrt(x*x + y*y + z*z); + *alp = atan22(y, x); + *dec = asin(z / r1); + *r = r1; +} + +/* +moontransit() takes date, the time zone and geographic longitude +of observer and returns the time (decimal hours) of lunar transit +on that day if there is one, and sets the notransit flag if there +isn't. See Explanatory Supplement to Astronomical Almanac +section 9.32 and 9.31 for the method. +*/ + +double moontransit(int y, int m, int d, double tz, double glat, double glong, int *notransit) { + double hm, ht, ht1, lon, lat, rv, dnew, lst; + int itcount; + + ht1 = 180 * RADS; + ht = 0; + itcount = 0; + *notransit = 0; + do { + ht = ht1; + itcount++; + dnew = days(y, m, d, ht * DEGS/15) - tz/24; + lst = gst(dnew) + glong; + /* find the topocentric Moon ra (hence hour angle) and dec */ + moonpos(dnew, &lon, &lat, &rv); + equatorial(dnew, &lon, &lat, &rv); + topo(lst, glat, &lon, &lat, &rv); + hm = rangerad(lst - lon); + ht1 = rangerad(ht - hm); + /* if no convergence, then no transit on that day */ + if (itcount > 30) { + *notransit = 1; + break; + } + } + while (fabs(ht - ht1) > 0.04 * RADS); + return(ht1); +} + +/* + Calculates the selenographic coordinates of either the sub Earth point + (optical libration) or the sub-solar point (selen. coords of centre of + bright hemisphere). Based on Meeus chapter 51 but neglects physical + libration and nutation, with some simplification of the formulas. +*/ +void libration(double day, double lambda, double beta, double alpha, double *l, double *b, double *p) { + double i, f, omega, w, y, x, a, t, eps; + t = day / 36525; + i = 1.54242 * RADS; + eps = epsilon(day); + f = range(93.2720993 + 483202.0175273 * t - .0034029 * t * t) * RADS; + omega = range(125.044555 - 1934.1361849 * t + .0020762 * t * t) * RADS; + w = lambda - omega; + y = sin(w) * cos(beta) * cos(i) - sin(beta) * sin(i); + x = cos(w) * cos(beta); + a = atan22(y, x); + *l = a - f; + + /* kludge to catch cases of 'round the back' angles */ + if (*l < -90 * RADS) *l += TPI; + if (*l > 90 * RADS) *l -= TPI; + *b = asin(-sin(w) * cos(beta) * sin(i) - sin(beta) * cos(i)); + + /* pa pole axis - not used for Sun stuff */ + x = sin(i) * sin(omega); + y = sin(i) * cos(omega) * cos(eps) - cos(i) * sin(eps); + w = atan22(x, y); + *p = rangerad(asin(sqrt(x*x + y*y) * cos(alpha - w) / cos(*b))); +} + +/* + Takes: days since J2000.0, eq coords Moon, ratio of moon to sun distance, + eq coords Sun + Returns: position angle of bright limb wrt NCP, percentage illumination + of Sun +*/ +void illumination(double day, double lra, double ldec, double dr, double sra, double sdec, double *pabl, double *ill) { + double x, y, phi, i; + y = cos(sdec) * sin(sra - lra); + x = sin(sdec) * cos(ldec) - cos(sdec) * sin(ldec) * cos (sra - lra); + *pabl = atan22(y, x); + phi = acos(sin(sdec) * sin(ldec) + cos(sdec) * cos(ldec) * cos(sra-lra)); + i = atan22(sin(phi) , (dr - cos(phi))); + *ill = 0.5*(1 + cos(i)); +} + +/* +sunpos() takes days from J2000.0 and returns ecliptic longitude +of Sun in the pointers. Latitude is zero at this level of precision, +but pointer left in for consistency in number of arguments. +This function is within 0.01 degree (1 arcmin) almost all the time +for a century either side of J2000.0. This is from the 'low precision +fomulas for the Sun' from C24 of Astronomical Alamanac +*/ +void sunpos(double d, double *lambda, double *beta, double *rvec) { + double L, g, ls, bs, rs; + + L = range(280.461 + .9856474 * d) * RADS; + g = range(357.528 + .9856003 * d) * RADS; + ls = L + (1.915 * sin(g) + .02 * sin(2 * g)) * RADS; + bs = 0; + rs = 1.00014 - .01671 * cos(g) - .00014 * cos(2 * g); + *lambda = ls; + *beta = bs; + *rvec = rs; +} + +/* +this routine returns the altitude given the days since J2000.0 +the hour angle and declination of the object and the latitude +of the observer. Used to find the Sun's altitude to put a letter +code on the transit time, and to find the Moon's altitude at +transit just to make sure that the Moon is visible. +*/ +double alt(double glat, double ha, double dec) { + return(asin(sin(dec) * sin(glat) + cos(dec) * cos(glat) * cos(ha))); +} + +/* returns an angle in degrees in the range 0 to 360 */ +double range(double x) { + double a, b; + b = x / 360; + a = 360 * (b - floor(b)); + if (a < 0) + a = 360 + a; + return(a); +} + +/* returns an angle in rads in the range 0 to two pi */ +double rangerad(double x) { + double a, b; + b = x / TPI; + a = TPI * (b - floor(b)); + if (a < 0) + a = TPI + a; + return(a); +} + +/* +gets the atan2 function returning angles in the right +order and range +*/ +double atan22(double y, double x) { + double a; + + a = atan2(y, x); + if (a < 0) a += TPI; + return(a); +} + +/* +returns mean obliquity of ecliptic in radians given days since +J2000.0. +*/ +double epsilon(double d) { + double t = d/ 36525; + return((23.4392911111111 - (t* (46.8150 + 0.00059*t)/3600)) *RADS); +} + +/* +replaces ecliptic coordinates with equatorial coordinates +note: call by reference destroys original values +R is unchanged. +*/ +void equatorial(double d, double *lon, double *lat, double *r) { + double eps, ceps, seps, l, b; + + l = *lon; + b = * lat; + eps = epsilon(d); + ceps = cos(eps); + seps = sin(eps); + *lon = atan22(sin(l)*ceps - tan(b)*seps, cos(l)); + *lat = asin(sin(b)*ceps + cos(b)*seps*sin(l)); +} + +/* +replaces equatorial coordinates with ecliptic ones. Inverse +of above, but used to find topocentric ecliptic coords. +*/ +void ecliptic(double d, double *lon, double *lat, double *r) { + double eps, ceps, seps, alp, dec; + alp = *lon; + dec = *lat; + eps = epsilon(d); + ceps = cos(eps); + seps = sin(eps); + *lon = atan22(sin(alp)*ceps + tan(dec)*seps, cos(alp)); + *lat = asin(sin(dec)*ceps - cos(dec)*seps*sin(alp)); +} + +/* +returns the siderial time at greenwich meridian as +an angle in radians given the days since J2000.0 +*/ +double gst( double d) { + double t = d / 36525; + double theta; + theta = range(280.46061837 + 360.98564736629 * d + 0.000387933 * t * t); + return(theta * RADS); +} + +void tmoonsub_(double *day, double *glat, double *glong, double *moonalt, + double *mrv, double *l, double *b, double *paxis) +{ + double mlambda, mbeta; + double malpha, mdelta; + double lst, mhr; + double tlambda, tbeta, trv; + + lst = gst(*day) + *glong; + + /* find Moon topocentric coordinates for libration calculations */ + + moonpos(*day, &mlambda, &mbeta, mrv); + malpha = mlambda; + mdelta = mbeta; + equatorial(*day, &malpha, &mdelta, mrv); + topo(lst, *glat, &malpha, &mdelta, mrv); + mhr = rangerad(lst - malpha); + *moonalt = alt(*glat, mhr, mdelta); + + /* Optical libration and Position angle of the Pole */ + + tlambda = malpha; + tbeta = mdelta; + trv = *mrv; + ecliptic(*day, &tlambda, &tbeta, &trv); + libration(*day, tlambda, tbeta, malpha, l, b, paxis); +} diff --git a/map65/libm65/toxyz.f90 b/map65/libm65/toxyz.f90 index 82b8f851..aef160c9 100755..100644 --- a/map65/libm65/toxyz.f90 +++ b/map65/libm65/toxyz.f90 @@ -1,25 +1,25 @@ -subroutine toxyz(alpha,delta,r,vec)
-
- implicit real*8 (a-h,o-z)
- real*8 vec(3)
-
- vec(1)=r*cos(delta)*cos(alpha)
- vec(2)=r*cos(delta)*sin(alpha)
- vec(3)=r*sin(delta)
-
- return
-end subroutine toxyz
-
-subroutine fromxyz(vec,alpha,delta,r)
-
- implicit real*8 (a-h,o-z)
- real*8 vec(3)
- data twopi/6.283185307d0/
-
- r=sqrt(vec(1)**2 + vec(2)**2 + vec(3)**2)
- alpha=atan2(vec(2),vec(1))
- if(alpha.lt.0.d0) alpha=alpha+twopi
- delta=asin(vec(3)/r)
-
- return
-end subroutine fromxyz
+subroutine toxyz(alpha,delta,r,vec) + + implicit real*8 (a-h,o-z) + real*8 vec(3) + + vec(1)=r*cos(delta)*cos(alpha) + vec(2)=r*cos(delta)*sin(alpha) + vec(3)=r*sin(delta) + + return +end subroutine toxyz + +subroutine fromxyz(vec,alpha,delta,r) + + implicit real*8 (a-h,o-z) + real*8 vec(3) + data twopi/6.283185307d0/ + + r=sqrt(vec(1)**2 + vec(2)**2 + vec(3)**2) + alpha=atan2(vec(2),vec(1)) + if(alpha.lt.0.d0) alpha=alpha+twopi + delta=asin(vec(3)/r) + + return +end subroutine fromxyz diff --git a/map65/libm65/trimlist.f90 b/map65/libm65/trimlist.f90 index 42a44106..9e8a36e6 100755..100644 --- a/map65/libm65/trimlist.f90 +++ b/map65/libm65/trimlist.f90 @@ -1,28 +1,28 @@ -subroutine trimlist(sig,km,ftol,indx,nsiz,nz)
-
- parameter (MAXMSG=1000) !Size of decoded message list
- real sig(MAXMSG,30)
- integer indx(MAXMSG),nsiz(MAXMSG)
-
-! 1 2 3 4 5 6 7 8
-! nfile nutc freq snr dt ipol flip sync
-
- call indexx(sig(1,3),km,indx) !Sort list by frequency
-
- n=1
- i0=1
- do i=2,km
- j0=indx(i-1)
- j=indx(i)
- if(sig(j,3)-sig(j0,3).gt.ftol) then
- nsiz(n)=i-i0
- i0=i
- n=n+1
- endif
- enddo
- nz=n
- nsiz(nz)=km+1-i0
- nsiz(nz+1)=-1
-
- return
-end subroutine trimlist
+subroutine trimlist(sig,km,ftol,indx,nsiz,nz) + + parameter (MAXMSG=1000) !Size of decoded message list + real sig(MAXMSG,30) + integer indx(MAXMSG),nsiz(MAXMSG) + +! 1 2 3 4 5 6 7 8 +! nfile nutc freq snr dt ipol flip sync + + call indexx(sig(1,3),km,indx) !Sort list by frequency + + n=1 + i0=1 + do i=2,km + j0=indx(i-1) + j=indx(i) + if(sig(j,3)-sig(j0,3).gt.ftol) then + nsiz(n)=i-i0 + i0=i + n=n+1 + endif + enddo + nz=n + nsiz(nz)=km+1-i0 + nsiz(nz+1)=-1 + + return +end subroutine trimlist diff --git a/map65/libm65/twkfreq.f90 b/map65/libm65/twkfreq.f90 index 7c240d52..be1fef0f 100755..100644 --- a/map65/libm65/twkfreq.f90 +++ b/map65/libm65/twkfreq.f90 @@ -1,26 +1,26 @@ -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)
- 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))
- w=w*wstep
- c4(i)=w*c3(i)
- enddo
-
- return
-end subroutine twkfreq
+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) + 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)) + w=w*wstep + c4(i)=w*c3(i) + enddo + + return +end subroutine twkfreq diff --git a/map65/libm65/twkfreq_xy.f90 b/map65/libm65/twkfreq_xy.f90 index 1d79c973..a5cc3769 100755..100644 --- a/map65/libm65/twkfreq_xy.f90 +++ b/map65/libm65/twkfreq_xy.f90 @@ -1,29 +1,29 @@ -subroutine twkfreq_xy(c4aa,c4bb,n5,a)
-
- complex c4aa(n5)
- complex c4bb(n5)
- real a(5)
- complex w,wstep
- data twopi/6.283185307/
-
-! Apply AFC corrections to the c4aa and c4bb 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,1000).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/1378.125)
- wstep=cmplx(cos(dphi),sin(dphi))
- endif
- w=w*wstep
- c4aa(i)=w*c4aa(i)
- c4bb(i)=w*c4bb(i)
- enddo
-
- return
-end subroutine twkfreq_xy
+subroutine twkfreq_xy(c4aa,c4bb,n5,a) + + complex c4aa(n5) + complex c4bb(n5) + real a(5) + complex w,wstep + data twopi/6.283185307/ + +! Apply AFC corrections to the c4aa and c4bb 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,1000).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/1378.125) + wstep=cmplx(cos(dphi),sin(dphi)) + endif + w=w*wstep + c4aa(i)=w*c4aa(i) + c4bb(i)=w*c4bb(i) + enddo + + return +end subroutine twkfreq_xy diff --git a/map65/libm65/txpol.f90 b/map65/libm65/txpol.f90 index db602c2f..042d3e54 100755..100644 --- a/map65/libm65/txpol.f90 +++ b/map65/libm65/txpol.f90 @@ -1,33 +1,33 @@ -subroutine txpol(xpol,decoded,mygrid,npol,nxant,ntxpol,cp)
-
-! If Tx station's grid is in decoded message, compute optimum TxPol
- character*22 decoded
- character*6 mygrid,grid
- character*1 cp
- logical xpol
-
- ntxpol=0
- i1=index(decoded,' ')
- i2=index(decoded(i1+1:),' ') + i1
- grid=' '
- if(i2.ge.8 .and. i2.le.18) grid=decoded(i2+1:i2+4)//'mm'
- ntxpol=0
- cp=' '
- if(xpol .and.grid(1:4).ne.'RR73') then
- if(grid(1:1).ge.'A' .and. grid(1:1).le.'R' .and. &
- grid(2:2).ge.'A' .and. grid(2:2).le.'R' .and. &
- grid(3:3).ge.'0' .and. grid(3:3).le.'9' .and. &
- grid(4:4).ge.'0' .and. grid(4:4).le.'9') then
- ntxpol=mod(npol-nint(2.0*dpol(mygrid,grid))+720,180)
- if(nxant.eq.0) then
- cp='H'
- if(ntxpol.gt.45 .and. ntxpol.le.135) cp='V'
- else
- cp='/'
- if(ntxpol.ge.90 .and. ntxpol.lt.180) cp='\'
- endif
- endif
- endif
-
- return
-end subroutine txpol
+subroutine txpol(xpol,decoded,mygrid,npol,nxant,ntxpol,cp) + +! If Tx station's grid is in decoded message, compute optimum TxPol + character*22 decoded + character*6 mygrid,grid + character*1 cp + logical xpol + + ntxpol=0 + i1=index(decoded,' ') + i2=index(decoded(i1+1:),' ') + i1 + grid=' ' + if(i2.ge.8 .and. i2.le.18) grid=decoded(i2+1:i2+4)//'mm' + ntxpol=0 + cp=' ' + if(xpol .and.grid(1:4).ne.'RR73') then + if(grid(1:1).ge.'A' .and. grid(1:1).le.'R' .and. & + grid(2:2).ge.'A' .and. grid(2:2).le.'R' .and. & + grid(3:3).ge.'0' .and. grid(3:3).le.'9' .and. & + grid(4:4).ge.'0' .and. grid(4:4).le.'9') then + ntxpol=mod(npol-nint(2.0*dpol(mygrid,grid))+720,180) + if(nxant.eq.0) then + cp='H' + if(ntxpol.gt.45 .and. ntxpol.le.135) cp='V' + else + cp='/' + if(ntxpol.ge.90 .and. ntxpol.lt.180) cp='\' + endif + endif + endif + + return +end subroutine txpol diff --git a/map65/libm65/usleep.c b/map65/libm65/usleep.c index 6c7d6449..21d242a6 100755..100644 --- a/map65/libm65/usleep.c +++ b/map65/libm65/usleep.c @@ -1,7 +1,7 @@ -#include <unistd.h>
-
-/* usleep(3) */
-void usleep_(unsigned long *microsec)
-{
- usleep(*microsec);
-}
+#include <unistd.h> + +/* usleep(3) */ +void usleep_(unsigned long *microsec) +{ + usleep(*microsec); +} diff --git a/map65/libm65/wavhdr.f90 b/map65/libm65/wavhdr.f90 index d39048f8..6568c1fa 100755..100644 --- a/map65/libm65/wavhdr.f90 +++ b/map65/libm65/wavhdr.f90 @@ -1,110 +1,110 @@ -module wavhdr
- type hdr
- character*4 ariff
- integer*4 lenfile
- character*4 awave
- character*4 afmt
- integer*4 lenfmt
- integer*2 nfmt2
- integer*2 nchan2
- integer*4 nsamrate
- integer*4 nbytesec
- integer*2 nbytesam2
- integer*2 nbitsam2
- character*4 adata
- integer*4 ndata
- end type hdr
-
- contains
-
- function default_header(nsamrate,npts)
- type(hdr) default_header,h
- h%ariff='RIFF'
- h%awave='WAVE'
- h%afmt='fmt '
- h%lenfmt=16
- h%nfmt2=1
- h%nchan2=1
- h%nsamrate=nsamrate
- h%nbitsam2=16
- h%nbytesam2=h%nbitsam2 * h%nchan2 / 8
- h%adata='data'
- h%nbytesec=h%nsamrate * h%nbitsam2 * h%nchan2 / 8
- h%ndata=2*npts
- h%lenfile=h%ndata + 44 - 8
- default_header=h
- end function default_header
-
- subroutine set_wsjtx_wav_params(fMHz,mode,nsubmode,ntrperiod,id2)
-
- parameter (NBANDS=23,NMODES=13)
- character*8 mode,modes(NMODES)
- integer*2 id2(4)
- integer iperiod(8)
- real fband(NBANDS)
- data fband/0.137,0.474,1.8,3.5,5.1,7.0,10.14,14.0,18.1,21.0,24.9, &
- 28.0,50.0,144.0,222.0,432.0,902.0,1296.0,2304.0,3400.0, &
- 5760.0,10368.0,24048.0/
- data modes/'Echo','FSK441','ISCAT','JT4','JT65','JT6M','JT9', &
- 'JT9+JT65','JTMS','JTMSK','WSPR','FT8','FT2'/
- data iperiod/5,10,15,30,60,120,900,0/
-
- dmin=1.e30
- iband=0
- do i=1,NBANDS
- if(abs(fMHz-fband(i)).lt.dmin) then
- dmin=abs(fMHz-fband(i))
- iband=i
- endif
- enddo
-
- imode=0
- do i=1,NMODES
- if(mode.eq.modes(i)) imode=i
- enddo
-
- ip=0
- do i=1,8
- if(ntrperiod.eq.iperiod(i)) ip=i
- enddo
-
- id2(1)=iband
- id2(2)=imode
- id2(3)=nsubmode
- id2(4)=ip
-
- return
- end subroutine set_wsjtx_wav_params
-
- subroutine get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok)
-
- parameter (NBANDS=23,NMODES=13)
- character*8 mode,modes(NMODES)
- character*6 band,bands(NBANDS)
- integer*2 id2(4)
- integer iperiod(8)
- logical ok
- data modes/'Echo','FSK441','ISCAT','JT4','JT65','JT6M','JT9', &
- 'JT9+JT65','JTMS','JTMSK','WSPR','FT8','FT2'/
- data iperiod/5,10,15,30,60,120,900,0/
- data bands/'2190m','630m','160m','80m','60m','40m','30m','20m', &
- '17m','15m','12m','10m','6m','2m','1.25m','70cm','33cm', &
- '23cm','13cm','9cm','6cm','3cm','1.25cm'/
-
- ok=.true.
- if(id2(1).lt.1 .or. id2(1).gt.NBANDS) ok=.false.
- if(id2(2).lt.1 .or. id2(2).gt.NMODES) ok=.false.
- if(id2(3).lt.1 .or. id2(3).gt.8) ok=.false.
- if(id2(4).lt.1 .or. id2(4).gt.8) ok=.false.
-
- if(ok) then
- band=bands(id2(1))
- mode=modes(id2(2))
- nsubmode=id2(3)
- ntrperiod=iperiod(id2(4))
- endif
-
- return
- end subroutine get_wsjtx_wav_params
-
-end module wavhdr
+module wavhdr + type hdr + character*4 ariff + integer*4 lenfile + character*4 awave + character*4 afmt + integer*4 lenfmt + integer*2 nfmt2 + integer*2 nchan2 + integer*4 nsamrate + integer*4 nbytesec + integer*2 nbytesam2 + integer*2 nbitsam2 + character*4 adata + integer*4 ndata + end type hdr + + contains + + function default_header(nsamrate,npts) + type(hdr) default_header,h + h%ariff='RIFF' + h%awave='WAVE' + h%afmt='fmt ' + h%lenfmt=16 + h%nfmt2=1 + h%nchan2=1 + h%nsamrate=nsamrate + h%nbitsam2=16 + h%nbytesam2=h%nbitsam2 * h%nchan2 / 8 + h%adata='data' + h%nbytesec=h%nsamrate * h%nbitsam2 * h%nchan2 / 8 + h%ndata=2*npts + h%lenfile=h%ndata + 44 - 8 + default_header=h + end function default_header + + subroutine set_wsjtx_wav_params(fMHz,mode,nsubmode,ntrperiod,id2) + + parameter (NBANDS=23,NMODES=13) + character*8 mode,modes(NMODES) + integer*2 id2(4) + integer iperiod(8) + real fband(NBANDS) + data fband/0.137,0.474,1.8,3.5,5.1,7.0,10.14,14.0,18.1,21.0,24.9, & + 28.0,50.0,144.0,222.0,432.0,902.0,1296.0,2304.0,3400.0, & + 5760.0,10368.0,24048.0/ + data modes/'Echo','FSK441','ISCAT','JT4','JT65','JT6M','JT9', & + 'JT9+JT65','JTMS','JTMSK','WSPR','FT8','FT2'/ + data iperiod/5,10,15,30,60,120,900,0/ + + dmin=1.e30 + iband=0 + do i=1,NBANDS + if(abs(fMHz-fband(i)).lt.dmin) then + dmin=abs(fMHz-fband(i)) + iband=i + endif + enddo + + imode=0 + do i=1,NMODES + if(mode.eq.modes(i)) imode=i + enddo + + ip=0 + do i=1,8 + if(ntrperiod.eq.iperiod(i)) ip=i + enddo + + id2(1)=iband + id2(2)=imode + id2(3)=nsubmode + id2(4)=ip + + return + end subroutine set_wsjtx_wav_params + + subroutine get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) + + parameter (NBANDS=23,NMODES=13) + character*8 mode,modes(NMODES) + character*6 band,bands(NBANDS) + integer*2 id2(4) + integer iperiod(8) + logical ok + data modes/'Echo','FSK441','ISCAT','JT4','JT65','JT6M','JT9', & + 'JT9+JT65','JTMS','JTMSK','WSPR','FT8','FT2'/ + data iperiod/5,10,15,30,60,120,900,0/ + data bands/'2190m','630m','160m','80m','60m','40m','30m','20m', & + '17m','15m','12m','10m','6m','2m','1.25m','70cm','33cm', & + '23cm','13cm','9cm','6cm','3cm','1.25cm'/ + + ok=.true. + if(id2(1).lt.1 .or. id2(1).gt.NBANDS) ok=.false. + if(id2(2).lt.1 .or. id2(2).gt.NMODES) ok=.false. + if(id2(3).lt.1 .or. id2(3).gt.8) ok=.false. + if(id2(4).lt.1 .or. id2(4).gt.8) ok=.false. + + if(ok) then + band=bands(id2(1)) + mode=modes(id2(2)) + nsubmode=id2(3) + ntrperiod=iperiod(id2(4)) + endif + + return + end subroutine get_wsjtx_wav_params + +end module wavhdr diff --git a/map65/libm65/wideband_sync.f90 b/map65/libm65/wideband_sync.f90 index 009b3b00..31a96d2c 100755..100644 --- a/map65/libm65/wideband_sync.f90 +++ b/map65/libm65/wideband_sync.f90 @@ -1,281 +1,281 @@ -module wideband_sync
-
- type candidate
- real :: snr !Relative S/N of sync detection
- real :: f !Freq of sync tone, 0 to 96000 Hz
- real :: xdt !DT of matching sync pattern, -1.0 to +4.0 s
- real :: pol !Polarization angle, degrees
- integer :: ipol !Polarization angle, 1 to 4 ==> 0, 45, 90, 135 deg
- integer :: iflip !Sync type: JT65 = +/- 1, Q65 = 0
- integer :: indx
- end type candidate
- type sync_dat
- real :: ccfmax
- real :: xdt
- real :: pol
- integer :: ipol
- integer :: iflip
- logical :: birdie
- end type sync_dat
-
- parameter (NFFT=32768)
- parameter (MAX_CANDIDATES=50)
- parameter (SNR1_THRESHOLD=4.5)
- type(sync_dat) :: sync(NFFT)
- integer nkhz_center
-
- contains
-
-subroutine get_candidates(ss,savg,xpol,jz,nfa,nfb,nts_jt65,nts_q65,cand,ncand)
-
-! Search symbol spectra ss() over frequency range nfa to nfb (in kHz) for
-! JT65 and Q65 sync patterns. The nts_* variables are the submode tone
-! spacings: 1 2 4 8 16 for A B C D E. Birdies are detected and
-! excised. Candidates are returned in the structure array cand().
-
- parameter (MAX_PEAKS=100)
- real ss(4,322,NFFT),savg(4,NFFT)
- real pavg(-20:20)
- integer indx(NFFT)
- logical xpol,skip,ldecoded
- type(candidate) :: cand(MAX_CANDIDATES)
- common/early/nhsym1,nhsym2,ldecoded(32768)
-
- call wb_sync(ss,savg,xpol,jz,nfa,nfb) !Output to sync() array
-
- tstep=2048.0/11025.0 !0.185760 s: 0.5*tsym_jt65, 0.3096*tsym_q65
- df3=96000.0/NFFT
- ia=nint(1000*nfa/df3) + 1
- ib=nint(1000*nfb/df3) + 1
- if(ia.lt.1) ia=1
- if(ib.gt.NFFT-1) ib=NFFT-1
- iz=ib-ia+1
-
- call indexx(sync(ia:ib)%ccfmax,iz,indx) !Sort by relative snr
-
- k=0
- do i=1,MAX_PEAKS
- n=indx(iz+1-i) + ia - 1
- f0=0.001*(n-1)*df3
- snr1=sync(n)%ccfmax
- if(snr1.lt.SNR1_THRESHOLD) exit
- flip=sync(n)%iflip
- if(flip.ne.0.0 .and. nts_jt65.eq.0) cycle
- if(flip.eq.0.0 .and. nts_q65.eq.0) cycle
- if(sync(n)%birdie) cycle
-
-! Test for signal outside of TxT range and set bw for this signal type
- j1=(sync(n)%xdt + 1.0)/tstep - 1.0
- j2=(sync(n)%xdt + 52.0)/tstep + 1.0
- if(flip.ne.0) j2=(sync(n)%xdt + 47.811)/tstep + 1.0
- ipol=sync(n)%ipol
- pavg=0.
- do j=1,j1
- pavg=pavg + ss(ipol,j,n-20:n+20)
- enddo
- do j=j2,jz
- pavg=pavg + ss(ipol,j,n-20:n+20)
- enddo
- jsum=j1 + (jz-j2+1)
- pmax=maxval(pavg(-2:2)) !### Why not just pavg(0) ?
- base=(sum(pavg)-pmax)/jsum
- pmax=pmax/base
- if(pmax.gt.5.0) cycle
- skip=.false.
- do m=1,k !Skip false syncs within signal bw
- diffhz=1000.0*(f0-cand(m)%f)
- bw=nts_q65*110.0
- if(cand(m)%iflip.ne.0) bw=nts_jt65*178.0
- if(diffhz.gt.-0.03*bw .and. diffhz.lt.1.03*bw) skip=.true.
- enddo
- if(skip) cycle
- k=k+1
- cand(k)%snr=snr1
- cand(k)%f=f0
- cand(k)%xdt=sync(n)%xdt
- cand(k)%pol=sync(n)%pol
- cand(k)%ipol=sync(n)%ipol
- cand(k)%iflip=nint(flip)
- cand(k)%indx=n
-! write(50,3050) i,k,m,f0+32.0,diffhz,bw,snr1,db(snr1)
-!3050 format(3i5,f8.3,2f8.0,2f8.2)
- if(k.ge.MAX_CANDIDATES) exit
- enddo
- ncand=k
-
- return
-end subroutine get_candidates
-
-subroutine wb_sync(ss,savg,xpol,jz,nfa,nfb)
-
-! Compute "orange sync curve" using the Q65 sync pattern
-
- use timer_module, only: timer
- parameter (NFFT=32768)
- parameter (LAGMAX=30)
- real ss(4,322,NFFT)
- real savg(4,NFFT)
- real savg_med(4)
- real ccf4(4),ccf4best(4),a(3)
- logical first,xpol
- integer isync(22)
- integer jsync0(63),jsync1(63)
- integer ip(1)
-
-! Q65 sync symbols
- data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/
- data jsync0/ &
- 1, 4, 5, 9, 10, 11, 12, 13, 14, 16, 18, 22, 24, 25, 28, 32, &
- 33, 34, 37, 38, 39, 40, 42, 43, 45, 46, 47, 48, 52, 53, 55, 57, &
- 59, 60, 63, 64, 66, 68, 70, 73, 80, 81, 89, 90, 92, 95, 97, 98, &
- 100,102,104,107,108,111,114,119,120,121,122,123,124,125,126/
- data jsync1/ &
- 2, 3, 6, 7, 8, 15, 17, 19, 20, 21, 23, 26, 27, 29, 30, 31, &
- 35, 36, 41, 44, 49, 50, 51, 54, 56, 58, 61, 62, 65, 67, 69, 71, &
- 72, 74, 75, 76, 77, 78, 79, 82, 83, 84, 85, 86, 87, 88, 91, 93, &
- 94, 96, 99,101,103,105,106,109,110,112,113,115,116,117,118/
- data first/.true./
- save first,isync,jsync0,jsync1
-
- tstep=2048.0/11025.0 !0.185760 s: 0.5*tsym_jt65, 0.3096*tsym_q65
- if(first) then
- fac=0.6/tstep
- do i=1,22 !Expand the Q65 sync stride
- isync(i)=nint((isync(i)-1)*fac) + 1
- enddo
- do i=1,63
- jsync0(i)=2*(jsync0(i)-1) + 1
- jsync1(i)=2*(jsync1(i)-1) + 1
- enddo
- first=.false.
- endif
-
- df3=96000.0/NFFT
- ia=nint(1000*nfa/df3) + 1 !Flat frequency range for WSE converters
- ib=nint(1000*nfb/df3) + 1
- if(ia.lt.1) ia=1
- if(ib.gt.NFFT-1) ib=NFFT-1
- npol=1
- if(xpol) npol=4
-
- do i=1,npol
- call pctile(savg(i,ia:ib),ib-ia+1,50,savg_med(i))
- enddo
-! do i=ia,ib
-! write(14,3014) 0.001*(i-1)*df3,savg(1:npol,i)
-!3014 format(5f10.3)
-! enddo
-
- lagbest=0
- ipolbest=1
- flip=0.
-
- do i=ia,ib
- ccfmax=0.
- do lag=0,LAGMAX
-
- ccf=0.
- ccf4=0.
- do j=1,22 !Test for Q65 sync
- k=isync(j) + lag
- ccf4(1:npol)=ccf4(1:npol) + ss(1:npol,k,i+1) + &
- ss(1:npol,k+1,i+1) + ss(1:npol,k+2,i+1)
- enddo
- ccf4(1:npol)=ccf4(1:npol) - savg(1:npol,i+1)*3*22/float(jz)
- ccf=maxval(ccf4)
- ip=maxloc(ccf4)
- ipol=ip(1)
- if(ccf.gt.ccfmax) then
- ipolbest=ipol
- lagbest=lag
- ccfmax=ccf
- ccf4best=ccf4
- flip=0.
- endif
-
- ccf=0.
- ccf4=0.
- do j=1,63 !Test for JT65 sync, std msg
- k=jsync0(j) + lag
- ccf4(1:npol)=ccf4(1:npol) + ss(1:npol,k,i+1) + ss(1:npol,k+1,i+1)
- enddo
- ccf4(1:npol)=ccf4(1:npol) - savg(1:npol,i+1)*2*63/float(jz)
- ccf=maxval(ccf4)
- ip=maxloc(ccf4)
- ipol=ip(1)
- if(ccf.gt.ccfmax) then
- ipolbest=ipol
- lagbest=lag
- ccfmax=ccf
- ccf4best=ccf4
- flip=1.0
- endif
-
- ccf=0.
- ccf4=0.
- do j=1,63 !Test for JT65 sync, OOO msg
- k=jsync1(j) + lag
- ccf4(1:npol)=ccf4(1:npol) + ss(1:npol,k,i+1) + ss(1:npol,k+1,i+1)
- enddo
- ccf4(1:npol)=ccf4(1:npol) - savg(1:npol,i+1)*2*63/float(jz)
- ccf=maxval(ccf4)
- ip=maxloc(ccf4)
- ipol=ip(1)
- if(ccf.gt.ccfmax) then
- ipolbest=ipol
- lagbest=lag
- ccfmax=ccf
- ccf4best=ccf4
- flip=-1.0
- endif
-
- enddo ! lag
-
- poldeg=0.
- if(xpol .and. ccfmax.ge.SNR1_THRESHOLD) then
- call polfit(ccf4best,4,a)
- poldeg=a(3)
- endif
- sync(i)%ccfmax=ccfmax
- sync(i)%xdt=lagbest*tstep-1.0
- sync(i)%pol=poldeg
- sync(i)%ipol=ipolbest
- sync(i)%iflip=flip
- sync(i)%birdie=.false.
- if(ccfmax/(savg(ipolbest,i)/savg_med(ipolbest)).lt.3.0) sync(i)%birdie=.true.
-! if(sync(i)%iflip.eq.0 .and. sync(i)%ccfmax .gt. 20.0) then
-! write(50,3050) i,lagbest,sync(i)%ccfmax,sync(i)%xdt,sync(i)%ipol, &
-! sync(i)%birdie,ccf4best
-!3050 format(2i5,f10.3,f8.2,i5,1x,L3,4f7.1)
-! endif
-
- enddo ! i (frequency bin)
-
- call pctile(sync(ia:ib)%ccfmax,ib-ia+1,50,base)
- sync(ia:ib)%ccfmax=sync(ia:ib)%ccfmax/base
-
- bw=65*4*1.66666667 !Q65-60C bandwidth
- nbw=bw/df3 + 1 !Number of bins to blank
- syncmin=2.0
- nguard=10
- do i=ia,ib
- if(sync(i)%ccfmax.lt.syncmin) cycle
- spk=maxval(sync(i:i+nbw)%ccfmax)
- ip =maxloc(sync(i:i+nbw)%ccfmax)
- i0=ip(1)+i-1
- ja=min(i,i0-nguard)
- jb=i0+nbw+nguard
- sync(ja:jb)%ccfmax=0.
- sync(i0)%ccfmax=spk
- enddo
-
-! do i=ia,ib
-! write(15,3015) 0.001*(i-1)*df3+32.0,sync(i)%ccfmax,sync(i)%xdt, &
-! sync(i)%ipol,sync(i)%iflip,sync(i)%birdie
-!3015 format(3f10.3,2i6,L5)
-! enddo
-
- return
-end subroutine wb_sync
-
-end module wideband_sync
+module wideband_sync + + type candidate + real :: snr !Relative S/N of sync detection + real :: f !Freq of sync tone, 0 to 96000 Hz + real :: xdt !DT of matching sync pattern, -1.0 to +4.0 s + real :: pol !Polarization angle, degrees + integer :: ipol !Polarization angle, 1 to 4 ==> 0, 45, 90, 135 deg + integer :: iflip !Sync type: JT65 = +/- 1, Q65 = 0 + integer :: indx + end type candidate + type sync_dat + real :: ccfmax + real :: xdt + real :: pol + integer :: ipol + integer :: iflip + logical :: birdie + end type sync_dat + + parameter (NFFT=32768) + parameter (MAX_CANDIDATES=50) + parameter (SNR1_THRESHOLD=4.5) + type(sync_dat) :: sync(NFFT) + integer nkhz_center + + contains + +subroutine get_candidates(ss,savg,xpol,jz,nfa,nfb,nts_jt65,nts_q65,cand,ncand) + +! Search symbol spectra ss() over frequency range nfa to nfb (in kHz) for +! JT65 and Q65 sync patterns. The nts_* variables are the submode tone +! spacings: 1 2 4 8 16 for A B C D E. Birdies are detected and +! excised. Candidates are returned in the structure array cand(). + + parameter (MAX_PEAKS=100) + real ss(4,322,NFFT),savg(4,NFFT) + real pavg(-20:20) + integer indx(NFFT) + logical xpol,skip,ldecoded + type(candidate) :: cand(MAX_CANDIDATES) + common/early/nhsym1,nhsym2,ldecoded(32768) + + call wb_sync(ss,savg,xpol,jz,nfa,nfb) !Output to sync() array + + tstep=2048.0/11025.0 !0.185760 s: 0.5*tsym_jt65, 0.3096*tsym_q65 + df3=96000.0/NFFT + ia=nint(1000*nfa/df3) + 1 + ib=nint(1000*nfb/df3) + 1 + if(ia.lt.1) ia=1 + if(ib.gt.NFFT-1) ib=NFFT-1 + iz=ib-ia+1 + + call indexx(sync(ia:ib)%ccfmax,iz,indx) !Sort by relative snr + + k=0 + do i=1,MAX_PEAKS + n=indx(iz+1-i) + ia - 1 + f0=0.001*(n-1)*df3 + snr1=sync(n)%ccfmax + if(snr1.lt.SNR1_THRESHOLD) exit + flip=sync(n)%iflip + if(flip.ne.0.0 .and. nts_jt65.eq.0) cycle + if(flip.eq.0.0 .and. nts_q65.eq.0) cycle + if(sync(n)%birdie) cycle + +! Test for signal outside of TxT range and set bw for this signal type + j1=(sync(n)%xdt + 1.0)/tstep - 1.0 + j2=(sync(n)%xdt + 52.0)/tstep + 1.0 + if(flip.ne.0) j2=(sync(n)%xdt + 47.811)/tstep + 1.0 + ipol=sync(n)%ipol + pavg=0. + do j=1,j1 + pavg=pavg + ss(ipol,j,n-20:n+20) + enddo + do j=j2,jz + pavg=pavg + ss(ipol,j,n-20:n+20) + enddo + jsum=j1 + (jz-j2+1) + pmax=maxval(pavg(-2:2)) !### Why not just pavg(0) ? + base=(sum(pavg)-pmax)/jsum + pmax=pmax/base + if(pmax.gt.5.0) cycle + skip=.false. + do m=1,k !Skip false syncs within signal bw + diffhz=1000.0*(f0-cand(m)%f) + bw=nts_q65*110.0 + if(cand(m)%iflip.ne.0) bw=nts_jt65*178.0 + if(diffhz.gt.-0.03*bw .and. diffhz.lt.1.03*bw) skip=.true. + enddo + if(skip) cycle + k=k+1 + cand(k)%snr=snr1 + cand(k)%f=f0 + cand(k)%xdt=sync(n)%xdt + cand(k)%pol=sync(n)%pol + cand(k)%ipol=sync(n)%ipol + cand(k)%iflip=nint(flip) + cand(k)%indx=n +! write(50,3050) i,k,m,f0+32.0,diffhz,bw,snr1,db(snr1) +!3050 format(3i5,f8.3,2f8.0,2f8.2) + if(k.ge.MAX_CANDIDATES) exit + enddo + ncand=k + + return +end subroutine get_candidates + +subroutine wb_sync(ss,savg,xpol,jz,nfa,nfb) + +! Compute "orange sync curve" using the Q65 sync pattern + + use timer_module, only: timer + parameter (NFFT=32768) + parameter (LAGMAX=30) + real ss(4,322,NFFT) + real savg(4,NFFT) + real savg_med(4) + real ccf4(4),ccf4best(4),a(3) + logical first,xpol + integer isync(22) + integer jsync0(63),jsync1(63) + integer ip(1) + +! Q65 sync symbols + data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/ + data jsync0/ & + 1, 4, 5, 9, 10, 11, 12, 13, 14, 16, 18, 22, 24, 25, 28, 32, & + 33, 34, 37, 38, 39, 40, 42, 43, 45, 46, 47, 48, 52, 53, 55, 57, & + 59, 60, 63, 64, 66, 68, 70, 73, 80, 81, 89, 90, 92, 95, 97, 98, & + 100,102,104,107,108,111,114,119,120,121,122,123,124,125,126/ + data jsync1/ & + 2, 3, 6, 7, 8, 15, 17, 19, 20, 21, 23, 26, 27, 29, 30, 31, & + 35, 36, 41, 44, 49, 50, 51, 54, 56, 58, 61, 62, 65, 67, 69, 71, & + 72, 74, 75, 76, 77, 78, 79, 82, 83, 84, 85, 86, 87, 88, 91, 93, & + 94, 96, 99,101,103,105,106,109,110,112,113,115,116,117,118/ + data first/.true./ + save first,isync,jsync0,jsync1 + + tstep=2048.0/11025.0 !0.185760 s: 0.5*tsym_jt65, 0.3096*tsym_q65 + if(first) then + fac=0.6/tstep + do i=1,22 !Expand the Q65 sync stride + isync(i)=nint((isync(i)-1)*fac) + 1 + enddo + do i=1,63 + jsync0(i)=2*(jsync0(i)-1) + 1 + jsync1(i)=2*(jsync1(i)-1) + 1 + enddo + first=.false. + endif + + df3=96000.0/NFFT + ia=nint(1000*nfa/df3) + 1 !Flat frequency range for WSE converters + ib=nint(1000*nfb/df3) + 1 + if(ia.lt.1) ia=1 + if(ib.gt.NFFT-1) ib=NFFT-1 + npol=1 + if(xpol) npol=4 + + do i=1,npol + call pctile(savg(i,ia:ib),ib-ia+1,50,savg_med(i)) + enddo +! do i=ia,ib +! write(14,3014) 0.001*(i-1)*df3,savg(1:npol,i) +!3014 format(5f10.3) +! enddo + + lagbest=0 + ipolbest=1 + flip=0. + + do i=ia,ib + ccfmax=0. + do lag=0,LAGMAX + + ccf=0. + ccf4=0. + do j=1,22 !Test for Q65 sync + k=isync(j) + lag + ccf4(1:npol)=ccf4(1:npol) + ss(1:npol,k,i+1) + & + ss(1:npol,k+1,i+1) + ss(1:npol,k+2,i+1) + enddo + ccf4(1:npol)=ccf4(1:npol) - savg(1:npol,i+1)*3*22/float(jz) + ccf=maxval(ccf4) + ip=maxloc(ccf4) + ipol=ip(1) + if(ccf.gt.ccfmax) then + ipolbest=ipol + lagbest=lag + ccfmax=ccf + ccf4best=ccf4 + flip=0. + endif + + ccf=0. + ccf4=0. + do j=1,63 !Test for JT65 sync, std msg + k=jsync0(j) + lag + ccf4(1:npol)=ccf4(1:npol) + ss(1:npol,k,i+1) + ss(1:npol,k+1,i+1) + enddo + ccf4(1:npol)=ccf4(1:npol) - savg(1:npol,i+1)*2*63/float(jz) + ccf=maxval(ccf4) + ip=maxloc(ccf4) + ipol=ip(1) + if(ccf.gt.ccfmax) then + ipolbest=ipol + lagbest=lag + ccfmax=ccf + ccf4best=ccf4 + flip=1.0 + endif + + ccf=0. + ccf4=0. + do j=1,63 !Test for JT65 sync, OOO msg + k=jsync1(j) + lag + ccf4(1:npol)=ccf4(1:npol) + ss(1:npol,k,i+1) + ss(1:npol,k+1,i+1) + enddo + ccf4(1:npol)=ccf4(1:npol) - savg(1:npol,i+1)*2*63/float(jz) + ccf=maxval(ccf4) + ip=maxloc(ccf4) + ipol=ip(1) + if(ccf.gt.ccfmax) then + ipolbest=ipol + lagbest=lag + ccfmax=ccf + ccf4best=ccf4 + flip=-1.0 + endif + + enddo ! lag + + poldeg=0. + if(xpol .and. ccfmax.ge.SNR1_THRESHOLD) then + call polfit(ccf4best,4,a) + poldeg=a(3) + endif + sync(i)%ccfmax=ccfmax + sync(i)%xdt=lagbest*tstep-1.0 + sync(i)%pol=poldeg + sync(i)%ipol=ipolbest + sync(i)%iflip=flip + sync(i)%birdie=.false. + if(ccfmax/(savg(ipolbest,i)/savg_med(ipolbest)).lt.3.0) sync(i)%birdie=.true. +! if(sync(i)%iflip.eq.0 .and. sync(i)%ccfmax .gt. 20.0) then +! write(50,3050) i,lagbest,sync(i)%ccfmax,sync(i)%xdt,sync(i)%ipol, & +! sync(i)%birdie,ccf4best +!3050 format(2i5,f10.3,f8.2,i5,1x,L3,4f7.1) +! endif + + enddo ! i (frequency bin) + + call pctile(sync(ia:ib)%ccfmax,ib-ia+1,50,base) + sync(ia:ib)%ccfmax=sync(ia:ib)%ccfmax/base + + bw=65*4*1.66666667 !Q65-60C bandwidth + nbw=bw/df3 + 1 !Number of bins to blank + syncmin=2.0 + nguard=10 + do i=ia,ib + if(sync(i)%ccfmax.lt.syncmin) cycle + spk=maxval(sync(i:i+nbw)%ccfmax) + ip =maxloc(sync(i:i+nbw)%ccfmax) + i0=ip(1)+i-1 + ja=min(i,i0-nguard) + jb=i0+nbw+nguard + sync(ja:jb)%ccfmax=0. + sync(i0)%ccfmax=spk + enddo + +! do i=ia,ib +! write(15,3015) 0.001*(i-1)*df3+32.0,sync(i)%ccfmax,sync(i)%xdt, & +! sync(i)%ipol,sync(i)%iflip,sync(i)%birdie +!3015 format(3f10.3,2i6,L5) +! enddo + + return +end subroutine wb_sync + +end module wideband_sync diff --git a/map65/libm65/wrapkarn.c b/map65/libm65/wrapkarn.c index 1b1a6311..9e0a51ca 100755..100644 --- a/map65/libm65/wrapkarn.c +++ b/map65/libm65/wrapkarn.c @@ -1,70 +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);
-}
-
+#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/map65/libm65/zplot.f90 b/map65/libm65/zplot.f90 index a10c85c8..55aa3c6f 100755..100644 --- a/map65/libm65/zplot.f90 +++ b/map65/libm65/zplot.f90 @@ -1,34 +1,34 @@ -subroutine zplot(amp,nz,jj,ave,rms)
-
- real amp(nz)
- character*1 line(100),mark(0:6)
- data mark/' ',' ','.','-','+','X','$'/
-
- sum=0.
- smax=0.
- do i=1,nz
- sum=sum+amp(i)
- if(amp(i).gt.smax) then
- smax=amp(i)
- ipk=i
- endif
- enddo
- ave=(sum-smax)/(nz-1)
- sq=0.
- do i=1,nz
- if(i.ne.ipk) sq=sq+(amp(i)-ave)**2
- enddo
- rms=sqrt(sq/(nz-2))
-
- do i=1,nz
- n=(amp(i)-ave)/rms
-! n=(amp(i)-ave)/0.33
- if(n.lt.0) n=0
- if(n.gt.6) n=6
- line(i)=mark(n)
- enddo
- write(89,1010) jj,0.01*ave,0.01*rms,(line(i),i=1,nz)
-1010 format(i3,2f6.1,1x,100a1)
-
- return
-end subroutine zplot
+subroutine zplot(amp,nz,jj,ave,rms) + + real amp(nz) + character*1 line(100),mark(0:6) + data mark/' ',' ','.','-','+','X','$'/ + + sum=0. + smax=0. + do i=1,nz + sum=sum+amp(i) + if(amp(i).gt.smax) then + smax=amp(i) + ipk=i + endif + enddo + ave=(sum-smax)/(nz-1) + sq=0. + do i=1,nz + if(i.ne.ipk) sq=sq+(amp(i)-ave)**2 + enddo + rms=sqrt(sq/(nz-2)) + + do i=1,nz + n=(amp(i)-ave)/rms +! n=(amp(i)-ave)/0.33 + if(n.lt.0) n=0 + if(n.gt.6) n=6 + line(i)=mark(n) + enddo + write(89,1010) jj,0.01*ave,0.01*rms,(line(i),i=1,nz) +1010 format(i3,2f6.1,1x,100a1) + + return +end subroutine zplot |
